Splunk Search

How can I resolve return 0 for "No Results Found"?

philh
Explorer

Hi, I have a query where I'm extrapolating type based on a conditional then counting by type. This works great when there are events for both cases, but I'd also like to show a value of 0 for a given type when there aren't any events for that type. I've seen some other posts using fillnull and appendpipe but those examples haven't worked for my use case. Any help would be appreciated!

 

| eval type=if(user_action="place_order", "AddInOrdersPlaced", "AddInForwardedOrders")
| convert timeformat="%Y-%m-%d" ctime(_time) AS date
| chart count over date by type

 

 

Labels (4)
0 Karma
1 Solution

diogofgm
SplunkTrust
SplunkTrust

If you're looking into a time range, and you're using chart over date, the chart won't create the missing dates where both types do not have an event. 
What you can try to do instead is using a timechart that for the given time range with create the missing dates of the span you select.

| eval type=if(user_action="place_order", "AddInOrdersPlaced", "AddInForwardedOrders")
| timechart span=1d count by type
| fillnull value="0" AddInOrdersPlaced AddInForwardedOrders


 

------------
Hope I was able to help you. If so, some karma would be appreciated.

View solution in original post

diogofgm
SplunkTrust
SplunkTrust

If you're looking into a time range, and you're using chart over date, the chart won't create the missing dates where both types do not have an event. 
What you can try to do instead is using a timechart that for the given time range with create the missing dates of the span you select.

| eval type=if(user_action="place_order", "AddInOrdersPlaced", "AddInForwardedOrders")
| timechart span=1d count by type
| fillnull value="0" AddInOrdersPlaced AddInForwardedOrders


 

------------
Hope I was able to help you. If so, some karma would be appreciated.

philh
Explorer

@diogofgm This works great thank you!

0 Karma

PickleRick
SplunkTrust
SplunkTrust

You can't find something that isn't there. See https://www.duanewaddle.com/proving-a-negative/ for ideas

0 Karma
Get Updates on the Splunk Community!

Exporting Splunk Apps

Join us on Monday, October 21 at 11 am PT | 2 pm ET!With the app export functionality, app developers and ...

Cisco Use Cases, ITSI Best Practices, and More New Articles from Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Build Your First SPL2 App!

Watch the recording now!.Do you want to SPL™, too? SPL2, Splunk's next-generation data search and preparation ...