Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
I need to calculate the sum of all amounts for a column in a table avoiding duplicate IDs in another column in same table.
At last I finished with two measures:
Max Order Gross Sales Amount =
MAX(tBrand[ORDER_TOTAL_AMOUNT])
Brand_Gross_Sales_Amount =
SUMX ( DISTINCT ( tBrand[ORDER_ID] ); [Max Order Gross Sales Amount] )
Using these two different measures all is fine, but when I tried to use variables in same measure like this:
Brand_Gross_Sales_Amount =
VAR vMax_Order_Gross_Sales_Amount =
MAX ( tBrand[ORDER_TOTAL_AMOUNT] )
RETURN
SUMX ( DISTINCT ( tBrand[ORDER_ID] ); vMax_Order_Gross_Sales_Amount )
In thi case returned amount is wrong (it is a lot bigger than first one). I have checked and I cannot find the problem. May you help me?
Thanks a lot.
Solved! Go to Solution.
I think the way you've set it up is best. You could have it all in one measure by simply using the code of the first one on the second one (note you need the CALCULATE to trigger context transition):
Brand_Gross_Sales_Amount =
SUMX (
DISTINCT ( tBrand[ORDER_ID] );
CALCULATE ( MAX ( tBrand[ORDER_TOTAL_AMOUNT] ) )
)
but having two measures as you had is more versatile and the best practice.
Please mark as solved when we get to the solution so that others can see it too. If you find the posts useful please consider kudoing.
Cheers
Hi @Anonymous
Variables in DAX are immutable once they are assigned a value at declaration. In your example,
VAR vMax_Order_Gross_Sales_Amount = MAX ( tBrand[ORDER_TOTAL_AMOUNT] )
the MAX() is evaluated before the SUMX and then the value obtained stored in vMax_Order_Gross_Sales_Amount.
vMax_Order_Gross_Sales_Amount is used when the SUMX is iterating. Note that value is always the same. THe measure, on the contrary, is calculated anew for each row as the SUMx iterates.
Thank you so much for your response. So, is possible to calculate sum for column values dependig on distinct ID values in other column in a more easy way? Do I need to use two different measures?
Thank you so much again.
I think the way you've set it up is best. You could have it all in one measure by simply using the code of the first one on the second one (note you need the CALCULATE to trigger context transition):
Brand_Gross_Sales_Amount =
SUMX (
DISTINCT ( tBrand[ORDER_ID] );
CALCULATE ( MAX ( tBrand[ORDER_TOTAL_AMOUNT] ) )
)
but having two measures as you had is more versatile and the best practice.
Please mark as solved when we get to the solution so that others can see it too. If you find the posts useful please consider kudoing.
Cheers
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 4 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 7 | |
| 7 | |
| 6 |