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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MisterFry
Resolver III
Resolver III

Percent of column total inside SUMX.

I have a single table of sales by item in various currencies. In order to calculate a weighted price to index against the USD currency, I need to take the price of the item, and multiply it by the item's unit contribution to the grand total. 

Basically, I need the sum of the sold units for a particular style, over the total number of units sold. 

I can calculate the percent of grand total in a measure easily enough:

 

Sales Unit Contribution = 
VAR unitSales = CALCULATE(SUM(VW_SALES_DETAILS[REG_SLS_U]),ALL(VW_SALES_DETAILS[CURRENCY_CODE],VW_SALES_DETAILS[COUNTRY_NAME]))
VAR totalSales = CALCULATE(SUM(VW_SALES_DETAILS[REG_SLS_U]), all(VW_SALES_DETAILS[STYLE],VW_SALES_DETAILS[CURRENCY_CODE],VW_SALES_DETAILS[COUNTRY_NAME]))
RETURN
DIVIDE(unitSales, totalSales)

 

Works great. 
Now, I need to use that Sales Unit Contribution as a weighting against the item's price and sum the total for all items. 
I want to do this: 

 

SUMX(VW_SALES_DETAILS, VW_SALES_DETAILS[Sales Unit Contribution] * VW_SALES_DETAILS[Average Price_])

 

 But, I believe that what is happening is that because of context switching, the universe of the 'grand total' inside the sumx is limited to just that single row, so, of course, the Sales Unit Contribution is the sum of sales units over the sum of sales units, which is 1. 
How can I calculate this weighted average price measure?

1 ACCEPTED SOLUTION

Ok, hard to diagnose without seeing the full table but you want to do something like:

 

SUMX(
	VW_SALES_DETAILS, 
	VAR Contribution = 
		CALCULATE (
			VW_SALES_DETAILS[Sales Unit Contribution],
			REMOVEFILTERS (VW_SALES_DETAILS),
			VALUES( VW_SALES_DETAILS[Column1] ),
			VALUES( VW_SALES_DETAILS[Column2] ),
			VALUES( VW_SALES_DETAILS[Column3] )
		)	
			
	RETURN
		Contribution * VW_SALES_DETAILS[Average Price_]
)

 

Where Column1, Column2, Column3... etc are the columns you need the Contribution to depend on. You could use ALLEXCEPT but I find the above syntax easier to control.

 

If that doesn't work I'd need to see a demo pbix file with a desired output.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

3 REPLIES 3
bcdobbs
Community Champion
Community Champion

Have you tried storing it in a variable outside of SUMX?

 

VAR Contribution = [Sales Unit Contribution]

RETURN
SUMX(VW_SALES_DETAILS, Contribution * VW_SALES_DETAILS[Average Price_])


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

The sales unit contribution needs to be evaluated per row of the VW_SALES_DETAILS table. 

Sales details contains the style ID, and the unit sold. The unit sales for each style is the thing I'm calculating the percent of grand total for. 
So, if I calculate outside of the SUMX I just get the sum of all of units sold at the respective currency over all of the sales in total. 

I still need a solution here. 

Thanks!

Ok, hard to diagnose without seeing the full table but you want to do something like:

 

SUMX(
	VW_SALES_DETAILS, 
	VAR Contribution = 
		CALCULATE (
			VW_SALES_DETAILS[Sales Unit Contribution],
			REMOVEFILTERS (VW_SALES_DETAILS),
			VALUES( VW_SALES_DETAILS[Column1] ),
			VALUES( VW_SALES_DETAILS[Column2] ),
			VALUES( VW_SALES_DETAILS[Column3] )
		)	
			
	RETURN
		Contribution * VW_SALES_DETAILS[Average Price_]
)

 

Where Column1, Column2, Column3... etc are the columns you need the Contribution to depend on. You could use ALLEXCEPT but I find the above syntax easier to control.

 

If that doesn't work I'd need to see a demo pbix file with a desired output.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.