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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Andy4BI
New Member

Look up value from other row of same table (like VLOOKUP in Excel)

Hello, 

I have the following table "People"

 

IDNicknameFull NameParentNicknameParentID ??
1AndyAndreas Müller  
2BertaBeate SchneiderFred? (expectet: 6)
3ClaraClaudi WagnerFred? (expectet: 6)
4DoraDaurene DaudererHarry? (expectet: 8 )
5ElmirElmar OtterbachAndy? (expectet: 1)
6FredFriedrich Holland  
7GeorgHans-Georg MeyerElmir? (expectet: 5)
8HarryHarald ZwiblerDora? (expectet: 4)

 

Now I'd like to calculate with M Query the column ParentID. So I'm looking for a function like "VLOOKUP" in Excel or in DAX:

ParentID = LOOKUPVALUE( People[ID], People[Nickname], People[ParentNickname])

It would be great, if some could help me. 

Thank you very much in advance

Andy

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Andy4BI Perhaps try Table.MatchesAnyRows.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

AlexisOlson
Super User
Super User

Merge the query with itself and expand the ID column.

AlexisOlson_0-1642523589751.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VZA9C8IwEIb/ypFZB79d1apdioODYOlwbY42EFO4tkj/m5t/zPRCC07PveHh7iVpqhZqpg5O9wFM2EDy/VhL7F9AZbNULf10JG5RiC3BvagcGS3OhUmLtvLhZJExsNMGHli6f2ntQ1SLE2HH5Ag8/SbRYmTuxdv4dLYvw4HIcGtb4hyLaiw8aNtx9wBDmk1RQVxbi05P/Xd+ulLNpVxwzVwCJNQTT2cGcT9VEKLV8HybPPyFtM6yHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Nickname = _t, #"Full Name" = _t, ParentNickname = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Nickname", type text}, {"Full Name", type text}, {"ParentNickname", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ParentNickname"}, #"Changed Type", {"Nickname"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"ID"}, {"ParentID"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Changed Type",{{"ID", Order.Ascending}})
in
    #"Sorted Rows"

 

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

Merge the query with itself and expand the ID column.

AlexisOlson_0-1642523589751.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VZA9C8IwEIb/ypFZB79d1apdioODYOlwbY42EFO4tkj/m5t/zPRCC07PveHh7iVpqhZqpg5O9wFM2EDy/VhL7F9AZbNULf10JG5RiC3BvagcGS3OhUmLtvLhZJExsNMGHli6f2ntQ1SLE2HH5Ag8/SbRYmTuxdv4dLYvw4HIcGtb4hyLaiw8aNtx9wBDmk1RQVxbi05P/Xd+ulLNpVxwzVwCJNQTT2cGcT9VEKLV8HybPPyFtM6yHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Nickname = _t, #"Full Name" = _t, ParentNickname = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Nickname", type text}, {"Full Name", type text}, {"ParentNickname", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ParentNickname"}, #"Changed Type", {"Nickname"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"ID"}, {"ParentID"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Changed Type",{{"ID", Order.Ascending}})
in
    #"Sorted Rows"

 

Great! Thank you for the quick solution. 

 

Greg_Deckler
Super User
Super User

@Andy4BI Perhaps try Table.MatchesAnyRows.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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