Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
WalidOthman
Frequent Visitor

IF and Related DAX or measure

Hi All,

 

How to add the cost of each product to the Sales table based on the corresponding country ?

 

Countries 

- South America: Argentina, Brazil,Peru

- Canada

- France

- South Korea 

- Others: rest of the world  (Congo and Nigeria as an example in the Sales table)

 

Also is this the best way to approach the below by adding a new cost column to the sales table, or is possible to add the cost as a measure ? Eventually I want to calculate the GP (Selling Price-Cost)/(Selling Price)

 

 

Pricing Table:

Product KeyCanada CostSouth Korea CostFrance CostSouth America CostOthers Cost
12311.511.5511.6511.211
23411.4511.511.611.1511
34511.3511.4511.5511.111

 

Sales Table:

Product KeyCountrySelling Price
123Brazil12
234Argentia12
345Peru12
123Canada 12
234France 12
345South Korea12
123Nigeria12
234Congo12
3 REPLIES 3
m3tr01d
Continued Contributor
Continued Contributor

To your question "Is it the best way to add a cost column in the sales table", the answer is most likely No.

In term of Data model, it is better for you if you do as @amitchandak said and unpivot the cost but I'm pretty sure you don't need to bring the cost column in the Sales table. You would be better to make a relationship between Sales and the Pricing table based on the product key and country


amitchandak
Super User
Super User

@WalidOthman , Unpivot all the countries in the first table

https://radacad.com/pivot-and-unpivot-with-power-bi
You will country and cost

 

You can leave other cost asis, if needed

 

New column in sales 

Cost =

var _1 = maxx(filter(Table1, Table1[Product] = sales[product]  && Table1[Country] = sales[Country] ) Table1[Cost])

var _2 = maxx(filter(Table1, Table1[Product] = sales[product]  && Table1[Country] = sales[Country] ) Table1[Other Cost])

// Var _2 is optional if other cost is a column

//return  _1

//or

return if(isblank(_1), _2, _1 )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Thanks.

 

Is there a way to do this without unpivtoing the pricing table ?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.