Forum Discussion

gaiusgw's avatar
gaiusgw
Icon for Helper III rankHelper III
4 years ago
Solved

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. 

  • 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 #]
    ) )

8 Replies

  • 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 #]
    )
    • gaiusgw's avatar
      gaiusgw
      Icon for Helper III rankHelper III

      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). 

       

      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. 

       

      Hope that helps to clarify. 

       

      Thanks a lot! 

      • johnt75's avatar
        johnt75
        Icon for Super User rankSuper User

        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 #]
        ) )