cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MichaelF1
Helper I
Helper I

Power Query - Add column from related table

Hi everyone, 

I'm trying to add a column from one related table to another in Power Query.

So in table 1 I have:

IDCust_RefCust_PostCode
1Customer001AB21 4EF
2Customer002BC65 R56
3Customer003

CD32 Y76

 

And in table 2 I have

IDCust_RefContact_Name
1Customer001Dave
2Customer002Dee
3Customer003Dozy

 

I want to add the Cust_PostCode column from table 1 to table 2, matching Cust_Ref from both tables, so table 2 has 4 columns.

 

I know how to do this using Merge Queries but this seems to take a very large amount of processing power, so I need to find another way if possible.

 

Thanks in advance 🙂

 

Michael

2 ACCEPTED SOLUTIONS
luohen
Resolver II
Resolver II

Hi @MichaelF1 ,

You can achieve it by the following methods:
1. Power Query: Add a custom column as below in Table2

 

= Table.AddColumn(#"Changed Type", "Cust_PostCode", each Table1[Cust_PostCode]{List.PositionOf(Table1[Cust_Ref],[Cust_Ref])})

 

yingyinr_0-1660197404798.png

In addition, you can refer the following blog to achieve it, there are two methods(merge method and add a custom column method) include in this blog.

VLOOKUP in Power Query Using List Functions

Merge methodMerge method

Add a custom column methodAdd a custom column method

2. DAX: Create a calculated column as below to get it

 

Column = 
CALCULATE (
    MAX ( 'Table1'[Cust_PostCode] ),
    FILTER ( 'Table1', 'Table1'[Cust_Ref] = 'Table2'[Cust_Ref] )
)

 

yingyinr_1-1660197628665.png

Best Regards

View solution in original post

Hi @MichaelF1 ,

You can download my sample pbix file from this link to get more details about creating custom column in Power Query Editor...

Add a custom column in Power BI Desktop

Best Regards

View solution in original post

7 REPLIES 7
luohen
Resolver II
Resolver II

Hi @MichaelF1 ,

You can achieve it by the following methods:
1. Power Query: Add a custom column as below in Table2

 

= Table.AddColumn(#"Changed Type", "Cust_PostCode", each Table1[Cust_PostCode]{List.PositionOf(Table1[Cust_Ref],[Cust_Ref])})

 

yingyinr_0-1660197404798.png

In addition, you can refer the following blog to achieve it, there are two methods(merge method and add a custom column method) include in this blog.

VLOOKUP in Power Query Using List Functions

Merge methodMerge method

Add a custom column methodAdd a custom column method

2. DAX: Create a calculated column as below to get it

 

Column = 
CALCULATE (
    MAX ( 'Table1'[Cust_PostCode] ),
    FILTER ( 'Table1', 'Table1'[Cust_Ref] = 'Table2'[Cust_Ref] )
)

 

yingyinr_1-1660197628665.png

Best Regards

Thank you very much, I didn't know about the add column method, I'll check it out 🙂

Hi @MichaelF1 ,

You can download my sample pbix file from this link to get more details about creating custom column in Power Query Editor...

Add a custom column in Power BI Desktop

Best Regards

Thanks @luohen , that's very helpful 🙂

amitchandak
Super User
Super User

@MichaelF1 , In power query you have to use merge .

 

In DAX you can use related or relatedtable with maxx or sumx etc

 


refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Hi @amitchandak ,

Thank you for the reply. I was hoping to do it in PQ rather than DAX. My problem is that I keep getting the 'resources exceed' error in Power BI so I was hoping to shift some of the heavy lifting to PQ, but Merge seems unworkable due to the length of tiome it takes.

Do you by any chance have any tips or links to improving the performance of DAX measures?

Thanks again,

Michael

@MichaelF1 , My viewpoint is, that if data is large do not do it in power bi. Bring it from the source.

 

But try the same in dataflow on service.  Try merge there



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 25

Ted's Dev Camp - August 25, 2022

Watch Session 25 of Ted's Dev Camp.

Top Solution Authors