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
Masatoshi
Frequent Visitor

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

2023-03-11_22h10_37.png

-----------------------
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.

2023-03-11_22h13_27.png

-----------------------

Thank you for your cooperation.

1 ACCEPTED SOLUTION
Anonymous
Not 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.

vtangjiemsft_0-1678686651671.png

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. 

View solution in original post

1 REPLY 1
Anonymous
Not 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.

vtangjiemsft_0-1678686651671.png

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. 

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.