Splunk Search

Sort the average duration based on time rather than alphabetically

chitreshakumar
Communicator

I have an average duration field which has months ,days ,hours and minutes.I want it to be sorted descending order
-Months,days,hours and minutes
Ascending -minutes,hours,days and months

0 Karma
1 Solution

elliotproebstel
Champion

If you are displaying this data in a dashboard and want to display the duration field as you've currently formatted it but sort based on the numeric duration values, I would recommend an approach that uses fieldformat to display the values while maintaining the actual values in numeric format. Here's a link to another answer that uses this approach to display data with one set of formatting while sorting based on another:
https://answers.splunk.com/answers/585952/when-clicking-on-table-header-want-to-sort-by-case-1.html#...

So the general approach will be to have a field called, say, average_duration that contains a numeric value representing the total number of seconds in the duration. (Or, if your data is only granular to the minute, then the total number of minutes is also fine.) Separately, you'll have a field called display_duration that will be formatted to match your desired display format. At the end of your search string, you'll add:

| sort - average_duration 
| fieldformat average_duration=display_duration

Or if you wanted to sort the values in an ascending order, that would be:

| sort average_duration 
| fieldformat average_duration=display_duration

And then in the XML formatting for the table you are displaying, you'll use the <fields> tag to specifically indicate which fields you want to display. Presumably, this would be a list of all the fields you are currently displaying - and specifically, not the field display_duration.

Here's some more info about fieldformat:
http://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Fieldformat
And here is some useful info about the spec of a simpleXML dashboard, specifically about the options you can put within a table:
http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Viz/PanelreferenceforSimplifiedXML#table

View solution in original post

0 Karma

elliotproebstel
Champion

If you are displaying this data in a dashboard and want to display the duration field as you've currently formatted it but sort based on the numeric duration values, I would recommend an approach that uses fieldformat to display the values while maintaining the actual values in numeric format. Here's a link to another answer that uses this approach to display data with one set of formatting while sorting based on another:
https://answers.splunk.com/answers/585952/when-clicking-on-table-header-want-to-sort-by-case-1.html#...

So the general approach will be to have a field called, say, average_duration that contains a numeric value representing the total number of seconds in the duration. (Or, if your data is only granular to the minute, then the total number of minutes is also fine.) Separately, you'll have a field called display_duration that will be formatted to match your desired display format. At the end of your search string, you'll add:

| sort - average_duration 
| fieldformat average_duration=display_duration

Or if you wanted to sort the values in an ascending order, that would be:

| sort average_duration 
| fieldformat average_duration=display_duration

And then in the XML formatting for the table you are displaying, you'll use the <fields> tag to specifically indicate which fields you want to display. Presumably, this would be a list of all the fields you are currently displaying - and specifically, not the field display_duration.

Here's some more info about fieldformat:
http://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Fieldformat
And here is some useful info about the spec of a simpleXML dashboard, specifically about the options you can put within a table:
http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Viz/PanelreferenceforSimplifiedXML#table

0 Karma

mayurr98
Super Champion

can you provide some sample data values ?
are you converting it to Months,days,hours and minutes eventually in the query?
if you are converting then do a sort before conversion.
refer this documentation for sort command:
https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

Let me know if this helps!

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!

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 ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...