Knowledge Management

How do I subtract two search?

politrons
Explorer

I´m making a union of two search, and now I´m trying to make a subtract of the two variables.

 

| set union [search "Output MeshRequestId" | stats avg(time) as avgTimeOut ] [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  |stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

 

Everything fine before the latest count. I can see the definition of two avg variables.

But when I do the stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

Always return 0. Any idea what is wrong

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

union is producing 2 events, one with avgTimeOut and one with avgTimeInt - the calculation is working on one event at a time from the pipeline, so for each event, one of the fields is null.

Have you considered using appendcols in this scenario?

0 Karma

politrons
Explorer

Thanks for the answer, any example that I can refer of how it should be done using appendcols for this use case?

 

regards 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

search "Output MeshRequestId" | stats avg(time) as avgTimeOut 
| appendcols [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  | stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

FrankVl
Ultra Champion

At that point you could also simply replace that last stats by an eval. (Unless I'm somehow completely missing what you're trying to achieve with that stats)

 

search "Output MeshRequestId"
| stats avg(time) as avgTimeOut 
| appendcols [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  | eval TimeInThrottler = avgTimeOut - avgTimeInt

 

 

0 Karma

politrons
Explorer

Thanks for all the answers, after apply both option of union and append. I got same result

Only avgTimeInt is present, and I cannot show the total Difference.

Also I would like to use the result in stats or timechar if is possible

 

splunk_issues.PNG

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It looks like

"Output MeshRequestId"
| stats avg(time) as avgTimeOut 

is not producing any results - please check the events from the search to make sure they have the time field with that exact name.

politrons
Explorer

Yep silly me the query were wrong, thanks  lot!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

    Thursday, June 25, 2026  |  11AM PDT / 2PM EDT  Duration: 1 Hour (Includes live Q&A) Register to ...

Analytics Workspace deprecation

As of Splunk Cloud Platform 10.4.2604 and Splunk Enterprise 10.4, Analytics Workspace is now deprecated. ...

Splunk Developer Day Recap: Building, Publishing, and Growing on the Splunk Platform

Splunk Developer Day brought the Splunk developer community together for a practical look at what it means to ...