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 Forwarders and Forced Time Based Load Balancing

Splunk customers use universal forwarders to collect and send data to Splunk. A universal forwarder can send ...

NEW! Log Views in Splunk Observability Dashboards Gives Context From a Single Page

Today, Splunk Observability releases log views, a new feature for users to add their logs data from Splunk Log ...

Last Chance to Submit Your Paper For BSides Splunk - Deadline is August 12th!

Hello everyone! Don't wait to submit - The deadline is August 12th! We have truly missed the community so ...