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

Create a column containing values from another table referenced by column and row

I have two tables:

 

Customers

Customers.png

 

Prices

Prices.png

 

I'd like to add a column named "Prices" to the table Customers. This column would contain prices based on the respective column and row from the table Prices using the Budget and Country from the Customers table.

 

For example, John would get 10000 (since he has a low budget and buys from China), Melanie 80000 (since she has a high budget and buys from the USA), Kirk 50000 (since he has a medium budget and buys from the USA) etc.

 

Any ideas would be welcomed 😅

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@MartinaV 

First, unpivot the second table

https://radacad.com/pivot-and-unpivot-with-power-bi

Then you will have Price Country and Value in the price table, after rename

A new column in customer

New Column Customers = maxx(filter(Prices,Prices[price]= (Customers[budget]) && Prices[country]= (Customers[country]) ),Prices[value])

 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@MartinaV 

First, unpivot the second table

https://radacad.com/pivot-and-unpivot-with-power-bi

Then you will have Price Country and Value in the price table, after rename

A new column in customer

New Column Customers = maxx(filter(Prices,Prices[price]= (Customers[budget]) && Prices[country]= (Customers[country]) ),Prices[value])

 

@amitchandak Thanks a lot! It works perfectly.

edhans
Super User
Super User

Can you unpivot your Country table? If you can, a FILTER function can quickly do this.

If your data is in Power Query, click on the Prices[Price] field and "Unpivot Other Columns"

 

If not let us know. The formula becomes much more complex and less dynamic if it has to stay in the format it is in.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans Thank you! I didn't know the unpivot function - it makes my life much easier 😊

Great @MartinaV  - the Pivot and UnPivot features are super useful in transforming data into something useful for a Power BI model. 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.