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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
ajsjoshua
Specialist
Specialist

Age bucket sorting

Dear all,

I am using this in script for age bucket

If(Age <=10, '<10 Years',

    IF(Age >= 11 and Age < 20, '11 - 20',

  IF(Age >= 21 and Age < 30, '21 - 30',

  IF(Age >= 31 and Age < 40, '31 - 40',

  IF(Age >= 41 and Age < 50, '41 - 50',

  IF(Age >= 51 and Age < 60, '51 - 60',

  IF(Age >= 61 and Age < 70, '61 - 70',

  IF(Age >= 71 and Age < 80, '71 - 80',

  IF(Age >= 81 and Age < 90, '81 - 90',

  IF(Age >= 91 and Age < 100, '91 - 100',

'100+')))))))))) as AgeRange,

When i use this AgeRange dimension in bar chart i am not getting the dimension in proper  order.I want to sort like this

<10 Years,'11 - 20','21 - 30','31 - 40','41 - 50','51 - 60','61 - 70','71 - 80','81 - 90','91 - 100', '100+'

PFA for screenshot

1 Solution

Accepted Solutions
sunny_talwar

Try this

If(Age <=10, Dual('<10 Years', 1),

  IF(Age >= 11 and Age < 20, Dual('11 - 20', 2),

  IF(Age >= 21 and Age < 30, Dual('21 - 30', 3),

  IF(Age >= 31 and Age < 40, Dual('31 - 40', 4),

  IF(Age >= 41 and Age < 50, Dual('41 - 50', 5),

  IF(Age >= 51 and Age < 60, Dual('51 - 60', 6),

  IF(Age >= 61 and Age < 70, Dual('61 - 70', 7),

  IF(Age >= 71 and Age < 80, Dual('71 - 80', 8),

  IF(Age >= 81 and Age < 90, Dual('81 - 90', 9),

  IF(Age >= 91 and Age < 100, Dual('91 - 100', 10),

Dual('100+', 11))))))))))) as AgeRange,

View solution in original post

2 Replies
sunny_talwar

Try this

If(Age <=10, Dual('<10 Years', 1),

  IF(Age >= 11 and Age < 20, Dual('11 - 20', 2),

  IF(Age >= 21 and Age < 30, Dual('21 - 30', 3),

  IF(Age >= 31 and Age < 40, Dual('31 - 40', 4),

  IF(Age >= 41 and Age < 50, Dual('41 - 50', 5),

  IF(Age >= 51 and Age < 60, Dual('51 - 60', 6),

  IF(Age >= 61 and Age < 70, Dual('61 - 70', 7),

  IF(Age >= 71 and Age < 80, Dual('71 - 80', 8),

  IF(Age >= 81 and Age < 90, Dual('81 - 90', 9),

  IF(Age >= 91 and Age < 100, Dual('91 - 100', 10),

Dual('100+', 11))))))))))) as AgeRange,

Anil_Babu_Samineni

Try this, add similar to all

If(Age <=10, '<10 Years',

    IF(Age >= 11 and Age < 20, dual('11 - 20',1),

  IF(Age >= 21 and Age < 30, dual('21 - 30',2),

  IF(Age >= 31 and Age < 40, '31 - 40',

  IF(Age >= 41 and Age < 50, '41 - 50',

  IF(Age >= 51 and Age < 60, '51 - 60',

  IF(Age >= 61 and Age < 70, '61 - 70',

  IF(Age >= 71 and Age < 80, '71 - 80',

  IF(Age >= 81 and Age < 90, '81 - 90',

  IF(Age >= 91 and Age < 100, '91 - 100',

'100+')))))))))) as AgeRange,

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful