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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
gaiusgw
Helper III
Helper III

Pull data from unrelated table like VLOOKUP

I have 2 tables that have a control # in common. I need to bring in the PO # into the other table based on the common control #. 

 

Tables;

OPENHEAD which has the control number and the PO number. 

TRANS has control number but I need to insert a column that pulls the PO number from OPENHEAD. 

 

I do not have these tables related as that breaks other relationships I need active. 

 

I know that LOOKUPVALUE is the equivalent of VLOOKUP but when I try inserting a custom column and use the following string, I get an error that will not let me move forward. 

 

LOOKUPVALUE( 'OPENHEAD'[CUST_PO], 'OPENHEAD'[CONTROL_NO], 'TRANS'[CONTROL_NO])

 

The OPENHEAD table would have the control number listed multiple times and also the PO number so not sure if maybe that is the reason it is failing. 

 

Please let me know if you see something I am missing. And if the above did not make it clear, I am a novice. 

1 ACCEPTED SOLUTION

I think it may be the blank control nos in the TRANS table which are causing problems. Try

PO # = 
var controlNumber = TRANS[control no]
return IF( NOT ISBLANK(controlNumber),
 SELECTCOLUMNS( CALCULATETABLE( TOPN( 1, OPENHEAD, OPENHEAD[ID]), 
   TREATAS( { controlNumber}, OPENHEAD[control no]) ),
   "@val", OPENHEAD[PO #]
) )

View solution in original post

8 REPLIES 8
johnt75
Super User
Super User

If OPENHEAD has a unique identifier for each row you could create the new column like

PO # = 
var controlNumber = TRANS[control no]
return SELECTCOLUMNS( CALCULATETABLE( TOPN( 1, OPENHEAD, OPENHEAD[ID]), 
   TREATAS( { controlNumber}, OPENHEAD[control no]) ),
   "@val", OPENHEAD[PO #]
)

thanks for the suggestion but this leads to the same error.

 

Here are screenshots if that might help. 

 

This is the OPENHEAD table. Each CONTROL_NO is unique and has a CUST_PO column (sometimes they are blank). 

Capture.JPG

 

This is the TRANS table. I need to insert a column that pulls the CUST_PO info. The common link is that both tables have CONTROL_NO. 

2.JPG

 

Hope that helps to clarify. 

 

Thanks a lot! 

I think it may be the blank control nos in the TRANS table which are causing problems. Try

PO # = 
var controlNumber = TRANS[control no]
return IF( NOT ISBLANK(controlNumber),
 SELECTCOLUMNS( CALCULATETABLE( TOPN( 1, OPENHEAD, OPENHEAD[ID]), 
   TREATAS( { controlNumber}, OPENHEAD[control no]) ),
   "@val", OPENHEAD[PO #]
) )

Still getting the same error. Im not sure that blanks are the issue because I cannot get passed the unexpected token. 

 

Capture.JPG

Ah, the code I posted was DAX. You need to add it as a new calculated column, not in Power Query.

Gotcha, thanks for pointing me in the right direction. I gave it a go but still getting errors. 

 

See the error at the bottom of this shot. Looks like it does not like that there are multiple lines with the same CONTROL_NO in the TRANS table. 

 

Capture.JPG

the column needs to go on the TRANS table. I thought that was where you wanted it ?

You are a legend! Thanks so much for your patience on this one. I was trying to put the new calculation under an area where I have lots of other independent calculations and that was the problem like you said. Added under TRANS and good to go! Thanks again! 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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