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!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...