Splunk Search

How to default stats to zero when no rows returned?

schres1
Explorer

I have a query similar to the one below. 

index = "idx" source = "mysource"  |spath path=myField output=res|stats count by res
| where res="xyz"

Is there a way to get the search to return zero if no rows are returned? The reason Im asking for this is because this is the query Im using to populate values into a dashboard panel. If no rows are returned I would prefer the panel show zero instead of no results. 

Labels (2)
Tags (2)
0 Karma
1 Solution

etoombs
Path Finder

There might be a more graceful way someone will provide, but I generally add something like this to the end, forcing a row with a 0 value, and then doing another quick sum before displaying it.

| append
[makeresults |eval count=0]
|stats sum(count) as count

 

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This is another way to get count=0

| appendpipe
    [stats count
    | where count=0
    | eval res="xyz"]

Having said that, there may be a better way depending on your full search.

0 Karma

schres1
Explorer

Thank you! I will give this a try!

0 Karma

etoombs
Path Finder

There might be a more graceful way someone will provide, but I generally add something like this to the end, forcing a row with a 0 value, and then doing another quick sum before displaying it.

| append
[makeresults |eval count=0]
|stats sum(count) as count

 

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...