Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
etrietsch
Frequent Visitor

Calculating the weighted average gives me incorrect values?

Hi,

 

When using the "New quick measure" button to calculate a weighed for the following example, I get a formula that doesn seem right.

 

MaterialYearLength
ST1976400
ST1956120
PVC19962000
PVC20061200
GIJ1946200
GIJ1936320

 

When using Age, Year and Material as input, the generated formula is:

Age weighted by Length per Material = 
VAR __CATEGORY_VALUES = VALUES('Test data'[Material])
RETURN
	DIVIDE(
		SUMX(
			KEEPFILTERS(__CATEGORY_VALUES);
			CALCULATE(SUM('Test data'[Age]) * SUM('Test data'[Length]))
		);
		SUMX(
			KEEPFILTERS(__CATEGORY_VALUES);
			CALCULATE(SUM('Test data'[Length]))
		)
	)

 

 

But the results for the materials are not correct however. But when using a SUMX() instead of SUM()*SUM() the results ARE correct:

Age weighted by Sum Length per Material = 
VAR __CATEGORY_VALUES = VALUES('Test data'[Material])
RETURN
	DIVIDE(
		SUMX(
			KEEPFILTERS(__CATEGORY_VALUES);
			CALCULATE(SUMX('Test data';'Test data'[Age]*'Test data'[Length]);NOT(ISBLANK('Test data'[Age]));NOT(ISBLANK('Test data'[Length])))
		);
		SUMX(
			KEEPFILTERS(__CATEGORY_VALUES);
			CALCULATE(SUM('Test data'[Length]);NOT(ISBLANK('Test data'[Age]));NOT(ISBLANK('Test data'[Length]))
		)
	))

 

Does this mean I 'm doing something wrong or is the autogenerated formula not correct?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @etrietsch,

 

It seems like the normal measure calculate issue on total/summary level, maybe you can take a look at following link about measure total issue:

Measure Totals, The Final Word


Regards,

Xiaoxin Sheng

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @etrietsch,

 

It seems like the normal measure calculate issue on total/summary level, maybe you can take a look at following link about measure total issue:

Measure Totals, The Final Word


Regards,

Xiaoxin Sheng

LivioLanzo
Solution Sage
Solution Sage

Hi @etrietsch

 

the first formula does indeed not look correct, calculation needs to be at per row level;

 

in fact

( 1 X 10 ) + ( 5 X 3 ) does not equal ( 1+ 5 )  X ( 10 + 3)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hi @LivioLanzo, so does this mean that the autogen formula is incorrect and that this is a bug? As I now have to manually correct the formula...

it does not look too correct to me, if you post a dataset and expected results we can make a new formula

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hi @LivioLanzo In my question I already posted the correct version of the formula: this one works as expected. But I was wondering why the 'out of the box' formula is incorrect? Is it a bug or is do I use the wizard incorrectly? 

Hi @etrietsch,

 

the first formula is incorrect because it is doing a multiplication of the sum instead of a sum of the multiplication which is what the second formula is doing

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors