Splunk Search

How to drop extra fields while maintaining groupby?

yuanliu
SplunkTrust
SplunkTrust

To groupby?  Or not to groupby?  That is the question. (Not really.  The question arises because trellis splitby seems to depend on an invisible groupby register.)

Take the following example:

 

 

| makeresults count=10
| eval value = "value" . random() % 3
| stats count by value
| eventstats sum(count) as total
| eval ratio = count / total

 

 

If I want to visualize ratio as single value in trellis, I can add `| fields - total count` in the end.

groupby.png

But if there are many intermediate variables, it gets tedious to list them for dropping.  I thought `table value ratio` would be simpler, as statistics table is exactly the same, but SPL's invisible hand prevents splitby from seeing the original groupby field, so I get weird output like

groupbynot.png

I can avoid tedious `fields -` listing by doing another stats with groupby, e.g., `stats values(ratio) as ratio by value`.

groupbydouble.png

 But I feel silly to do a useless calculation.  Is there a simpler way to preserve groupby register without the tedious listing?

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

is there any SPL answer to the original question?

The answer, it turns out, is yes.  Instead of listing intermediate field names for exclusion, name all intermediate fields to be "hidden", i.e., start with underscore _.  The above search can be written as

| makeresults count=10
| eval value = "value" . random() % 3
| stats count as _count by value
| eventstats sum(_count) as _total
| eval ratio = _count / _total

Splunk visualization will conveniently ignore hidden fields.

Screenshot 2026-01-21 at 12.49.26 PM.png

This writing has more elaborate use cases of this technique: Up Your Textual Viz with Splunk.

View solution in original post

0 Karma

yuanliu
SplunkTrust
SplunkTrust

I just realize that I can carefully name intermediate variables so I can drop them with wildcard.  But is there any SPL answer to the original question?

Tags (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

is there any SPL answer to the original question?

The answer, it turns out, is yes.  Instead of listing intermediate field names for exclusion, name all intermediate fields to be "hidden", i.e., start with underscore _.  The above search can be written as

| makeresults count=10
| eval value = "value" . random() % 3
| stats count as _count by value
| eventstats sum(_count) as _total
| eval ratio = _count / _total

Splunk visualization will conveniently ignore hidden fields.

Screenshot 2026-01-21 at 12.49.26 PM.png

This writing has more elaborate use cases of this technique: Up Your Textual Viz with Splunk.

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...