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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...