Splunk Search

using addcoltotals

dolj
Explorer

Can you leverage the total derived using the addcoltotals command to support other calculations? i.e. can you use it to calculate a percentage? 

| addcoltotals count labelfield="total"
| eval percent=((count/total)*100)
| table host count percent

 

 

Tags (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

You can't use the total calculated by addcoltotals as it's in a new row at the bottom of the table, however, as @richgalloway the typical way to calculate percentages is to use eventstats to add up all the counts, so that the total is added to _every_ row in your data set, which you can then calculate the percentages with.

Then discard that calculated total field if you no longer need it

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Yes, the output of the addcoltotals command can be used to perform calculations.  The sample code, however, won't work.  That's because the value of the "total" field created by addcoltotals is text (the label) rather than a number so the eval will fail.

Another way to get percentages is to use eventstats to compute the total then eval the percentage.

| eventstats sum(count) as total
| eval percent=((count/total)*100)
| table host count percent

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...