Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

order by TimeBand

Hi, I have a field called TimeBand that contains the following data:

> 5y
1m
2 and
3m
3y
4y
5y
6m
12m
1d
7d
1m
2m
3m
6m
1y
2 and
3y
4y
5y
+ 5y

As you can see are periods of time. I need to sort them from minor to major but I do not know how to do it. What I want is for it to look like this: (days, months, years)

1d
7d
1m
2m
3m
6m
12m
1y
2 and
3y
4y
5y
> 5y


Thanks

Labels (1)
6 Replies
Anonymous
Not applicable
Author

Try this in "Sort by Expression":

if(wildmatch(Period,'>*'),4,if(wildmatch(Period,'*and'),3,if(wildmatch(Period,'*d'),1,if(wildmatch(Period,'*m'),2,if(wildmatch(Period,'*y'),3,5)))))

Anonymous
Not applicable
Author

Thanks Aron,

the field where I get that data is called 'bucket', do I have to change the word period for bucket?

Anonymous
Not applicable
Author

Yes change the the word period for bucket or whatever the field name is.

sunny_talwar
MVP
MVP

Are these bands created in the script? I would suggest using dual function while your create these bands and then you can easily sort on numerically

Anonymous
Not applicable
Author

it is a field that comes like this from an excel.

How is that function you are talking about?

thanks

sunny_talwar
MVP
MVP

You can read about Dual here:

How to use- Dual()

Alternatively, you can use Mapping load to assign a numerical value to your field in the script.