Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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?
Solved! Go to 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.
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_])
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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 38 | |
| 38 | |
| 37 | |
| 28 | |
| 28 |
| User | Count |
|---|---|
| 124 | |
| 89 | |
| 73 | |
| 66 | |
| 65 |