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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
cheryl
Contributor III
Contributor III

Moving average 3 months in script

HI Community,

I have a table like this:

Load
Month,
Avg([Results]) as Results
resident Survey_results
where "Respondent Unit"='SL'
group by Month;

 

This will give a number every month; e.g.

Jan-22: 3;

Feb-22: 4;

Mar-22: 5;

Apr-22: 3.5;

 

I would like to create another table which shows the moving average of 3 months, which is (this month + previous 2 months)/3.

So the new table will look like:

Mar-22 : (3+4+5)/3 = 4

Apr-22 : (4+5+3.5)/3 = 4.167

 

How should I write script in Qliksense that can give me such table?

 

Thanks!

Cheryl

Labels (3)
1 Solution

Accepted Solutions
QFabian
MVP
MVP

Hi @cheryl , please try something like this, using inter record function 'previous' or peek. 

Check both for your understanding.

https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterReco...

 

Data:
Load
Month,
Avg([Results]) as Results
resident Survey_results
where
"Respondent Unit"='SL'
group by
Month;

Data_3:
Load
Month,
(Results + previous(Result) + previous(previous(Result))) / 3 s Result_Mov1
(Results + peek(Result) + peek(Result, 2)) / 3 s Result_Mov2
Resident Data
order by
Month;

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.

View solution in original post

1 Reply
QFabian
MVP
MVP

Hi @cheryl , please try something like this, using inter record function 'previous' or peek. 

Check both for your understanding.

https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterReco...

 

Data:
Load
Month,
Avg([Results]) as Results
resident Survey_results
where
"Respondent Unit"='SL'
group by
Month;

Data_3:
Load
Month,
(Results + previous(Result) + previous(previous(Result))) / 3 s Result_Mov1
(Results + peek(Result) + peek(Result, 2)) / 3 s Result_Mov2
Resident Data
order by
Month;

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.