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
Revered Legend

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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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