Splunk Search

Summing of row in a column on condition

vinay_ks04
New Member

I have three columns

ColumnA     ColumnB     ColumnC
vin          1            1
vin          1            2 
vin          2            3
kum          1            1
kum          1            2
kum          2            3

I wanted sum columnc and find out the percentage by ColumnA

ColumnA     ColumnB     ColumnC     "Totalof Columnc by Site" Percentage
vin          1            3              6                       50
             2            3              6                       50
kum          1            3              6                       50
             2            3              6                       50      
Tags (1)
0 Karma

David
Splunk Employee
Splunk Employee

Based on your result, it looks like you want to add something like this to the end of your search:

| stats sum(ColumnC) as "Total of ColumnC by Site" by ColumnA, ColumnB | eventstats sum(ColumnC) as OverallColumnCTotal | eval Percentage = round("Total of ColumnC by Site" / OverallColumnCTotal * 100,0) | table ColumnA ColumnB ColumnC "Total of ColumnC by Site" Percentage

Does that match what you're looking for?

0 Karma

vinay_ks04
New Member

Thanks a lot 🙂
I have added extra columnname in stats, below is my query.

index="autolab_prod" sourcetype="Percentage_Usage_Config" | stats sum(taskcount) as TOTAL_Task by Site ConfigID CONFIG | eventstats sum(TOTAL_Task) as SiteTotal by Site | eval percent=round(100*TOTAL_Task/SiteTotal,0) | stats list(ConfigID) AS "CONFIG ID", list(CONFIG) AS CONFIGNAME, list(TOTAL_Task) AS "TASK_TOTAL", list(SiteTotal) AS TASK_TOTAL_COUNT, list(percent) as PERCENTAGE by Site

0 Karma

vinay_ks04
New Member

thank you,
yes, but I am not able to add one more column.

0 Karma

lguinn2
Legend

Try this

yoursearchhere
| stats sum(ColumnC) as CTotal by ColumnA ColumnB  
| eventstats sum(CTotal) as SiteTotal by ColumnA
| eval Percentage = round(CTotal*100/SiteTotal,0)
0 Karma

lguinn2
Legend

After the stats command, your search pipeline no longer has any fields except the ones that are the result of the command: TOTAL_Task Site and ConfigID

So if you want the CONFIG to be included, you will have to include it in the by clause of the stats command.

0 Karma

vinay_ks04
New Member

Thanks a lot it is working.......

I am adding one more column to just print the value which is there in the log, but it is not printing.
I am using "list(Config) As "Config Name"

index="autolab_prod" sourcetype="Percentage_Usage_Config" | stats sum(taskcount) as TOTAL_Task by Site ConfigID | eventstats sum(TOTAL_Task) as SiteTotal by Site | eval percent=round(100*TOTAL_Task/SiteTotal,0) | stats list(ConfigID) AS "CONFIG ID", list(CONFIG) AS "CONFIG NAME", list(TOTAL_Task) AS "TOTAL_Task", list(SiteTotal) AS SiteTotal, list(percent) as PERCENTAGE by Site

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...