Splunk Search

How to divide the results of one search by the results of a second search?

slashnburn
Path Finder

I have two separate searches and would like to divide the results of the first by the second.

My first search is, which returns "3":

| set intersect [search source="test1.csv" | table Setting] [search source="test2.csv" | table Setting] | stats count(Setting)

And my second search is, which returns "5":

source="test1.csv" | table Setting| stats count(Setting)

I am looking to combine both searches to get ".6". I know how to do this with a more simple search that doesn't involve the intersection of two sources, but am not familiar with how to do it in this case.

1 Solution

strive
Influencer

Try this

| set intersect [search source="test1.csv" | table Setting] [search source="test2.csv" | table Setting] | stats count(Setting) as Setting1 | appendcols [search source="test1.csv" | table Setting| stats count(Setting) as Setting2] | eval finalValue = Setting1/Setting2

alt text

View solution in original post

bwooden
Splunk Employee
Splunk Employee

There are a few ways to solve this. One way is use use append to combine the two results into one result set and then use stats to isolate the data points you want. It is easier if we rename the counts before passing them to stats. I will use that approach below

| set intersect [search source="test1.csv" | table Setting] [search source="test2.csv" | table Setting] | stats count(Setting) as dividend
| append [ search source="test1.csv" | table Setting| stats count(Setting) as divisor ]
| stats max(dividend) as dividend max(divisor) as divisor | eval quotient=dividend/divisor

somesoni2
SplunkTrust
SplunkTrust

Try this

source="test1.csv" [search source="test2.csv" | table setting] | stats count(setting) as countCommon | appendcols [search source="test1.csv" | table Setting| stats count(Setting) as countAll] | eval perc=countCommon/countAll

strive
Influencer

Try this

| set intersect [search source="test1.csv" | table Setting] [search source="test2.csv" | table Setting] | stats count(Setting) as Setting1 | appendcols [search source="test1.csv" | table Setting| stats count(Setting) as Setting2] | eval finalValue = Setting1/Setting2

alt text

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...