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
Katiedog1
New Member

Retrieve Multiple Values from Another Table

Hello,

I have 2 tables (Table A & Table B).  I want to Use 'Animal Categories' in Table B to lookup the corresponding 'Animal Type' in Table A that will give me all Animal Types.  See example tables below.  Appreciate the help in advance!

Katiedog1_0-1721330820282.png

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @Katiedog1, check also this:

 

Result

dufoq3_0-1721378316074.png

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslPV9JR8k3MzU3MUYrViVZyTixBFfDJzM9DFXHMS0/NScsszgAKu4EokKBTaU5ORmpiCrKYc2JRSmYeUJeOklNmUQpErCi/HJnvlFOampVYCReKBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Categories = _t, #"Animal Type" = _t]),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRcslPj8lzTiyJyXMqzcnJSE1MUYrViVZycXUDSjonFqVk5iXmxOT5ZObngSXcPTwhupRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Zoo Type" = _t, #"Animal Categories" = _t]),
    Ad_CatHelper = Table.AddColumn(TableB, "CatHelper", each Text.SplitAny([Animal Categories], "#(lf)#(cr)"), type list),
    Ad_v1 = Table.AddColumn(Ad_CatHelper, "v1", each Text.Combine(List.Transform([CatHelper], (x)=> TableA{[Categories = x]}[Animal Type]), "#(lf)"), type text ),
    Ad_v2 = Table.AddColumn(Ad_v1, "v2", each 
        [ a = List.Transform([CatHelper], (x)=> TableA{[Categories = x]}[Animal Type]),
          b = List.Accumulate(List.Zip({{0..List.Count(a)-1}, a}), {}, (s,c)=> s &
                { if List.Contains(s, c{1}) then "" else if c{0} = List.Last(List.PositionOf(a, c{1}, Occurrence.All)) then c{1} else "" } ),
          c = Text.Combine(b, "#(lf)")
        ][c], type text)
in
    Ad_v2

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @Katiedog1, check also this:

 

Result

dufoq3_0-1721378316074.png

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslPV9JR8k3MzU3MUYrViVZyTixBFfDJzM9DFXHMS0/NScsszgAKu4EokKBTaU5ORmpiCrKYc2JRSmYeUJeOklNmUQpErCi/HJnvlFOampVYCReKBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Categories = _t, #"Animal Type" = _t]),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRcslPj8lzTiyJyXMqzcnJSE1MUYrViVZycXUDSjonFqVk5iXmxOT5ZObngSXcPTwhupRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Zoo Type" = _t, #"Animal Categories" = _t]),
    Ad_CatHelper = Table.AddColumn(TableB, "CatHelper", each Text.SplitAny([Animal Categories], "#(lf)#(cr)"), type list),
    Ad_v1 = Table.AddColumn(Ad_CatHelper, "v1", each Text.Combine(List.Transform([CatHelper], (x)=> TableA{[Categories = x]}[Animal Type]), "#(lf)"), type text ),
    Ad_v2 = Table.AddColumn(Ad_v1, "v2", each 
        [ a = List.Transform([CatHelper], (x)=> TableA{[Categories = x]}[Animal Type]),
          b = List.Accumulate(List.Zip({{0..List.Count(a)-1}, a}), {}, (s,c)=> s &
                { if List.Contains(s, c{1}) then "" else if c{0} = List.Last(List.PositionOf(a, c{1}, Occurrence.All)) then c{1} else "" } ),
          c = Text.Combine(b, "#(lf)")
        ][c], type text)
in
    Ad_v2

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Hi @Katiedog1 

 

Firstly split the 'Animal Categories' column into rows by delimiter #(lf), then merge Table A to Table B by using Categories column as matching column. 

Split columns by delimiter - Power Query | Microsoft Learn

Merge queries overview - Power Query | Microsoft Learn

Result:

vjingzhanmsft_0-1721356181766.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

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.