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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
markgraham123
Specialist
Specialist

Calculating average in set analysis

(Avg(Aggr(Sum({<[Recent 7 Days] -= {'-'}>}eaches ),[Recent 7 Days]))) /

Avg((Aggr(Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs ),[Recent 7 Days])))

Hi all,

i'm using above script to calculate average of 'eaches' consumed in recent 7 days.

Although it is giving me the average, i do not wanna divide the average eaches in recent 7 days with

average hrs logged in.

I'm trying to divide sum of eaches / sum of logged in hrs. (Still having the condition Recent 7 Days <> '-'


Not working:

(Aggr(Sum({<[Recent 7 Days] -= {'-'}>}eaches ),[Recent 7 Days]))) /

((Aggr(Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs ),[Recent 7 Days])))

Any help is highly appreciated!

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Not sure if I understand, but in general, use (outer) aggregation functions

Sum(Aggr(Sum({<[Recent 7 Days] -= {'-'}>}eaches ),[Recent 7 Days]))) /

Sum((Aggr(Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs ),[Recent 7 Days])))

edit: Or maybe you don't need to group by [Recent 7 Days]?

=Sum({<[Recent 7 Days] -= {'-'}>}eaches ) /  Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs )

View solution in original post

2 Replies
swuehl
MVP
MVP

Not sure if I understand, but in general, use (outer) aggregation functions

Sum(Aggr(Sum({<[Recent 7 Days] -= {'-'}>}eaches ),[Recent 7 Days]))) /

Sum((Aggr(Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs ),[Recent 7 Days])))

edit: Or maybe you don't need to group by [Recent 7 Days]?

=Sum({<[Recent 7 Days] -= {'-'}>}eaches ) /  Sum({<[Recent 7 Days] -= {'-'}>}duration_logged_in_Hrs )

markgraham123
Specialist
Specialist
Author

Thanks a lot swuehl

I learnt a good thing about set analysis