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 am looking for a way to calculate the following using two tables that have a many-to-one relationship, but I can't find it. Can you please provide me with a DAX that can solve this?
-----------------------
Relationships
- Many: 'Sales' table
- 1: 'Operation' table
-----------------------
The formula I would like to achieve
Subtract the 'Operation' table cost for the same day from the following measure you want to create in the 'Sales' table = margin
Daily_Amount = CALCULATE(
SUM(Sales[Amount]),
ALLSELECTED(Sales[Item])
)
However, using the RELATED function will result in an error, probably because there is no row context.
Margin = [Daily_Amount] - RELATED('Operation'[Cost])
Margin = [Daily_Amount] - RELATED('Operation'[Cost])
Error message
The column 'Operation[Cost]' either doesn't exist or doesn't have a relationship to any table available in the current context.
-----------------------
Thank you for your cooperation.
Solved! Go to Solution.
Hi @Masatoshi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a measure.
Margin =
var _cost = LOOKUPVALUE(Operation[Cost],'Operation'[Date],MAX('Sales'[Date]))
return 'Sales'[Daily_Amount]-_cost
(3) Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Masatoshi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a measure.
Margin =
var _cost = LOOKUPVALUE(Operation[Cost],'Operation'[Date],MAX('Sales'[Date]))
return 'Sales'[Daily_Amount]-_cost
(3) Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 37 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 130 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |