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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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 )

@amitchandak Thanks.

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors