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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...