Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How to do partial comparison b/w 2 columns in power bi, power query, DAX

I have to columns where i need to do comparison. If data in 2 columns are exactly same I am getting correct result but where there are additinal characters, I am not getting desired result. For eg: Following values in 2 columns must match, how to do that? I used contain function in power query, SEARCH function in DAX but not getting result. Need help!!

 

abc234defqazwsxabc234de
4edcv234edcv
123qaz3qaz
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous 

    You can put the following code to advanced editor in power query

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKNjI2SUlNU9JRKkysKi+ugIkoxepEK5mkpiSXAaWAImAWSMzQyBioEigIpmJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine(List.Intersect({Text.ToList([Column1]),Text.ToList([Column2])}))),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom]<>null then "Matched" else "Not Matched")
    in
        #"Added Custom1"

    Output

    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.

     

6 Replies

  • mlsx4's avatar
    mlsx4
    Icon for Memorable Member rankMemorable Member

    Hi Anonymous 

     

    You can do:

    = Table.AddColumn(#"PreviousStepName", "IsContained", each Text.Contains( [Column1] , [Column2] , Comparer.OrdinalIgnoreCase ) or Text.Contains( [Column2] , [Column1] , Comparer.OrdinalIgnoreCase ) , type logical)
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi mlsx4 ,
      Thanks for your reply. Like I mentioned, I have already tried mentioned steps and it is not working.

      • mlsx4's avatar
        mlsx4
        Icon for Memorable Member rankMemorable Member

        I have tried with your exact example and it is working perfectly. 

        Have you checked?