Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

New dax column showing true or false if two different columns match row by row.

Hi,

I'm trying to fix phone number formats to the preferred ###-###-#### format. 

I would like to know which of the raw phone numbers (left column) already match the formatted numbers I built (right column).

I have tried the IF and CONTAINSSTRINGEXACT. All rows return true even though the formatted phone numbers have hyphens.

There are two tables. List whichs contains a mix of correct and in correct formatted numbers and Phone which contains the formatted numbers.

 

Snag_e9a172.png

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Try this, I have included the PBIX below sig. 

Column = 
    VAR __First3 = LEFT([Column1],3)
    VAR __FirstSep = MID([Column1],4,1)
    VAR __Second3 = MID([Column1],5,3)
    VAR __SecondSep = MID([Column1],8,1)
    VAR __Third4 = RIGHT([Column1],4)
RETURN
    SWITCH(TRUE(),
        NOT(ISERROR(__First3+0)) && LEN(__First3) = 3 && NOT(CONTAINSSTRING(__First3,"-")) && NOT(ISERROR(__Second3+0)) && LEN(__Second3)=3 && NOT(CONTAINSSTRING(__Second3,"-")) && NOT(ISERROR(__Third4+0)) && LEN(__Third4) = 4 && NOT(CONTAINSSTRING(__Third4,"-")) && __FirstSep = "-" && __SecondSep = "-", TRUE(),
        FALSE()
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Looking for help with adjusting the awesome work of Greg Deckler. I need to modify his code below to show that this phone format is "true" (###) ###-#### instead of my original request of ###-###-####

 

 

Column = 
    VAR __First3 = LEFT([Column1],3)
    VAR __FirstSep = MID([Column1],4,1)
    VAR __Second3 = MID([Column1],5,3)
    VAR __SecondSep = MID([Column1],8,1)
    VAR __Third4 = RIGHT([Column1],4)
RETURN
    SWITCH(TRUE(),
        NOT(ISERROR(__First3+0)) && LEN(__First3) = 3 && NOT(CONTAINSSTRING(__First3,"-")) && NOT(ISERROR(__Second3+0)) && LEN(__Second3)=3 && NOT(CONTAINSSTRING(__Second3,"-")) && NOT(ISERROR(__Third4+0)) && LEN(__Third4) = 4 && NOT(CONTAINSSTRING(__Third4,"-")) && __FirstSep = "-" && __SecondSep = "-", TRUE(),
        FALSE()
    )
Anonymous
Not applicable

@Greg_Deckler that's amazing! Thank you so much. I always enjoy reading your replies to folks. Truly helpful for me to continue my learning.

Greg_Deckler
Community Champion
Community Champion

@Anonymous - Try this, I have included the PBIX below sig. 

Column = 
    VAR __First3 = LEFT([Column1],3)
    VAR __FirstSep = MID([Column1],4,1)
    VAR __Second3 = MID([Column1],5,3)
    VAR __SecondSep = MID([Column1],8,1)
    VAR __Third4 = RIGHT([Column1],4)
RETURN
    SWITCH(TRUE(),
        NOT(ISERROR(__First3+0)) && LEN(__First3) = 3 && NOT(CONTAINSSTRING(__First3,"-")) && NOT(ISERROR(__Second3+0)) && LEN(__Second3)=3 && NOT(CONTAINSSTRING(__Second3,"-")) && NOT(ISERROR(__Third4+0)) && LEN(__Third4) = 4 && NOT(CONTAINSSTRING(__Third4,"-")) && __FirstSep = "-" && __SecondSep = "-", TRUE(),
        FALSE()
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler Hi again Greg, the developer of our data source is not switching to using (###) ###-#### for proper phone formatting. Could you please help me convert the above code which populates my true/false column?

The original "true" value looked for ###-###-####

Thank you in advance for a reply!

 

Jim

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.