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
mstoppelman
Frequent Visitor

Match between two columns in different order

Hi, I've got two calculated columns, so a Power Query solution isn't feasible, and I don't really know where to start, or if it's possible to achieve my expected result. The two columns have data separated by commas, and I want to check if what's between the commas matches, even if the items are in a different order.

 

Here is a visual of what I'm looking for, let's say this table is called "test"

Calculated Column1Calculated Column2Expected Result
ABC,DEFGH,IJIJ,ABC,DEFGH

Match

XYZ,MNOPQRLMN,TUVWXYZNo Match
2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

This is annoying to do in DAX since there isn't a nice function to split the text. However, it's possible to abuse the PATH functions to accomplish this.

 

Expected Result = 
VAR Path1 = SUBSTITUTE ( Concat[Calculated Column1], ",", "|" )
VAR Path2 = SUBSTITUTE ( Concat[Calculated Column2], ",", "|" )
VAR Len1 = PATHLENGTH ( Path1 )
VAR Len2 = PATHLENGTH ( Path2 )
VAR List1 = SELECTCOLUMNS ( GENERATESERIES ( 1, Len1 ), "Item", PATHITEM ( Path1, [Value] ) )
VAR List2 = SELECTCOLUMNS ( GENERATESERIES ( 1, Len2 ), "Item", PATHITEM ( Path2, [Value] ) )
RETURN
    IF ( MAX ( Len1, Len2 ) = COUNTROWS ( INTERSECT ( List1, List2  ) ), "Match", "No Match" )

 

This turns each concatenation into a path and then constructs a list of each item in the path. Then if the intersection of these lists has as many items as each individual one, it's a match.

View solution in original post

mahoneypat
Employee
Employee

This would be much easier in Power Query.  Is it possible to make your Calculated Columns there instead, so you can do this too there?  Or is it indepent and you could do it there first?

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

This would be much easier in Power Query.  Is it possible to make your Calculated Columns there instead, so you can do this too there?  Or is it indepent and you could do it there first?

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


AlexisOlson
Super User
Super User

This is annoying to do in DAX since there isn't a nice function to split the text. However, it's possible to abuse the PATH functions to accomplish this.

 

Expected Result = 
VAR Path1 = SUBSTITUTE ( Concat[Calculated Column1], ",", "|" )
VAR Path2 = SUBSTITUTE ( Concat[Calculated Column2], ",", "|" )
VAR Len1 = PATHLENGTH ( Path1 )
VAR Len2 = PATHLENGTH ( Path2 )
VAR List1 = SELECTCOLUMNS ( GENERATESERIES ( 1, Len1 ), "Item", PATHITEM ( Path1, [Value] ) )
VAR List2 = SELECTCOLUMNS ( GENERATESERIES ( 1, Len2 ), "Item", PATHITEM ( Path2, [Value] ) )
RETURN
    IF ( MAX ( Len1, Len2 ) = COUNTROWS ( INTERSECT ( List1, List2  ) ), "Match", "No Match" )

 

This turns each concatenation into a path and then constructs a list of each item in the path. Then if the intersection of these lists has as many items as each individual one, it's a match.

Thank you so much! This works great

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.