Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Sum last three month sales and only maximum number in last 3 months

Hello all,

I need help with the following: Sum last three month sales and only maximum number in last 3 months.

based on the maximum version, i need to sum the sales amount.

Ex- If i selected 4th month, I will sum the values month 4 - sales 35 ,month 3- sales 20 and month 2 - sales 40. so finally i will get 95.

Thanks in advance.

monthversionsales
1110
1220
1330
2110
2250
2330
2440
3110
3220
4110
4210
4320
4415
4535
4635
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

It's working nice. Thanks a lot.

View solution in original post

11 Replies
devarasu07
Master II
Master II

Hi,

Try like this in your expression

=FirstSortedValue(Distinct Aggr(Max(sales),month,version),-Aggr(Max(sales),month,version))

Anil_Babu_Samineni

May be this?

Max({<month = {'> $(=Max(month-3)) <=$(=Max(month))'}, version = {'<=$(=Max(version))'}>}sales)

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
Anil_Babu_Samineni

Or this?

Max({<month = {'> $(=Max(month-3)) <=$(=Max(month))'}, version = {'<=$(=FirstSortedValue(sales, Aggr(Max(version), version)))'}>}sales)

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
Digvijay_Singh

Like this -

Don't forget to change the total mode to Sum of rows.

Capture.PNG

sunny_talwar

Try this

=Sum({<month = {"$(='>=' & (Max(month) - 2) & '<=' & Max(month))"}>}Aggr(FirstSortedValue(sales, -version), month))


Capture.PNG

sunny_talwar

I think the OP is not looking to pick max sales, but sales associated with max version

Digvijay_Singh

Ya, missed that, this works -

Firstsortedvalue({<month={">=$(=Max(month)-2)<=$(=Max(month))"}>}sales,-version)

Digvijay_Singh

Updated one, missed version condition earlier..

Anonymous
Not applicable
Author

The above expression shows only maximum values of the selected month only.