Splunk Search

How do I insert a label into a field using the stats command?

alanbudd
Explorer

Good day

I have been trying to create a summary row for columns of a table. I started using the addcoltotals command and it does add the summary row I wanted. I also used the labelfield label command to format the table to look better for use in a report. I only want to keep the summary row and remove all the other rows. I therefore replaced the addcoltotals with stats sum (*) as * as recommended in
https://answers.splunk.com/answers/206455/how-do-display-only-the-total-row.html
However stats sum does not support the labelfield modifier.

Is there a way to either keep only the summary row with addcoltotals and suppress the other rows or else an equivalent to labelfield in the stats command?

0 Karma
1 Solution

somesoni2
Revered Legend

The labelfield property of addcoltotals is to provide a label (default Total) in the summary row under that field. If you're using stats, then just use an eval to create a field where you want this label should be available, like this

your search giving table with all values | stats sum(*) as * | eval YourLabelFieldName="Total" | table YourLabelFieldName *

View solution in original post

somesoni2
Revered Legend

The labelfield property of addcoltotals is to provide a label (default Total) in the summary row under that field. If you're using stats, then just use an eval to create a field where you want this label should be available, like this

your search giving table with all values | stats sum(*) as * | eval YourLabelFieldName="Total" | table YourLabelFieldName *

alanbudd
Explorer

Worked perfectly. Thanks

0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...