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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
test_engineer
Contributor
Contributor

Weighted Average of Averages by selection from a filter on a chart

Hi there;

I have some aggregated data (example in table below) I have already calculated the averages and also brought in the counts to hopefully enable what I want to do. It is partially working but not 100% how I want to (may not be possible? or I am very close but missing something)

week event type worked_days (this is an avg)

week_counts

(count of event which avg is based on)

03/01/2022 event_a 2 2
10/01/2022 event_a 1.67 6
17/01/2022 event_a 1.2 5
24/01/2022 event_a 2.33 3
31/01/2022 event_a 2 1

 

I have a qlik chart and the dates listed. My chart has filters of week, and event type (there are more event types this example is just the same event)

So using the standard 

 

 

=Sum(worked_days*week_counts)/Sum(week_counts)

 

 

 I get worked_days displaying as is on the chart (if I combine with another event it seems to work OK in terms of weighted avg btw).

If I use:

 

 

=Sum(worked_days*week_counts)/Sum(Total week_counts)

 

 

It displays the weighted values, i.e (if I was to sum them all it would be correct).

This displays the value I want but always as a constant.

 

 

=Sum(Total worked_days * Aggr(Sum(week_counts), worked_days)) / Sum(Total Aggr(Sum(week_counts), worked_days))

 

 

Its almost like I want a rolling cumulative avg based on selection

i.e. if I select three dates, it plots 1 data point as the first mean, then the 2nd data point as the weighted mean of the two, then the third data point as the weighted mean for the three selected dates (not necessarily consecutive dates, any selected dates - all my dates are start_of_week dates)

i.e. in the chart I ideally would like the first data point would be 2,

second would be 1.75 =(2*+ 1.67*6)/(2+6)

third would be 1.54 =(2*+ 1.67*+ 1.2*5)/(2+6+5)

Thanks in advance.

0 Replies