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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
daicaboy
Helper I
Helper I

Look up value if they contains specific value of other column

Hello,

I want to Look up value in table A if they contains specific value in column of table B. (Just contain, don't need the same value)

Ex:

Table A

ProductColor Code
A001
B002,0001,003
C004,005
D005

Table B

Color CodeColor
001Blue
002Red
003Green
004Yellow

The result:

Color CodeColor
ABlue
BRed,Blue,Green
CYellow
DNone

 

Thank for your time!

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @daicaboy, another approach:

 

Result

dufoq3_0-1719409416856.png

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIwMFSK1YlWcgKzjXQMgAJAwhgs6AwWNAHyTcF8FzAfyI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, #"Color Code" = _t]),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwVNJRcsopTVWK1QFxjYDcoNQUKM8YyHMvSk3Ng/JNgPzI1Jyc/HKl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Color Code" = _t, Color = _t]),
    BufferedTableB = Table.Buffer(TableB),
    Ad_Color = Table.AddColumn(TableA, "Color", each Text.Combine(Table.Combine(List.Transform(Text.Split([Color Code], ","), (x)=> Table.SelectRows(BufferedTableB, (y)=> Text.Contains(x, y[Color Code]))))[Color], ","), type text),
    ReplacedValue = Table.ReplaceValue(Ad_Color,"","None",Replacer.ReplaceValue,{"Color"}),
    RemovedColumns = Table.RemoveColumns(ReplacedValue,{"Color Code"})
in
    RemovedColumns

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

4 REPLIES 4
daicaboy
Helper I
Helper I

Thank you, 

I really appreciate it.

 

dufoq3
Super User
Super User

Hi @daicaboy, another approach:

 

Result

dufoq3_0-1719409416856.png

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIwMFSK1YlWcgKzjXQMgAJAwhgs6AwWNAHyTcF8FzAfyI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, #"Color Code" = _t]),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwVNJRcsopTVWK1QFxjYDcoNQUKM8YyHMvSk3Ng/JNgPzI1Jyc/HKl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Color Code" = _t, Color = _t]),
    BufferedTableB = Table.Buffer(TableB),
    Ad_Color = Table.AddColumn(TableA, "Color", each Text.Combine(Table.Combine(List.Transform(Text.Split([Color Code], ","), (x)=> Table.SelectRows(BufferedTableB, (y)=> Text.Contains(x, y[Color Code]))))[Color], ","), type text),
    ReplacedValue = Table.ReplaceValue(Ad_Color,"","None",Replacer.ReplaceValue,{"Color"}),
    RemovedColumns = Table.RemoveColumns(ReplacedValue,{"Color Code"})
in
    RemovedColumns

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

AlienSx
Super User
Super User

let
    dict = Record.FromList(TableB[Color], TableB[Color Code]),
    color = Table.TransformColumns(
        TableA, 
        {"Color Code", (x) => Text.Combine(
            List.Transform(
                Text.Split(x, ","), 
                (w) => Record.FieldOrDefault(dict, w, "None")
            ), 
            ","
        )}
    )
in
    color
Ahmedx
Super User
Super User

pls try

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIwMFSK1YlWcgKzjXSAfCA2Bos5g8VMgHxTMN8FzAeyYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, #"Color Code" = _t]),
    dict = List.Buffer(Table.ToList(TableB,(x)=>x)),
    f = (x) =>[
      a = List.Accumulate(dict, x, (s, c) =>  Text.Replace(s, c{0}, c{1})), 
        
      b =  if a = x then "None" else Text.Combine(  List.Select( Text.Split( a,","),(z)=> not  Text.Contains(z,"00")),",")
    ][b],
    Custom1 = Table.TransformColumns(Source,{"Color Code",f})
in
    Custom1

Screenshot_1.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors