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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...