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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
vishnus85
Partner - Creator
Partner - Creator

Help with expression : Avg of latest 7 cases

Hi,

We have a measure field as "Duration" for each "Case_number". We have another field named "Case_Date" that would allow us to sort the cases based on the its occurrence date.

My requirement is to find the Avg(Duration) for the latest 7 Cases ( based on Case_Date) for a particular selection.

Can anyone help me frame this expression

Regards,

Vishnu S

5 Replies
swuehl
MVP
MVP

Maybe like

=RangeAvg(

FirstSortedValue(Duration, -Case_Date,1),

FirstSortedValue(Duration, -Case_Date,2),

FirstSortedValue(Duration, -Case_Date,3),

FirstSortedValue(Duration, -Case_Date,4),

FirstSortedValue(Duration, -Case_Date,5),

FirstSortedValue(Duration, -Case_Date,6),

FirstSortedValue(Duration, -Case_Date,7)

)

vishnus85
Partner - Creator
Partner - Creator
Author

swuel,

That should work. But there might a better solution, one which doesnt need the statemenst to be repeated.

Not applicable

Hi,

     it can be done in load script itself.

can you please attach your sample file here. So it will be easy to understand the problem.

Thanx,

Ashutosh

tresesco
MVP
MVP

Try something like:

=Avg(Aggr(If(rank(Case_Date)<8,Duration),Case_Date))

Not applicable

If you are working in a chart, use something like this:

RangeAvg(Above(Sum(x),0,7))