Forum Discussion

garich's avatar
garich
Frequent Visitor
2 years ago
Solved

Display only the first record after merging 2 tables

Hi,

 

I would like to merge 2 tables below linking Customer ID and Person ID where I only need to display the first top record of Table B.

 

Table: A

IDCustomerID
1123
2456
3789

 

Table: B

IDPersonIDPRSName
1123Doe, Jane
2123Doe, Mary Jane
2456Smith, John
3789White, Robert
4789White, Robert Jr

 

 

I have this M language query which results to the Actual below and I'm stuck on what to do next...

 

 

    #"Merged Queries1" = Table.NestedJoin(#"Expanded PRS DateExtensions", {"CustomerID"}, #"PRS HistoricPersonRecords", {"PersonID"}, "PRS HistoricPersonRecords", JoinKind.LeftOuter),
    #"Expanded PRS HistoricPersonRecords" = Table.ExpandTableColumn(#"Merged Queries1", "PRS HistoricPersonRecords", {"PRSName"}, {"PRS HistoricPersonRecords.PRSName"}),

 

 

 

Expected Result:

IDCustomerIDPRSName
1123Doe, Jane
2456Smith, John
3789White, Robert

 

 

Actual Result:

IDCustomerIDPRSName
1123Doe, Jane
1123Doe, Mary Jane
2456Smith, John
3789White, Robert
3789White, Robert Jr
  • Hi,

    Step1 = Table.NestedJoin(
    #"Expanded PRS DateExtensions", {"Customer ID"},
    #"PRS HistoricPersonRecords", {"PersonID"},
    "PRS HistoricPersonRecords", JoinKind.LeftOuter),
    Step2 = Table.AddColumn(Step1, "PRSName", each [#"PRS HistoricPersonRecords"]{0}[PRSName])

     Stéphane

3 Replies

  • Hi,

    Step1 = Table.NestedJoin(
    #"Expanded PRS DateExtensions", {"Customer ID"},
    #"PRS HistoricPersonRecords", {"PersonID"},
    "PRS HistoricPersonRecords", JoinKind.LeftOuter),
    Step2 = Table.AddColumn(Step1, "PRSName", each [#"PRS HistoricPersonRecords"]{0}[PRSName])

     Stéphane

  • garich's avatar
    garich
    Frequent Visitor

    slorin thank you! But how do I handle null values? It is throwing an error

     

    • slorin's avatar
      slorin
      Super User

      Hi,

       

      try [#"PRS HistoricPersonRecords"]{0}[PRSName] otherwise null
      if Table.IsEmpty([#"PRS HistoricPersonRecords"]) then null else [#"PRS HistoricPersonRecords"]{0}[PRSName]

      Stéphane