Knowledge Management

How to subtract outcome of count

rijk
Explorer

I have two saved searches, saved them as macros.

1: [search sourcetype="brem" sanl31 eham Successfully completed (cc*) | fields MessageTime] sanl31 eham Successfully completed cc* | stats count

This is saved as brem_correction_count

2: [search sourcetype="brem" sanl31 eham Successfully completed (cc*) | fields MessageTime] sanl31 eham Successfully completed NOT cc* | stats count

This is saved as brem_corrected_count

How can I use these searches to subtract the outcome of the 2 searches?

Tags (2)
0 Karma
1 Solution

lguinn2
Legend

First, I don't understand what the subsearch is doing in either one of these. I think you can simplify like this:

Search 1:

sourcetype="brem" sanl31 eham Successfully completed cc* | stats count

Search 2:

sourcetype="brem" sanl31 eham Successfully completed NOT cc* | stats count

The fastest search that would calculate the difference would probably be

sourcetype="brem" sanl31 eham Successfully completed
| eval ccType=if(match(_raw,"\bcc"),"Yes","No")
| stats count(eval(ccType="Yes")) as ccCount count(eval(ccType="No")) as NotCcCount
| eval diff =ccCount - NotCcCount

View solution in original post

rijk
Explorer

Many thanks for you answer, it does exactly what I needed. The subsearch is needed to find two related messages based on a field MessageTime. Sorry that I confused you, but the subsearch is needed.

0 Karma

lguinn2
Legend

First, I don't understand what the subsearch is doing in either one of these. I think you can simplify like this:

Search 1:

sourcetype="brem" sanl31 eham Successfully completed cc* | stats count

Search 2:

sourcetype="brem" sanl31 eham Successfully completed NOT cc* | stats count

The fastest search that would calculate the difference would probably be

sourcetype="brem" sanl31 eham Successfully completed
| eval ccType=if(match(_raw,"\bcc"),"Yes","No")
| stats count(eval(ccType="Yes")) as ccCount count(eval(ccType="No")) as NotCcCount
| eval diff =ccCount - NotCcCount
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...