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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
G_Whit-UK
Helper II
Helper II

Power Bi Query Editor - Calculated Column using values from another table

Hi,

 

I have two sets of data ("Transactions Table", and "Costs Table").  I want to be able to add a column to the "Transactions Table" to reflec the processing cost of that particular transaction.  The cost is determined by the transaction type, which is listed in the "Transactions Table" - of which there are two types (A & B).  The base cost for each type is held in the "Cost Table".

 

The structure of "Cost Table" has the transaction types (A & B) as row headers, with Row 1 reflecting the respective costs.

 

Simple example of the table structures:

Simple representation of the two tablesSimple representation of the two tables

 

I attempted to merge the "Costs Table" into the "Transactions Table" using the full outer join function, but that resulted in the joined columns reflecting null values.  My intension was then to perform an IF statement calculation where if 'Transactions Table'[Type] = "A", 'Costs Table'[A],'Costs Table[B]'.  However this plan didn't work and now I'm a little stuck.

 

Does anyone have any ideas as to how I can go about building this in Query Editor?

 

Thanks

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @G_Whit-UK 

 

You can Unpivot Columns A and B, and later Merge Queries, please see the attached for ref

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.



 

View solution in original post

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @G_Whit-UK ,

Is this what you want to get?

dd4.PNG

If yes, maybe you can do like this:

1. Unpivot all columns in "Cost table":

dd5.PNG

The you can get this:

dd6.PNG

2. Merge the wables by "Inner":

dd7.PNG

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mariusz
Community Champion
Community Champion

Hi @G_Whit-UK 

 

You can Unpivot Columns A and B, and later Merge Queries, please see the attached for ref

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.



 

Hi @Mariusz 

 

Thanks for the tip, however the proposed method only partially solves my situation.  I never mentioned in my original post that the "Costs Table" has two additional columns ("C" & "D") which both reflect a daily transaction cost.  I need to be able to bring these daily costs into the "Transactions Table" where I can then multiple the daily costs by the number of days the transaction was active for.

 

I could use your proposed solution by adding two temporary columns to the Transactions Table and give the value of "C" and "D" for each row under the respective column, and then perform the merge, however I'm wondering if there is an alternative way to acheive the same outcome?

 

Thanks.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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