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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rlfRodrigo
Frequent Visitor

Find whats different between elements of a string

Im having trouble figuring out how to get it done.

Need to find the difference between elements of two strings using DAX

A dummy table to ilustrate what i have:

rlfRodrigo_2-1721305828553.png

 

What i need on C:

rlfRodrigo_3-1721305850915.png

 

1 ACCEPTED SOLUTION

Hi,

Thanks for the solution @rajendraongole1  provided, and i want to offer some more information for user to rerfer to.

hello @rlfRodrigo , you can refer to the following calculated column.

Column = 
VAR a =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [A] ), 1 ),
            "Value_A", PATHITEM ( [A], [Value] )
        ),
        "ValueA", [Value_A]
    )
VAR b =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [B] ), 1 ),
            "Value_B", PATHITEM ( [B], [Value] )
        ),
        "ValueB", [Value_B]
    )
RETURN
    CONCATENATEX ( EXCEPT ( a, b ), [ValueA], "|" )

Output

vxinruzhumsft_0-1721352696991.png

 

 

 

Best Regards!

Yolo Zhu

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

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Just in case you are interested, this M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(List.Difference(Text.Split([Text1],"|"),Text.Split([Text2],"|")),"|"))
in
    #"Added Custom"

Hope this helps.

Ashish_Mathur_0-1721357797562.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I thought about using M but both of my columns came from another calculated column so it wasnt possible without export/import

Hi @rlfRodrigo 

You can refer to the solution I offered above. it gives the result you want.

 

Best Regards!

Yolo Zhu

rlfRodrigo
Frequent Visitor

That works perfectly when I have 1 character per delimiter, but how can I modify it to get multiple characters? (the idea is to use it with series of 7 characteres) 

Like this:
rlfRodrigo_0-1721311431975.png

In this case, C would be:
CC|AA|22
BB|GG|77

The modification I got half working was this one:

rlfRodrigo_1-1721311833283.png

But apparently it removes any character found within B:

rlfRodrigo_2-1721311852965.png

 

Hi,

Thanks for the solution @rajendraongole1  provided, and i want to offer some more information for user to rerfer to.

hello @rlfRodrigo , you can refer to the following calculated column.

Column = 
VAR a =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [A] ), 1 ),
            "Value_A", PATHITEM ( [A], [Value] )
        ),
        "ValueA", [Value_A]
    )
VAR b =
    SELECTCOLUMNS (
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [B] ), 1 ),
            "Value_B", PATHITEM ( [B], [Value] )
        ),
        "ValueB", [Value_B]
    )
RETURN
    CONCATENATEX ( EXCEPT ( a, b ), [ValueA], "|" )

Output

vxinruzhumsft_0-1721352696991.png

 

 

 

Best Regards!

Yolo Zhu

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

Thank you @v-xinruzhu-msft, that worked perfectly!

rajendraongole1
Super User
Super User

Hi @rlfRodrigo -To find the difference between elements of two strings in DAX and produce

create a below calculated column

Difference =
VAR ListA = SUBSTITUTE(PIPE[A], "|", ",")
VAR ListB = SUBSTITUTE(PIPE[B], "|", ",")
VAR TableA = ADDCOLUMNS(
                 SELECTCOLUMNS(
                     GENERATESERIES(1, LEN(ListA)),
                     "CharA", MID(ListA, [Value], 1)
                 ),
                 "IsInB", SEARCH([CharA], ListB, 1, 0)
             )
VAR Result = CONCATENATEX(
                 FILTER(TableA, [IsInB] = 0),
                 [CharA],
                 "|"
             )
RETURN Result
 
rajendraongole1_0-1721307364365.png

 

Hope it helps

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.