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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Fab117
Helper IV
Helper IV

[Power BI] Copy a column content from one table to another one (linked through common column)

Hello,

I've 2 tables:

Table 1
CodeQuantity
A5
B3
A4
C6
B4
A2
C5
A3
B1
C4

 

Table 2
CodePrice
A1.00 $/unit
B1.20 $/unit
C1.40 $/unit

 

To simplify future calculation, I'd like to add in column one the corresponding price in each line

 

=> 

Table 1
CodeQuantityPrice
A51.00 $/unit
B31.20 $/unit
A41.00 $/unit
C61.40 $/unit
B41.20 $/unit
A21.00 $/unit
C51.40 $/unit
A31.00 $/unit
B11.20 $/unit
C41.40 $/unit

 

Would someone know the formulae to use in Power Query?

 

Thanks

 

Fab

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Fab117 

This can be done easily in Power query with a merge. Place the following M code in a blank query to see the steps. See it all at work in the attached file.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJVitWJVnICsozBLJCYCZjlDGSZwWVN4LJGcFlTuJgxXJ0hXBaoIxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Quantity = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Quantity", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Code"}, Table2, {"Code"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Price"}, {"Price"})
in
    #"Expanded Table2"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

View solution in original post

4 REPLIES 4
AlB
Community Champion
Community Champion

Hi @Fab117 

If you want it in DAX, you can create a calculate column in Table1. See it all at work in the attached file.

Price per unit = 
LOOKUPVALUE(Table2[Price], Table2[Code], Table1[Code])

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Community Champion
Community Champion

Hi @Fab117 

This can be done easily in Power query with a merge. Place the following M code in a blank query to see the steps. See it all at work in the attached file.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJVitWJVnICsozBLJCYCZjlDGSZwWVN4LJGcFlTuJgxXJ0hXBaoIxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Quantity = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Quantity", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Code"}, Table2, {"Code"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Price"}, {"Price"})
in
    #"Expanded Table2"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

Hi,

Thank you very much for looking at my issue and for your proposal.

I looked at the Merge option, this is for sure a good solution.

I'm still also assessing the possibility to do it in Power Desktop with the LookUpValue formulae.

Not sure which one is the most appropriate in my case.

 

Happy new year

 

Fab

Fab117
Helper IV
Helper IV

Waiting to see if it was possible to do this in Power Query, I found a possibility to do it in Power Desktop in Data mode:

Methology applied

 

Target: "NetReg_file"

Source: "Prices"

In Data Mode in Power Desktop (not Power Query)

Fab117_0-1671813776562.png

 

Select "New column"

Fab117_1-1671813776571.png

 

Then type formulae

Name new column= LOOKUPVALUE(Source Table[Field to copy], Source Table [Common field],Target Table[Common field])

For me:

SP = LOOKUPVALUE(Prices[Standard price (GBP)],Prices[GMM],NetReg_file[GMM])

 

As I've 2 different prices to considere, I did excatly the same with second one:

NP = lookupvalue(Prices[Net Price (GBP)],Prices[GMM],NetReg_file[GMM])
 
But faced an unexpected issue:
Power BI issue.png
 

I'm not sure if I'm doing something wrong or if it's a bug.

Did someone see what is going wrong?

 

Tks

 

Fab

 

 

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 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.

Top Solution Authors
Top Kudoed Authors