Splunk Search

How to create a new column in my table showing the sum of FieldA by FieldB?

akawacz
Path Finder

HI

My data

Quarter   Type   Amount
2014q1     a      100
2014q1     b      200
2015q2     a      100
2015q2     b      100

I would like to create an additional column with sum for the same quarter.

Expected result

Quarter   Type   Amount  New_column
2014q1     a      100       300
2014q1     b      200       300
2015q2     a      100       200
2015q2     b      100       200

My current search:

index=test |stats(amount) as amount by quarter type

I do not want to use join and append.

Could you help me?

0 Karma
1 Solution

somesoni2
Revered Legend

Try this

your current search | eventstats sum(amount) as New_column by quarter

View solution in original post

somesoni2
Revered Legend

Try this

your current search | eventstats sum(amount) as New_column by quarter

akawacz
Path Finder

That works!! thank you

0 Karma

ppablo
Retired

Hi @akawacz,

Glad @somesoni2 helped you find your answer 🙂 Please be sure to accept his answer by clicking "Accept" directly below the answer, otherwise this post will show as unresolved. Thanks!

Patrick

0 Karma

woodcock
Esteemed Legend

This is not your search; you are missing a function between stats and (amount).

0 Karma

akawacz
Path Finder

Yes, good point. Just forgot to put it. i was recreating version of my bigger search that would be better/easier to explain.

0 Karma

woodcock
Esteemed Legend

OK, so what is it supposed to be?

0 Karma

akawacz
Path Finder

should be sum

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...