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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Kaushik2020
Creator III
Creator III

How to change value based on Rank

Dear All, 

I have a below expression as a measure --> Value Column

Avg(Aggr(Sum({$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>}
Value),Code, Id)

The above expression generates value, -2, -1, 0, 1, 2 respectively.

Further below is my background expression to highlight top 10.

If(Rank(total Num(Avg(Aggr(Sum({$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>}
Value),Code, Id),'#,##0%')<=10,'#3D8D7A')

Requirement:

If the Value column is negative and in Top 10 (Green) and the value is -1 or -2, then change it to 2. Refer below sample.

kaushi2020_2-1743050568285.png

thanks in advance. 

1 Solution

Accepted Solutions
henrikalmen
Specialist II
Specialist II

And you could probably shorten the expression by moving the set expression outside:

{$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>} if(match( Avg(Aggr(Sum(Value),Code, Id), -1, -2) and Rank(total Num(Avg(Aggr(Sum(Value),Code, Id),'#,##0%')<=10, 2, Avg(Aggr(Sum(Value),Code, Id))

View solution in original post

2 Replies
henrikalmen
Specialist II
Specialist II

Something like this: if(match([expression1], -1, -2) and [expression2]<=10, 2, [expression1])

So that would be:

if(match( Avg(Aggr(Sum({$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>}
Value),Code, Id), -1, -2) and Rank(total Num(Avg(Aggr(Sum({$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>}
Value),Code, Id),'#,##0%')<=10, 2, Avg(Aggr(Sum({$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>}
Value),Code, Id))

henrikalmen
Specialist II
Specialist II

And you could probably shorten the expression by moving the set expression outside:

{$<Year=, Month=, Day=,
Date={">=$(=date(monthstart(max(Date))))<=$(=date(max(Date)))"}>} if(match( Avg(Aggr(Sum(Value),Code, Id), -1, -2) and Rank(total Num(Avg(Aggr(Sum(Value),Code, Id),'#,##0%')<=10, 2, Avg(Aggr(Sum(Value),Code, Id))