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
J_o_n_a_s
Helper I
Helper I

Lookup ?

Hi. I created a simple example for my question. I would like to create column D.

 

I would like that if C matches A (from a different row or same row), then in column D it will give the result from column B.

 

ABCD
Z-1DogsZ-1Dogs
Z-2CatsZ-2Cats
Z-3nullZ-1Dogs

 

I have a lot of rows, so if possible I would like to do this in Power Query and i would not like to create a new table to merge with.

 

Thanks a lot

Jonas

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You can do a self-merge column C with column A and then expand column B to create column B:

AlexisOlson_0-1672779850437.png

 

Full sample query you can paste into the Advanced Editor of a new blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WitI1VNJRcslPLwZSIE6sDkjQCMhzTiyBCBpBBY2BPJiqWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}, {"C", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"C"}, #"Changed Type", {"A"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"B"}, {"D"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Changed Type",{{"A", Order.Ascending}})
in
    #"Sorted Rows"

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

You can do a self-merge column C with column A and then expand column B to create column B:

AlexisOlson_0-1672779850437.png

 

Full sample query you can paste into the Advanced Editor of a new blank query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WitI1VNJRcslPLwZSIE6sDkjQCMhzTiyBCBpBBY2BPJiqWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}, {"C", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"C"}, #"Changed Type", {"A"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"B"}, {"D"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Changed Type",{{"A", Order.Ascending}})
in
    #"Sorted Rows"

Thanks Alexis. I should have known that 😀

 

Jonas

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