Forum Discussion

Ocasio27's avatar
Ocasio27
Iron Contributor
Sep 17, 2020
Solved

Help simplifying this DAX code

I am trying to find a way to simplify this code since it annoying to add nested characters and I think it inefficient when it comes to performance   The point is, to leave only number 0-9 character...
  • SergeiBaklan's avatar
    SergeiBaklan
    Sep 17, 2020

    Ocasio27 

    To my knowledge in DAX there is no equivalent for sequential SUBSTITUTE() in such cases. As a comment, these days such transformation usually are doing in Power Query with M-script, that will be one short string.

     

    As for DAX, I'd adjust formula a bit like

    =
    VAR phoneNumber=
       IF(
         ISBLANK([CELULAR]),
         [TELEFONO],
         [CELULAR]
        )
    VAR cleanText=
       SUBSTITUTE (
         SUBSTITUTE (
           SUBSTITUTE (
             SUBSTITUTE(
               SUBSTITUTE(
                 SUBSTITUTE(
                   phoneNumber, "-", "" 
                 ), "(", ""
                ),")",""
              )," ",""
            ),"/",""
          ),"\",""
        )
    RETURN cleanText

Resources