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

Simple Average Problem

Hi

I'm trying to calculate sum of the average but getting Qlik is not calculating it correctly.

I have a simple table,

tab5.PNG

I need to take average of the last three dates only. I'm using this expression:

sum(

aggr(if(Rank(Only({<Date={"=Len(Only(Date))>1"}>}Date))<4,

  sum( aggr(sum(Sale),ID,Date))

  / count(aggr(count(DISTINCT Date),ID,Date))

  ),ID,Date)

  )

If I use avg instead of sum it shows correct average but I need to be able to sum the average calculated. Can anyone help?

Thanks

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Guys

I've resolved it using the following expression

sum(

aggr(if(Rank(Only({<Date={"=Len(Only(Date))>1"}>}Date))<4,

  sum( aggr(sum(Sale),ID,Date))

  / sum(TOTAL <ID>aggr(if(Rank(Only({<Date={"=Len(Only(Date))>1"}>}Date))<4,count(DISTINCT Date)),ID,Date))

  ),ID,Date)

  )

tab6.PNG

View solution in original post

1 Reply
Anonymous
Not applicable
Author

Guys

I've resolved it using the following expression

sum(

aggr(if(Rank(Only({<Date={"=Len(Only(Date))>1"}>}Date))<4,

  sum( aggr(sum(Sale),ID,Date))

  / sum(TOTAL <ID>aggr(if(Rank(Only({<Date={"=Len(Only(Date))>1"}>}Date))<4,count(DISTINCT Date)),ID,Date))

  ),ID,Date)

  )

tab6.PNG