Splunk Search

How to write a search that returns count totals and percentages?

splunk_hvijay
Explorer

I have some tables like below extracting from a csv file.

BusinessUnit      Status           SLAMET

Finance           Mailed           On-Time
Finance           Mailed           Late
Finance           Mailed           Early
Finance           Processed        No Status
Finance           Processed        No Status
HR               Mailed           On-Time
HR                Mailed           Late
HR                Mailed           Early
HR                Processed        No Status
HR                Processed        No Status  

I want to write a search query which returns the counts and percentages as below.. Can someone please help?

BusinessUnit    Total    OnTime    %OnTime    Late     %Late   Early     %Early
Finance            5        1         20%       1        20%     1        20%
HR               5        1         20%       1        20%     1        20%
0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

your current search giving fields BusinessUnit, Status, SLAMET 
| stats count as Total count(eval(SLAMET="On-Time")) as OnTime count(eval(SLAMET="Late")) as Late count(eval(SLAMET="Early")) as Early | eval "%Ontime"=tostring(round(OnTime*100/Total,1))."%" | eval "%Late"=tostring(round(Late*100/Total,1))."%" | eval "%Early"=tostring(round(Early*100/Total,1))."%"
| table BusinessUnit Total OnTime "%OnTime" Late "%Late" Early "%Early"

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this

your current search giving fields BusinessUnit, Status, SLAMET 
| stats count as Total count(eval(SLAMET="On-Time")) as OnTime count(eval(SLAMET="Late")) as Late count(eval(SLAMET="Early")) as Early | eval "%Ontime"=tostring(round(OnTime*100/Total,1))."%" | eval "%Late"=tostring(round(Late*100/Total,1))."%" | eval "%Early"=tostring(round(Early*100/Total,1))."%"
| table BusinessUnit Total OnTime "%OnTime" Late "%Late" Early "%Early"
0 Karma

splunk_hvijay
Explorer

Thank You.. I just added the "stats by BusinessUnit" in the query. Thanks so much again.

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...