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!

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 ...