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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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