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: 
Not applicable

Weighted Average

Hi Community,

I need help on calculating a weighted average. A simple version of my problem and the accordant data look as follows:

machine    weight    time

A               60          4

A               80          9

A               90          8

A               1000      4

B               60          3

B               90          5

B               90          9

B               100        2

B               100        3

What I aim at is to calculate the weighted average of time for each of the machines (A & B) with the weight as the weighting factor.

Can anybody help me on this?

Thanks in advance!

1 Solution

Accepted Solutions
joshabbott
Creator III
Creator III

So the weight for a machine is out of the sum of all weight for that machine right:

sum(TOTAL <machine> weight) - For A this should give you 1230

So to get a percent, I would think you would need to divide the weight for the row into the total:

sum(weight) /  sum(TOTAL <machine> weight)

Then, would you multiply this by the time?

(sum(weight) /  sum(TOTAL <machine> weight)) * sum(Time)

View solution in original post

4 Replies
joshabbott
Creator III
Creator III

So the weight for a machine is out of the sum of all weight for that machine right:

sum(TOTAL <machine> weight) - For A this should give you 1230

So to get a percent, I would think you would need to divide the weight for the row into the total:

sum(weight) /  sum(TOTAL <machine> weight)

Then, would you multiply this by the time?

(sum(weight) /  sum(TOTAL <machine> weight)) * sum(Time)

marcus_sommer

Maybe so:

t1:

Load machine, sum(weight*time) / count(machine) as avg Resident xyz Group by machine;

- Marcus

MarcoWedel

Hi,

one solution:

table1:

LOAD machine,

    weight,

    Interval(time)as time

INLINE [

    machine, weight, time

    A, 60, 4

    A, 80, 9

    A, 90, 8

    A, 1000, 4

    B, 60, 3

    B, 90, 5

    B, 90, 9

    B, 100, 2

    B, 100, 3

];

table2:

LOAD machine,

    Interval(sum(weight*time)/sum(weight)) as average

Resident table1

Group By machine;

QlikCommunity_Thread_130450_Pic1.JPG.jpg

hope this helps

regards

Marco

Not applicable
Author

Thanks a lot. This helped me already... 😉