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

Rolling N months average + filter/selection

Hello

I need help calculating 3 month average. It needs to work dynamically with selections and filter on date fields like YearMonth. Please see explanation below

Note: YearMonth has been generated from a date field (YYYY-MM-DD) so date field is available

YearMonthSales3M sales AVG
20170955
201710107,5
20171146,3
20171256,3
20180123,6
20180254
201803105,6
201804105

Expressions:

Sales = sum (sales)

3M sales AVG = rangeavg(above(sum(sales),0,3))

Now if I filter on a YearMonth for example 201804, I get same value in "3M sales AVG" column as I get in "Sales" column

I get for 201804

Sales3M sales AVG
1010

But I need it to be:

Sales3M sales avg
105

So same for other months for example 201801 I get 2+2 but I need 2+3.6...

I guess this is due to filtering on a YearMonth makes the rangeavg expression not work since it doesn't have access to the previous periods... so is there a solution for this? Preferably in expression itself. Or is an AsOf calendar required?

1 Reply
joeallen
Contributor III
Contributor III
Author

Note a little mistake 3M sales avg for 201804 should be 8.3 obviously not 5 (sorry)