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!

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2025 SplunkTrust is officially open! If you ...

Splunk Answers Content Calendar, June Edition II

Get ready to dive into Splunk Dashboard panels this week! We'll be tackling common questions around ...

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...