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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...