Splunk Search

How to get sum of all columns into a new column?

paullt12345
Explorer

Hi

I need to do a sum of all columns into new column

EVNT  COL1  COL2  COL3 SUM
1       22   22     22  66
2       1     0     0    1

-paull

0 Karma
1 Solution

vnravikumar
Champion

Hi

You can try

| makeresults 
| eval EVNT=1,COL1=22,COL2=22,COL3=22,SUM=0 
| foreach COL* 
    [ eval SUM = SUM+<<FIELD>>] 
| table EVNT,COL1,COL2,COL3,SUM

View solution in original post

renjith_nair
Legend

@paullt12345 ,

Just add |addtotals fieldname=sum to your search and you get a new sum field

https://docs.splunk.com/Documentation/SplunkCloud/7.2.4/SearchReference/Addtotals

---
What goes around comes around. If it helps, hit it with Karma 🙂

ClubMed
Path Finder

5 years later and I came upon this. This should be the actual, concise answer for OP's question.

paullt12345
Explorer

Thanks it also works as expected.

0 Karma

vnravikumar
Champion

Hi

You can try

| makeresults 
| eval EVNT=1,COL1=22,COL2=22,COL3=22,SUM=0 
| foreach COL* 
    [ eval SUM = SUM+<<FIELD>>] 
| table EVNT,COL1,COL2,COL3,SUM

paullt12345
Explorer

Thanks...

0 Karma
Get Updates on the Splunk Community!

Developer Spotlight with Brett Adams

In our third Spotlight feature, we're excited to shine a light on Brett—a Splunk consultant, innovative ...

Index This | What can you do to make 55,555 equal 500?

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

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...