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!

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...