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!

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!

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 ...