Splunk Search

How to rearrange below numeric columns based on order?

Ashwini008
Builder

Hi,

I have to rearrange below columns in below order

i.e. 31-60 Days, 61-90 Days, 91-120 Days,151-180 Days,Over 180 Days, Total

Query: 

| inputlookup ACRONYM_Updated.csv
|stats count by ACRONYM Aging
|xyseries ACRONYM Aging count
|addtotals

Ashwini008_0-1677047440146.png

 

Labels (1)
Tags (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

There are a number of techniques to solve this.

First one is to make your dashboard create a token that represents. the fields that are to be included in the table and simply use that token in the table statement - i.e.

| table $field_order_token$

that token is calculated in the same place that determines which fields are included.

Second one is the use of a prefix to force the column ordering in the xyseries, followed by a double transpose, which does not change field order when flipping, so this example shows how

| makeresults count=100
| eval Aging=mvindex(split("31-60 Days,61-90 Days,91-120 Days,151-180 Days,Over 180 Days", ","), random() % 5)
| eval ACRONYM=mvindex(split("RTFM,WYSIWIG,OK", ","), random() % 3)
``` Simulated data setup above ```
| stats count by ACRONYM Aging
``` Prefix the value with a sort order ```
| eval Aging=case(Aging="31-60 Days", 1, Aging="61-90 Days", 2, Aging="91-120 Days", 3, Aging="151-180 Days", 4, Aging="Over 180 Days", 5).":".Aging
| xyseries ACRONYM Aging count
``` Now flip the table and remove the sort element and flip back - no field re-order occurs ```
| transpose 0 header_field=ACRONYM
| eval column=replace(column, "^\d:", "")
| transpose 0 header_field=column

Note that you can replace your stats + xyseries with a single operation

| chart count over ACRONYM by Aging

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Just table the columns as you need them

| table ACRONYM "31-60 Days" "61-90 Days" "91-120 Days" "151-180 Days" "Over 180 Days" Total
0 Karma

Ashwini008
Builder

@bowesmana Based on user selection from the dashboard the data keeps changing as below. So i cannot table it since depending on user selection data will be displayed in dashboard. Irrespective of any selection the days should sorted in order. Can we do that in query

Example 

Ashwini008_0-1677066264463.png

Ashwini008_1-1677066300741.png

 

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

There are a number of techniques to solve this.

First one is to make your dashboard create a token that represents. the fields that are to be included in the table and simply use that token in the table statement - i.e.

| table $field_order_token$

that token is calculated in the same place that determines which fields are included.

Second one is the use of a prefix to force the column ordering in the xyseries, followed by a double transpose, which does not change field order when flipping, so this example shows how

| makeresults count=100
| eval Aging=mvindex(split("31-60 Days,61-90 Days,91-120 Days,151-180 Days,Over 180 Days", ","), random() % 5)
| eval ACRONYM=mvindex(split("RTFM,WYSIWIG,OK", ","), random() % 3)
``` Simulated data setup above ```
| stats count by ACRONYM Aging
``` Prefix the value with a sort order ```
| eval Aging=case(Aging="31-60 Days", 1, Aging="61-90 Days", 2, Aging="91-120 Days", 3, Aging="151-180 Days", 4, Aging="Over 180 Days", 5).":".Aging
| xyseries ACRONYM Aging count
``` Now flip the table and remove the sort element and flip back - no field re-order occurs ```
| transpose 0 header_field=ACRONYM
| eval column=replace(column, "^\d:", "")
| transpose 0 header_field=column

Note that you can replace your stats + xyseries with a single operation

| chart count over ACRONYM by Aging

 

Ashwini008
Builder

@bowesmana  Thank You. Works perfect 

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...