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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
garich
Frequent Visitor

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
1 ACCEPTED SOLUTION
slorin
Super User
Super User

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

View solution in original post

3 REPLIES 3
garich
Frequent Visitor

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

garich_0-1701284521902.png

 

Hi,

 

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

Stéphane 

slorin
Super User
Super User

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors