cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gaiusgw
Helper II
Helper II

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
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors