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: 
chrisjones16
Contributor
Contributor

Need some help calculating an average

Hi All,

Hoping someone could help me out with a calculation im trying to build. I have attached a quick snapshot of dummy data to help explain this better.

Below is the granular data (Item 1.), what im trying to do is build a 6 month rolling metric. The way this needs to be calculated is by adding up the last 6 months pass rate by each month (e.g. Item 2. see below)  and then dividing by six.

So for example if the user selects June , i need to calculate the pass rate the by last six months on a monthly basis (Jun2019, May2019, Apr2019 etc)  then sum the monthly pass rates and divide by 6.  (item 3.)

(pass rate = students passed/ no of students)

Any help would be greatly appreciated.

Item 1.

Row_dateNo Of StudentsStudents passed
04/11/201821
07/11/201843
23/11/201821
04/12/201876
12/12/201887
15/12/201844
19/12/201865
21/12/201821
01/01/201943
04/01/201911
11/01/201999
01/02/201921
11/02/201943
20/02/201921
02/03/201976
19/03/201965
05/04/201943
10/04/201965
20/04/201955
11/05/201943
18/05/201943
21/05/201998
11/06/201966
17/06/201975

 

Item 2.

Monthpass rate
Dec-1895
Jan-1992
Feb-1990
Mar-1997
Apr-1992
May-1992
Jun-1990

 

Item 3. 

Final output needed

 rolling 6 month pass rate
Dec-18 
Jan-19 
Feb-19 
Mar-19 
Apr-19 
May-1996% (sum( Dec18 to May19)/6)
Jun-1992 % (sum( Jan19 to Jun19)/6)
6 Replies
JordyWegman
Partner - Master
Partner - Master

Hi Chris,

Some questions before the solution..

  1. Do you have item two already prepared? Or does it start at one?
  2. Can we prepare item three in the script? This would be a lot easier

Jordy

Climber

Work smarter, not harder
chrisjones16
Contributor
Contributor
Author

Hi , thanks for getting back. No it starts with item1 but could prepare it in the script. Not sure how i would approach that.
sunny_talwar

Not sure how you are getting your numbers within Item 2... but may be see if this is what you want?

image.png

chrisjones16
Contributor
Contributor
Author

Thanks Sunny,  yes the way you have shown is how i get the percentages in item2 . Will give  your range avg calculation a go which looks promising.

Could you help me understand why the    *Avg(1)  is needed?

 

sunny_talwar

I used that to make sure that if you select June, it only shows June. Without Avg(1), it will show all the Months because I am ignoring selection in Month in the inside aggregation to be able to calculate RangeAvg() over 6 months.

chrisjones16
Contributor
Contributor
Author

Hi,

i implemented your solution and it works great but i want to take it further.  This works fine if i have all the months present(no date filtered). But if i filter by may2019 the data gets filtered by May and the calculation doesnt work as it only shows  the may pass rate not the previous 6 months(including may).

How can i get the result to include the previous 6 months when a users filters by a specific month.

this is a measure which im looking to add to a kpi object in qliksense .

 

Thanks