Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Lookup Column in related table with a specific value in another column

I am a Power Query newbie and am trying to replicate a VLOOKUP in a one to many relationship.  I have 2 realated tables, Request and AuditLog with RequestCode as the related column.  What I would like to do is add a custom column with the date the Product Child Assigned to the Requests Table.  Is there a simple way to perform this Lookup?  Below is the sample data and some the code I have tried.  Thank you in advance.

 

Request Table

RequestCode                                                                 RequestName                 Date Assigned                       

OE45497.45499Part CreationLookup Value

 

Audit Log Table

ActionDate              Status                             Action                                                          RequestCode

3/4/2021 4:22NewProduct Child CreatedOE45497.45499
3/4/2021 4:22ChildExecutionProduct Child AssignedOE45497.45499
3/4/2021 4:22RequestInProgressProduct Child SubmittedOE45497.45499
3/4/2021 4:23QCInprogressProduct Child Assigned for QCOE45497.45499
3/4/2021 4:23Ready for QCProduct Child ExecutedOE45497.45499
3/5/2021 18:39QC CompleteQC PassOE45497.45499
3/5/2021 18:39QC CompleteRisk-Issue ConfirmationOE45497.45499
6/28/2021 20:57ChildCloseClosed Product ChildOE45497.45499

 

 

 #"Merged Queries" = Table.NestedJoin(#"Sorted Rows", {"RequestCode"}, GetAllChildRequestsAudit, {"RequestCode"}, "GetAllChildRequestsAudit", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Date Assigned", each  Table.SelectRows(GetAllChildRequestsAudit[ActionDate]),(GetAllChildRequestsAudit[Action] = "Product Child Assigned"))
in
    #"Added Custom"

 

 

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    You can write it like:

    #"Merged Queries" = Table.Join(#"Sorted Rows", {"RequestCode"}, GetAllChildRequestsAudit{[Action = "Product Child Assigned"]}, {"RequestCode"}, "GetAllChildRequestsAudit", JoinKind.Inner)

     

    --Nate

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous  - Thanks for the response!!  Your code suggestion makes sense but I received an Expression Error.

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    I tried to be too fancy!

     

    You can write it like:

    #"Merged Queries" = Table.Join(#"Sorted Rows", {"RequestCode"}, Table.SelectRows(GetAllChildRequestsAudit, each [Action] = "GetAllChildRequestsAudit"),{"RequestCode"}, JoinKind.Inner)

     

    --Nate

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks again Anonymous!  I was able to get your suggestion to almost work.  With the Inner Join, just one row showed up on the table but I was expecting 140 from my sample data.  I switched the Join to a Left Outer and got the 140 rows I expected but the ActionDate only populated one of the rows.