Splunk Search

Make a stats by value a separate field

ebs
Communicator

I've performed a stats by command I was wondering if there was a way to store all these as fields and then for the by field which has returned 0 make it null.

For context I performed an eval field to create a new field on via case then performed a stats by command.

stats command: stats avg(response_time) by category

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Have you considered transpose?

| transpose 0 header_field=value

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @ebs,

I'm not sure to understood your questions:

you want to know how to pass all fields after a stats command and how to manage values where the BY fields are null, is it correct?

If this is your need:

it's better to have in the stats command only the fields you need so you use less memory, but if you want to have all the fields, you could use values(*) AS * , but I don't like.

Abouth the null BY fields, you can use the fillnull command (adding e.g. "-") before the stats command, in this way you're sure that all the events have a value for the BY fields.

Ciao.

Giuseppe

0 Karma

ebs
Communicator

Hi @gcusello,

To explain further when I do my stats avg by command I have one column of field values and one column of correlating stats values. What I want to do is take the stats value and then assign it a field with the name of the corresponding field value e.g. if the avg of a = 3 and the avg of b = 5 I then want a field created called a, where the field value is 3 and another field called b where the value is 5. If there is then a value of c where there are no results, I want that created into a field and then do a fillnull command.

Also I specifically wanted the fillnull value for the created stats field

Thanks!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Have you considered transpose?

| transpose 0 header_field=value

ebs
Communicator

Thanks so much! I didn't even think of this command

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @ebs,

in the stats command you can assign the field name as you want, e.g. something like this:

| stats avg(a) AS a avg(b) AS b BY c

and anyway, you have the rename command to change a field name.

about the null values, you have to try to use the fillnull command.

Ciao.

Giuseppe

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...