Forum Discussion
How to Calculate Measure and Relative Table Columns
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.
- Anonymous3 years ago
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.
1 Reply
- AnonymousNot applicable
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.