Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Brites
Contributor II
Contributor II

Sum values in the top three of a given column

Hello! I want to sum all the sales on the latest three weeks.

Week Sales
202140 10
202142 9
202142 10
202141 11
202140 10
202132 30
202131 50

 

In this example, i would want to sum only the top 3 highest weeks (202140,202141 and 202142), returning a total of 50.

The expression that i wrote is not working, which is:

Sum({<[week] = {'>$(=Max(week,4))'}>} [sales])

I am unsure on why this operation is returning zero. on the other hand if i try to do a similar calculation looking only at the top one week, the following expression works perfectly:

Sum({<[week] = {'$(=Max(week))'}>} [sales])

I seen to be having an issue with the "greater than" sign and how it is evaluating my results. can anyone help me?

1 Solution

Accepted Solutions
RsQK
Creator II
Creator II

Hi, when you're trying to use comparisons in the set analysis, you must use the double quotes (") instead of single quotes (')

So, the expression should look like this:

SUM({<Week={">$(=MAX(Week,4))"}>}Sales)

View solution in original post

1 Reply
RsQK
Creator II
Creator II

Hi, when you're trying to use comparisons in the set analysis, you must use the double quotes (") instead of single quotes (')

So, the expression should look like this:

SUM({<Week={">$(=MAX(Week,4))"}>}Sales)