Splunk Search

How to compare and generate percentage from two lookup fields?

Minasdad
Path Finder

file1.csv and file2.csv with a common field of "Tests". Wanting to compare File2 field "Tests" against file1.csv field "Tests" and generate a percentage. Example file1.csv has 4 test vs. file2.csv with 2, generating a percentage of 50%.

Labels (1)
0 Karma
1 Solution

marysan
Communicator

| inputlookup file1.csv 
| eventstats dc(Tests) as file1_tests_count
| dedup file1_tests_count
| inputlookup append=T  file2.csv
| eventstats dc(Tests) as file2_tests_count
| dedup file2_tests_count
| fields file1_tests_count,file2_tests_count
| eval percentage=(file1_tests_count/file2_tests_count*100)

View solution in original post

Tags (2)

marysan
Communicator

| inputlookup file1.csv 
| eventstats dc(Tests) as file1_tests_count
| dedup file1_tests_count
| inputlookup append=T  file2.csv
| eventstats dc(Tests) as file2_tests_count
| dedup file2_tests_count
| fields file1_tests_count,file2_tests_count
| eval percentage=(file1_tests_count/file2_tests_count*100)

Tags (2)

gcusello
SplunkTrust
SplunkTrust

Hi  @Minasdad,

let me understand: you want to display the persentage of the count of lookup2 respect lookup1, is it correct?

I f this is your need, please try this:

| inputlookup file1.csv
| stats count 
| eval lookup=file2
| append [ 
   | inputlookup file1.csv
   | stats count
   | eval lookup=file2
   ]
| transpose header_field=lookup
| eval perc=round(file2/file1*100,2)
| table perc

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...