Splunk Search

Modifying stats count to include fields with zero-values

HallGM
Engager

I have some data with a field called "priority", which has a value from P1 -> P5.

this search query:

...
| stats count as Quantity by priority

 

produces a table that looks something like this:

priorityQuantity
P21
P31
P46
P53

 

As you can see,  there are no data entries with a priority of "P1". However, I would like to actually include that as a row in the table and show that there is a quantity of "0". Ideally I would want to include all 5 priority levels for any dataset, even when they are empty

Can anyone help and let me know how I can do this? Is there a way to specify which values to count?

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

 

...
| eval count=1
| append [| makeresults | eval priority=SPLIT("P1,P2,P3,P4,P5", ",") | mvexpand priority | eval count=0]
| stats sum(count) AS Quantity BY priority

 

View solution in original post

VatsalJagani
SplunkTrust
SplunkTrust

Use below:

| append [| makeresults | eval priority=split("P1,P2,P3,P4,P5", ",") | mvexpand priority | eval count=0]
| stats sum(count) AS Quantity BY priority
0 Karma

johnhuang
Motivator

 

...
| eval count=1
| append [| makeresults | eval priority=SPLIT("P1,P2,P3,P4,P5", ",") | mvexpand priority | eval count=0]
| stats sum(count) AS Quantity BY priority

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...