Reporting

"No results found" to be represented as NULL or 0

adityapavan18
Contributor

Hi I have a query ending

| stats count as Traffic,avg(duration) by host

It works fine if i have some logs.

If there are no logs, i get "no results found"

But is it possible to return

Traffic     avg(duration)   host
0              0            NULL
Tags (1)
1 Solution

jonuwz
Influencer

Try something like this :

| stats count as Traffic, avg(duration) as duration by host 
| appendpipe [ stats count | eval Traffic=0 | eval duration=0 | eval host="NULL" | where count==0 | fields - count ]

This adds an extra line to your output with default values, but only if the result count = 0

View solution in original post

jonuwz
Influencer

Try something like this :

| stats count as Traffic, avg(duration) as duration by host 
| appendpipe [ stats count | eval Traffic=0 | eval duration=0 | eval host="NULL" | where count==0 | fields - count ]

This adds an extra line to your output with default values, but only if the result count = 0

karthik4455
Explorer

I have a scenario where one column needs to be indicated with Zero in the instance of no result. While this seems to be working, however, it's showing other fileds as NULL.

query:
index=dailyincidents earliest=-90d@d source=FW1-HKS-01 | dedup id | stats values(customer) AS Customer count AS QuarterlyVolume by source | appendpipe [stats count | eval QuarterlyVolume=0 | where count=0 | fields - count]

I am using the above query and I'm seeing the below result:
source Customer QuarterlyVolume
1 0

I want to see the details of source and Customer as well.

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...