Splunk Search

Sort rows in tables

ghnwmlguy
Explorer

The results of a report show the following in a table:

-variable value

-Allowed 1

-Allowed_Tagged 1

-Blocked 2

-Quarantined 1

-Total 10

-Viruses 5

How can I change the order of Rows so that 'Total' shows up at the bottom?

Tags (1)
1 Solution

sideview
SplunkTrust
SplunkTrust

One simple way, is to back up a bit and instead of reordering a field, just let the Splunk search language do all the totalling for you.

It looks like you're actually getting the 'total' from the data itself, so you'd have to take that out. If you cant take it out one way or another from the 'main search', you can take it out of your stats output manually with another search clause.

Once it's not in there you can safely use the 'addcoltotals' command (its really a part of 'addtotals' so you can read the docs for 'addtotals')

<main search> | stats sum(value) as mySum by variable | search variable!="Total" | addcoltotals fieldname=mySum label=Total labelfield=mySum

what's that doing is saying -- add up all the columns and put the totals in a new row at the bottom, then in that row, set the value of the 'mySum' field to 'Total'.

View solution in original post

sideview
SplunkTrust
SplunkTrust

One simple way, is to back up a bit and instead of reordering a field, just let the Splunk search language do all the totalling for you.

It looks like you're actually getting the 'total' from the data itself, so you'd have to take that out. If you cant take it out one way or another from the 'main search', you can take it out of your stats output manually with another search clause.

Once it's not in there you can safely use the 'addcoltotals' command (its really a part of 'addtotals' so you can read the docs for 'addtotals')

<main search> | stats sum(value) as mySum by variable | search variable!="Total" | addcoltotals fieldname=mySum label=Total labelfield=mySum

what's that doing is saying -- add up all the columns and put the totals in a new row at the bottom, then in that row, set the value of the 'mySum' field to 'Total'.

ghnwmlguy
Explorer

search string:

| stats sum(value) by variable

0 Karma

ghnwmlguy
Explorer

I played with the sort command a little but found that it only worked with columns in tables. My search string goes like this:

| stats sum(value) by variable
where the log entries contain "variable=value"

I looked a way to create a table in this 'thing' but couldn't find anything. Not sure if I really want to put up a screen shot.

0 Karma

jrodman
Splunk Employee
Splunk Employee

Does this thing support screenshots? If so it might help.

You can modify the search to use the sort command to re-order the results. If you are looking for interactive reordering, I'm not aware of such a facility.

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!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...