Conditional Weighted Average

lager1001

Board Regular
Joined
May 17, 2019
Messages
88
Need help with a weighted average formula. I've tried AverageIfs but get #DIV/0 errors because some of the numbers being calculated in the average are "0".

See below example.

There are 4 unique accounts (but 7 line items) in CW24, each with their respective Score. If I do a simple average, it takes all scores for all line items and I get 63.86. What I need is the weighted average so it calculates each score only once for each account and provide the average by the unique number of accounts for the calendar week. The desired outcome is the "Weighted Average Column" which would be 70.39+65.45+99.96+0.00 / 4. Some of my scores are 0.00 so these have to be inclusive to the formula. Can anyone assist?

Year/CWAccountScoreAverage ScoreWeighted Average
2020-CW24ABC70.3963.8658.95
2020-CW24ABC70.3963.8658.95
2020-CW24ABC70.3963.8658.95
2020-CW24ABC70.3963.8658.95
2020-CW24DEF65.4563.8658.95
2020-CW24GHI99.9663.8658.95
2020-CW24JKL0.0063.8658.95
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
=AVERAGE(IFERROR(C2:C8/IF(FREQUENCY(MATCH(B2:B8,B2:B8,0),MATCH(B2:B8,B2:B8,0))>0,1,0),FALSE))
 
Upvote 0
Hi
Thanks for the formula. I need this to include the Year/CW column as well. I tried adding it as a MATCH factor, but it is giving me the same results as the normal Average function. There are hundreds of accounts with various scores over the CWs throughout the year. That is the goal here. Is to get the weighted average per CW for each account.
 
Upvote 0
Book1
ABCDEFGH
1Year/CWAccountScore
22020-CW24ABC70.39
32020-CW24ABC70.392020-CW2467.5875
42020-CW24ABC70.392020-CW25158.96
52020-CW24ABC70.39
62020-CW24DEF100
72020-CW24GHI99.96
82020-CW24JKL0
92020-CW25ABC70.39
102020-CW25ABC70.39
112020-CW25ABC70.39
122020-CW25ABC70.39
132020-CW25DEF65.45
142020-CW25GHI500
152020-CW25JKL0
Sheet1
Cell Formulas
RangeFormula
H3:H4H3=AVERAGE(IF(IF(FREQUENCY(MATCH($A$2:$A$15&$B$2:$B$15,$A$2:$A$15&$B$2:$B$15,0),MATCH($A$2:$A$15&$B$2:$B$15,$A$2:$A$15&$B$2:$B$15,0))>0,TRUE,FALSE)=TRUE,IF($A$2:$A$15=G3,$C$2:$C$15),FALSE))
 
Upvote 0
Thanks again. But how can this be made dynamic? Each report will have different numbers of rows. Can I not use dynamic table header names instead of cells? I'm unable to get this to work in this format. I need the average to be in every row for every CW and Account regardless of how many times that Account appears (see original example).
 
Upvote 0
Book1
ABCD
1Year/CWAccountScore
22020-CW24ABC70.3967.5875
32020-CW24ABC70.3967.5875
42020-CW24ABC70.3967.5875
52020-CW24ABC70.3967.5875
62020-CW24DEF10067.5875
72020-CW24GHI99.9667.5875
82020-CW24JKL067.5875
92020-CW25ABC70.39158.96
102020-CW25ABC70.39158.96
112020-CW25ABC70.39158.96
122020-CW25ABC70.39158.96
132020-CW25DEF65.45158.96
142020-CW25GHI500158.96
152020-CW25JKL0158.96
Sheet1
Cell Formulas
RangeFormula
D2:D15D2=AVERAGE(IF(IF(FREQUENCY(MATCH($A$2:$A$15&$B$2:$B$15,$A$2:$A$15&$B$2:$B$15,0),MATCH($A$2:$A$15&$B$2:$B$15,$A$2:$A$15&$B$2:$B$15,0))>0,TRUE,FALSE)=TRUE,IF($A$2:$A$15=A2,$C$2:$C$15),FALSE))


Use Named Ranged instead of cell reference in case your ranges are dynamic in nature.
 
Upvote 0
If you convert your data to a structured table you can use it like
+Fluff New.xlsm
ABCD
1Year/CWAccountScoreWeighted Average
22020-CW24ABC70.3958.95
32020-CW24ABC70.3958.95
42020-CW24ABC70.3958.95
52020-CW24ABC70.3958.95
62020-CW24DEF65.4558.95
72020-CW24GHI99.9658.95
82020-CW24JKL058.95
92020-CW25ABC70.39158.96
102020-CW25ABC70.39158.96
112020-CW25ABC70.39158.96
122020-CW25ABC70.39158.96
132020-CW25DEF65.45158.96
142020-CW25GHI500158.96
152020-CW25JKL0158.96
sheet2
Cell Formulas
RangeFormula
D2:D15D2=AVERAGE(IF(IF(FREQUENCY(MATCH([Year/CW]&[Account],[Year/CW]&[Account],0),MATCH([Year/CW]&[Account],[Year/CW]&[Account],0))>0,TRUE,FALSE)=TRUE,IF([Year/CW]=[@[Year/CW]],[Score]),FALSE))
 
Upvote 0
Hmmm. Entered this exactly, and it pulls the same average for every line regardless of calendar week or account. Not sure what I'm doing wrong.
 
Upvote 0
You probably need to confirm the formula with Ctrl Shift Enter, rather than just enter & then fill it down.
 
Upvote 0
Here is example of what pulled as a result.

Year/CWAccountScoreColumn1
2019-CW46AAA0.0057.692108
2020-CW03BBB0.0057.692108
2020-CW03CCC0.0057.692108
2020-CW03CCC0.0057.692108
2020-CW03CCC13.0257.692108
2020-CW03DDD13.0257.692108
2020-CW03DDD13.0257.692108
2020-CW03DDD13.0257.692108
2020-CW03EEE55.1457.692108
2020-CW07EEE55.1457.692108
2020-CW07EEE55.1457.692108
2020-CW07EEE55.1457.692108
2020-CW07EEE55.1457.692108
2020-CW08FFF0.0057.692108
2020-CW08FFF0.0057.692108
2020-CW08FFF0.0057.692108
2020-CW08GGG57.3657.692108
2020-CW12GGG57.3657.692108
2020-CW12GGG57.3657.692108
2020-CW12GGG57.3657.692108
2020-CW12GGG57.3657.692108
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top