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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors