Forum Discussion
Help simplifying this DAX code
- Sep 17, 2020
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
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
Thank you.
In this case, is there any way to remove non numerical characters? I am trying to extract only 0-9 characters
- SergeiBaklanSep 22, 2020Diamond Contributor
There is a variant. Not sure how it'll be from performance point of view, however. Let add helper table ID to the data model
With it calculated column B
could be as
=VAR source=Table2[A] VAR charactersTable= FILTER ( SELECTCOLUMNS ( 'ID', "Value",'ID'[ID], "mchar",MID(source,'ID'[ID],1), "mcode", UNICODE(MID(source,'ID'[ID],1)) ), [mcode] <58 && [mcode] >47 ) VAR Result= CONCATENATEX(charactersTable, [mchar]) Return Result(48 is ascii code for zero, and 57 for 9)
- SergeiBaklanSep 18, 2020Diamond Contributor
Unfortunately I don't know other ways with DAX-only but modifications of above formula.