Forum Discussion

Applicable88's avatar
Applicable88
Impactful Individual
5 years ago
Solved

Count with string search

Hello,

 

I have two different sample tables and need two different measures for different use cases. I want to count the orders distinct which has the string W3W, B2B, B2C. On Table1 the String stands for itself, on Table2 the string is wrapped up inside other letters or numbers. Sometimes there are two numbers or letters at the front or at the end, so its highly irregular:

Table1

OrdernumberString
1234W3W
1235B2B
1236B2C
1237SLS
1238WAS
1239TAS
1240MAS
1241LAS



Table2:

OrdernumberString
1234ZZW3WZZ
1235ZB2BZ
1236ZB2CZ
1237BSLSB
1238MWASM
12398TAS8
12409MAS9
12413LAS3

 

And also if I needed to count base on two columns string search:

Here I want for example searching for W3W , B2B and B2C but only when in column string2 its already CLSD (closed)

 

Table3:

 

OrdernumberStringString2
1234W3WOPEN DLVR
1235B2BBACK CLSD
1236B2COpen  
1237SLSEND CLSD
1238WASOPEN DLVR
1239TASBACK CLSD
1240MASOpen  
1241B2CEND CLSD

 

 

 

 

Thank you very much in advance.

Best. 

  • CNENFRNL's avatar
    CNENFRNL
    5 years ago
    Flag_Measure = 
    NOT ISEMPTY(
        FILTER(
            ORDERS,
            ORDERS[String] IN { "W3W", "B2B", "B2C" }
                && CONTAINSSTRING( ORDERS[String2], "Clsd" )
        )
    )

5 Replies

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

    Power Query works better than DAX in your case,

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUQo3DgeS/gGufgouPmFBSrE6YClToKCTkROIdHT2VnD2CXaBSZmBpZxBugpS8xQUYOLmQJFgn2Ag6erngqLDAmSPYzA2eyyBgiFgKXR7TAyAgr4QXcj2mBjC7UfYEwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ordernumber = _t, String = _t, String2 = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Flag", each Text.Contains([String2], "CLSD", Comparer.OrdinalIgnoreCase) and List.Contains({"W3W", "B2B", "B2C"}, [String]))
    in
        #"Added Custom"

    • Applicable88's avatar
      Applicable88
      Impactful Individual

      CNENFRNL thank you. I still hope there is a better way in DAX to solve this. It is a big disadvantage if it cannot do "simple"  wildcards search, which is such a essential part of a BI-Software. It's a big mess that in many circumstances, we need to calculate another Flag for search.

      • CNENFRNL's avatar
        CNENFRNL
        Community Champion
        Flag_CC = 
        ORDERS[String] IN { "W3W", "B2B", "B2C" }
            && CONTAINSSTRING( ORDERS[String2], "Clsd" )