Splunk Search

Populating top 2 failed-policy counts for each cycledate

AC
New Member

I am trying to write a search for getting the top two failed policy count for each cycledate. The below works for a single day but not for multiple cycledates.

index=xxx host=yy* source="*E:\\logfile\*" tag="*error*" "Error ==>*" | stats distinct_count(polnum) as FailedPolicy by error_message, err_code, cycledate | sort 2-FailedPolicy

 

Table without the sort 2 -FailedPolicy

error_ messageerr_CodeCycleDateFailedPolicy
Err1201670911202035
Err2234610911202012
Err3234510911202022
Err41324091120203
Err51341550910202021
Err632450910202081
Err71234091020202
Err841240909202021
Err95670909202031
Err1098730909202045
Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It isn't clear whether your search includes a space between "-" and "FailedPolicy"

| sort 2 - FailedPolicy
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The dedup command can select the first two events for each value of a given field.

index=xxx host=yy* source="*E:\\logfile\*" tag="*error*" "Error ==>*" 
| stats distinct_count(polnum) as FailedPolicy by error_message, err_code, cycledate 
| sort - FailedPolicy
| dedup 2 CycleDate
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...