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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...