Splunk Search

Why are the numbers not sorted as expected in my chart?

changux
Builder

Hi all.

I have this search:

index="bucle_cm" sourcetype="cierres-pendientes" "Tipo Actuacion"="*" "Tipo Actuacion"!=Bajas EMPRES="*" | sort num("DIA CIERRE") | chart count by "Tipo Actuacion","DIA CIERRE" limit=0 | addcoltotals  | addtotals fieldname=Total

Where "DIA CIERRE" is a number field with values like 1,2,3,4,10,11..etc.

The result set looks like this:

alt text

Why are the numbers not sorted?

Thanks!

0 Karma
1 Solution

sundareshr
Legend

how about something like this

....| eval "DIA CIERRE"=if(len("DIA CIERRE")=1, "0".'DIA CIERRE', 'DIA CIERRE') | chart count over "TIPO"  by "DIA CIERRE"

Then max value wouldn't matter
Full search

index="bucle_cm" sourcetype="cierres-pendientes" "Tipo Actuacion"="*" "Tipo Actuacion"!=Bajas EMPRES="*" .| eval "DIA CIERRE"=if(len("DIA CIERRE")=1, "0".'DIA CIERRE', 'DIA CIERRE') | chart count over "TIPO"  by "DIA CIERRE" | addcoltotals  | addtotals fieldname=Total

View solution in original post

somesoni2
Revered Legend

Give this a try (assuming "DIA CIERRE" always starts with 1.

index="bucle_cm" sourcetype="cierres-pendientes" "Tipo Actuacion"="*" "Tipo Actuacion"!=Bajas EMPRES="*" | chart count by "Tipo Actuacion","DIA CIERRE" limit=0 | addcoltotals  | addtotals fieldname=Total | table [search index="bucle_cm" sourcetype="cierres-pendientes" "Tipo Actuacion"="*" "Tipo Actuacion"!=Bajas EMPRES="*"  | stats max("DIA CIERRE") as t | eval search=mvrange(1,t,1) | stats list(search) as search delim="," | nomv search ]
0 Karma

sundareshr
Legend

how about something like this

....| eval "DIA CIERRE"=if(len("DIA CIERRE")=1, "0".'DIA CIERRE', 'DIA CIERRE') | chart count over "TIPO"  by "DIA CIERRE"

Then max value wouldn't matter
Full search

index="bucle_cm" sourcetype="cierres-pendientes" "Tipo Actuacion"="*" "Tipo Actuacion"!=Bajas EMPRES="*" .| eval "DIA CIERRE"=if(len("DIA CIERRE")=1, "0".'DIA CIERRE', 'DIA CIERRE') | chart count over "TIPO"  by "DIA CIERRE" | addcoltotals  | addtotals fieldname=Total

somesoni2
Revered Legend

This could work just fine...since max value is 31 (2 digit)
Much simpler than mine...

0 Karma

changux
Builder

Works great! Awesome @somesoni2. Thanks a lot!!

0 Karma

changux
Builder

Hi.
I tried first:

| eval "DIA CIERRE"=if(len('DIA CIERRE')=1, "0".y, y) | table "DIA CIERRE"

And not results. Can you explain please your idea?

0 Karma

somesoni2
Revered Legend

Replace y with 'DIA CIERRE'.

0 Karma

somesoni2
Revered Legend

The field names in Splunk are treated as alphanumeric string, not number, hence the column ordering you see here. The sort command before the chart will not have any effect on the output of the chart command.

0 Karma

changux
Builder

Thanks. Putting the sort after the chart command give the same ordering issue.

0 Karma

somesoni2
Revered Legend

There is no good way to sort columns with numbers in it. Do you know if "DIA CIERRE" has fixed number of values??

0 Karma

changux
Builder

"DIA CIERRE" is a day in a month, so, in the worst case, you have 31 as fixed value.

0 Karma

somesoni2
Revered Legend

Does it's value depends upon the time range you run the query for? In other words, is there a way I can find out the max value of "DIA CIERRE" which your search is going to return? I've a workaround but I need to know the max value (and the start value).

0 Karma

changux
Builder

With a subsearch like:

| stats max("DIA CIERRE")

We can obtain this one. In the last case is 11.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...