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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Find the values in a column which "StartsWith" any of the value from another column

Hello Experts,

Good Day!
I am stuck with finding the values from  a column which "StartsWith" any of the value from another column.

Example - 

I have two tables with one column each

 

Table 1

 

Type
Cat
Dog
Bag
Ball
Hello

 

Table 2

Object
Dogs
Cat Food
School Bag
BaseBall

!HelloWorld

 

I need output like below

Output

ObjectFlag
DogsTRUE
Cat FoodTRUE
School BagFALSE
BaseBallFALSE
!HelloWorldFALSE

 

Logic - If table 2 values starts with table 1 values then Flag column returns TRUE else false eventhough Table 1 value present in table 2 value in middle.

 

Please assist.

Thanks in advance...!!!

3 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

let
    Lookup = {"Cat","Dog","Bag","Ball","Hello"},
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslPL1aK1YlWck4sUXDLz08Bc4KTM/LzcxScEtPBXKfE4lSnxJwcMEfRIzUnJz88vygHqDYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Object = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Flag", each List.Accumulate(Lookup, false, (s,c) => s or Text.PositionOf([Object], c, null, Comparer.OrdinalIgnoreCase)=0))
in
    #"Added Custom"

Screenshot 2021-07-20 222652.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

gvrajesh
Frequent Visitor

Flag =
VAR SO = Table2[Object]
VAR Tab = FILTER(Table1, CONTAINSSTRING(LEFT(SO,LEN(Table1[Type])),Table1[Type]))
RETURN
IF( COUNTROWS(Tab) > 0, TRUE(),FALSE())
 
gvrajesh_0-1626851287089.png

 

View solution in original post

Icey
Community Support
Community Support

Hi @Anonymous ,

 

In addition to @CNENFRNL 's and @gvrajesh 's methods, you can also try to create a calculated column like so:

Column =
IF (
    SUMX (
        Table1,
        FIND (
            UPPER ( Table1[Type] ),
            LEFT ( UPPER ( Table2[Object] ), LEN ( Table1[Type] ) ),
            ,
            0
        )
    ) > 0,
    TRUE (),
    FALSE ()
)

flag.PNG

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Anonymous ,

 

In addition to @CNENFRNL 's and @gvrajesh 's methods, you can also try to create a calculated column like so:

Column =
IF (
    SUMX (
        Table1,
        FIND (
            UPPER ( Table1[Type] ),
            LEFT ( UPPER ( Table2[Object] ), LEN ( Table1[Type] ) ),
            ,
            0
        )
    ) > 0,
    TRUE (),
    FALSE ()
)

flag.PNG

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

gvrajesh
Frequent Visitor

Flag =
VAR SO = Table2[Object]
VAR Tab = FILTER(Table1, CONTAINSSTRING(LEFT(SO,LEN(Table1[Type])),Table1[Type]))
RETURN
IF( COUNTROWS(Tab) > 0, TRUE(),FALSE())
 
gvrajesh_0-1626851287089.png

 

CNENFRNL
Community Champion
Community Champion

let
    Lookup = {"Cat","Dog","Bag","Ball","Hello"},
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslPL1aK1YlWck4sUXDLz08Bc4KTM/LzcxScEtPBXKfE4lSnxJwcMEfRIzUnJz88vygHqDYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Object = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Flag", each List.Accumulate(Lookup, false, (s,c) => s or Text.PositionOf([Object], c, null, Comparer.OrdinalIgnoreCase)=0))
in
    #"Added Custom"

Screenshot 2021-07-20 222652.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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