Splunk Search

How do I add the total count of all events in each row ?

Ombessam
Path Finder

Here is what I have

Screenshot 2025-09-22 at 12.29.15.png

Now I want to add a new column like this eval nullPercent = round((nullCount/total)*100, 2) where total is the total count of all events.

For that I tried first to append total like this

Screenshot 2025-09-22 at 12.48.58.png

Unfortunately total is only appended in the first row therefore I'm not able to calculate nullPercent.

 

Can someone help me achieve my goal ? 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The appendcols command is almost always the wrong answer to a SPL problem.  There are too many considerations for it to be as useful as one might expect.

In this case, try using eventstats to calculate the total.  Then you can use eval to get the percentage for each value.

...
| eventstats sum(nullCount) as total
| eval nullPercent=round((nullCount * 100)/total,2)

P.S. Please put SPL in a code block rather than in an image.  That makes it easier for us to test your code and our responses.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The appendcols command is almost always the wrong answer to a SPL problem.  There are too many considerations for it to be as useful as one might expect.

In this case, try using eventstats to calculate the total.  Then you can use eval to get the percentage for each value.

...
| eventstats sum(nullCount) as total
| eval nullPercent=round((nullCount * 100)/total,2)

P.S. Please put SPL in a code block rather than in an image.  That makes it easier for us to test your code and our responses.

---
If this reply helps you, Karma would be appreciated.

Ombessam
Path Finder

Thanks @richgalloway  you're right. It worked

 

index=main source="employees_data.csv" 
| fields - source* sourcetype* splunk* eventtype tag* index* linecount* punct* timestamp* _time _raw
| foreach * 
    [ eval <<FIELD>>_isNull = if(isnull('<<FIELD>>'), 1, 0) ]
| stats sum(*_isNull) as *
| transpose column_name="missing_logs"
| rename "row 1" as nullCount
| eventstats sum(nullCount) as total_events
| eval nullPercent = round((nullCount / total_events) * 100, 2)
| fields - total_events
| where nullCount > 0 
| rename nullCount as "Total Missing", nullPercent as "Missing Percentage", missing_logs as "Missing Logs"

 

Screenshot 2025-09-22 at 22.14.30.png

Ombessam
Path Finder

@richgalloway  thanks for your answer.

But I want to calculate nullPercent based on total_events (Total count of all events) not based on total count of nulls (| eventstats sum(nullCount) as total)

0 Karma

thahir
Contributor

@Ombessam you need total number of null events across overall?

like below

thahir_0-1758546353658.png

 

0 Karma
Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...