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!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...