Splunk Search

Groups in stats command: How to get the sum of multiple fields by a field?

splunkuser320
Path Finder

I am trying to create a query to get the sum of multiple fields by a field. 

 

index="*****"
|stats sum(field_A) as  A by field_C,sum(field_B) as B  by field_C

| table field_C, field_A,field_B

 

This query is giving error. 

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @splunkuser320,

you cannot use two BY clauses in a stats command, please try this:

index="*****"
| stats sum(field_A) AS field_A sum(field_B) AS field_B BY field_C

Ciao.

Giuseppe

View solution in original post

splunkuser320
Path Finder

Thanks for quick help 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @splunkuser320,

you cannot use two BY clauses in a stats command, please try this:

index="*****"
| stats sum(field_A) AS field_A sum(field_B) AS field_B BY field_C

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...