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: 
rvijayanth
Creator
Creator

How to sort either ascending or descending based on variable selection using expression

I have a table with dimensions Gender or Age  or Class in column 1 and counts in column 2

Based on a user set variable (A, B or C), column 1 shall show (gender, age or Class) and Column 2 is a measure called count (ID)

I'm looking to sorting this table like this:

If variable is set to A or B, I need it to match my below mention order  in Column 1 (for age and sex),

If variable is C, the sorting shall be descending of column 2

The first two line of below expression works fine, but if variable is set to C, the descending of count is not working correctly.

if (vR = 'A', Match([Age], '0-1 Month', '2 Month-2 Years', '3-11 Years'),

if (vR = 'B', 'Sex', Match(Sex, 'Male', 'Female', 'Unknown'),

if (vR = 'C', COUNT(distinct CASE_ID_INT)))

1 Reply
rvijayanth
Creator
Creator
Author

The solution in this link worked.

I just added 1/count (ID). It worked.

Control Ascending/Descending