Splunk Search

Zero count not displaying when stats count is used

Harshi1993
New Member

My query is :

index="stage*" source="*record service*" | eval type=case(like(message, "%successful generated account%"),"Success Accounts",
like(message, "%Granting failed Accounts%"),"Granting failed Accounts", like(message, "%Inbound setup failed accounts%"),"Inbound  failed Accounts")|
stats count as Results by type

I am getting the result as:

type                                               Results

Success Accounts                   10

Granting failed Accounts       20

 

I am unable to get the results for the string  Inbound failed Accounts as the results are zero. I need the output as 

type                                               Results

Success Accounts                   10

Granting failed Accounts       20

Inbound  failed Accounts         0

 

Please help me with the query for displaying the strings with zero count as well

 

Labels (1)
0 Karma

renjith_nair
Legend

Try

index="stage*" source="*record service*" 
| eval type=case(like(message, "%successful generated account%"),"Success Accounts",
like(message, "%Granting failed Accounts%"),"Granting failed Accounts", like(message, "%Inbound setup failed accounts%"),"Inbound  failed Accounts")
|stats count as Results by type
|append [|stats count as Results|eval type="Success Accounts,Granting failed Accounts,Inbound  failed Accounts"|makemv type delim=","|mvexpand type]
|stats sum(Results) by type

 

---
What goes around comes around. If it helps, hit it with Karma 🙂

PickleRick
SplunkTrust
SplunkTrust

It's a typical mistake to want to have knowledge about _what_ was done earlier "down the road" whereas Splunk doesn't work that way.

After a pipe you get only a _result_ of the command from before the pipe. So if any command is supposed to look for - let's say - one of three different values but finds only two of them, the result will only have two of those values and any subsequent command won't have the knowledge that you wanted to search for the third value as well. You only get the results.

So the most obvious workaround in such case as yours is - as @ITWhisperer showed - creating an initial set of "empty" (with a value of zero) result set and then sum this set with your actual result. That way if you don't have any other results, you'll just stay with your static results of zero hits.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| append [| makeresults
| eval type=split"Success Accounts|Granting failed Accounts|Inbound  failed Accounts","|")
| mvexpand type
| eval Results=0
| table type Results]
| stats sum(Results) as Results by type
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...