Splunk Search

Add sum in new field

HeinzWaescher
Motivator

Hi,

in one single event, the field amount appears multiple times. What I need is a new field that includes the total_amount for each event, to calculate stats with it afterwards.

For instance, we have the field amount in an event three times:
amount=5
amount=10
amount=5

Is it possible to add a field thats sums up the total_amount=20 in this event?

Tags (1)
0 Karma

theouhuios
Motivator

addtotals command should help.

Please see the documentation for the command

http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Addtotals

Try this

|eventstats sum(<yourfield>) as Sum
0 Karma

HeinzWaescher
Motivator

Sadly not. I think I will try to convert the field into a numeric type somehow and then use addtotals.
Thanks for your input!

0 Karma

theouhuios
Motivator

I am really sorry, I thought you had it as a field already. Anyways to do that you might want to do a rex to extract the fields in an event first.

0 Karma

HeinzWaescher
Motivator

eventstats needs numerical values as well. and next to that I it would calculate the sum for all events. And I don't a useful field to group by the eventstats 😕

0 Karma

theouhuios
Motivator

Updated the answer. Please try eventstats

0 Karma

HeinzWaescher
Motivator

Hi,

thanks for this hint. I tried it out, but I get an empty result.
The field i want to use is definded as a string in the fieldlist. Can this be the reason? On the other hand the same field works with | stats sum() commands

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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

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

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...