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

RANGE SUM per product on the three previous values

Hi
I would like to be able to calculate the sum of the three previous days as in the example below where I can estimate the total sales over the last three days by product...

I have already started to make a first formula just to sum the last three values, and it works well:

RangeSum(above(TOTAL Sum(Sales),0,3))

Where I have trouble is to get the sum of the last three days but by product, it does not work with this formula:

RangeSum(above(TOTAL Sum({<Product}Sales),0,3))

Below, here is what the result should look like

DATEProductSalesLast 3 days sales
01/01/2019APPLE22
01/01/2019ORANGE11
01/01/2019BANANA1010
02/01/2019APPLE13
02/01/2019ORANGE12
02/01/2019BANANA2030
03/01/2019APPLE47
03/01/2019ORANGE24
03/01/2019BANANA1040
04/01/2019APPLE49
04/01/2019ORANGE47
04/01/2019BANANA535
05/01/2019APPLE412
05/01/2019ORANGE1016
05/01/2019BANANA116

 

Here is the source file attached,

Thank you very much.

 

Labels (2)
1 Solution

Accepted Solutions
Tomas
Contributor
Contributor

Hi @lotitolo,

 this should help: 

Aggr(RangeSum(above(sum(Sales),0,3)),Product,DATE)

Extremely important here is order of dimension in arguments. Because

Aggr(RangeSum(above(sum(Sales),0,3)),DATE,Product)

will give you unwanted result thanks to different ordering

View solution in original post

2 Replies
Tomas
Contributor
Contributor

Hi @lotitolo,

 this should help: 

Aggr(RangeSum(above(sum(Sales),0,3)),Product,DATE)

Extremely important here is order of dimension in arguments. Because

Aggr(RangeSum(above(sum(Sales),0,3)),DATE,Product)

will give you unwanted result thanks to different ordering
lotitolo
Contributor III
Contributor III
Author

Thank you very much, this solution works perfectly!