Splunk Search

How to make stats count result value become filters in search/dashboard

b1211ry
Explorer

Hi,

I need to call the result value as a filter. like this table below, the second value on column RecipientDomain will call on search as filter. become this query:

index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain=@yahoo.com | stats count by xxx

 

splunk first query.jpg

 

Help please..

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You need a subsearch.  The subsearch runs first and selects the value the main search will look for.

index=sec_office365_dlp sourcetype=sec_office365_dlp [ index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain IN (@gmail.com @yahoo.com @hotmail.com) 
  | stats count by RecipientDomain
  | sort limit=2 - count
  | tail 1
  | return RecipientDomain ]
| stats count by xxx

The subsearch selects the last (tail 1) result from the two produced by sort, which is the same as the second of three.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

How does Splunk know which RecipientDomain value to use?  Is it always the second?

---
If this reply helps you, Karma would be appreciated.
0 Karma

b1211ry
Explorer

Yes @richgalloway , we always use the second one value.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You need a subsearch.  The subsearch runs first and selects the value the main search will look for.

index=sec_office365_dlp sourcetype=sec_office365_dlp [ index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain IN (@gmail.com @yahoo.com @hotmail.com) 
  | stats count by RecipientDomain
  | sort limit=2 - count
  | tail 1
  | return RecipientDomain ]
| stats count by xxx

The subsearch selects the last (tail 1) result from the two produced by sort, which is the same as the second of three.

---
If this reply helps you, Karma would be appreciated.
0 Karma

b1211ry
Explorer

Thanks for your help @richgalloway .  It works!!👍

 

 

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...