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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bernate
Helper III
Helper III

Get 2nd Result from Merge Queries

Hello, I am using Merge Queries in Power BI as a VLOOKUP to get the resulting row value based on the columns I am matching on. Table 1 contains the names of people, Table 2 contains the names and the departments the people work in. I want to get the result shown in Merged Table, where I list the names of the people and 2 columns for people who may work in more than 1 department. I can get the Department 1 column in Power Query by doing a merge of Table 1 and Table 2, but how can I get the Department 2 column?

bernate_0-1724367729012.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I would do it like this:

 

let
Source = Table.NestedJoin(Table1, {"Name"}, Table2, {"Name"}, "Table2", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(Source, "Department 1", each [Table2]{0}[Department]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Department 2", each try [Table2]{1}[Department] otherwise null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Table2"})
in
#"Removed Columns"

 

watkinnc_0-1724379043350.png

 

 

--Nate

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

I would do it like this:

 

let
Source = Table.NestedJoin(Table1, {"Name"}, Table2, {"Name"}, "Table2", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(Source, "Department 1", each [Table2]{0}[Department]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Department 2", each try [Table2]{1}[Department] otherwise null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Table2"})
in
#"Removed Columns"

 

watkinnc_0-1724379043350.png

 

 

--Nate

Perfect, thank you Nate!

Ahmedx
Super User
Super User

pls try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWJVrowCcg0gjAXApnGCCZQNBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Department = _t]),
    group = Table.Group(Source, "Name", {"tmp", 
(x)=>   [  a = x[Department],
          b = Table.FromRows( {a}, List.Transform({1..List.Count(a)},(x)=>"Department"& Text.From(x)))
   ][b]
}),
    #"Expanded tmp" = Table.ExpandTableColumn(group, "tmp", {"Department1", "Department2"})
in
    #"Expanded tmp"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors