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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
irah
New Member

masking first part of email id using dax query

can someone please help in writing the PBI DAX query for replacing the first part of the email id with***** and displaying only the domain name of the email id.. example     ******@microsoft.com.

 

I tried the below code but in vain-

 
test2 = replace(Emp[Email],1, FIND("@",[Email])+1,LEN([Email]) -FIND("@",[Email]),"********"))
1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this

 

Masked Email = REPLACE([EMail],1,FIND("@",[EMail])-1,REPT("*",FIND("@",[EMail])-1)) 

 

You can also use variable and write in DAX short line syntax

 

Masked Email = 
VAR _PositionOfDomain = FIND("@",[EMail])-1
RETURN
    REPLACE(
        [EMail],
        1,
        _PositionOfDomain,
        REPT("*",_PositionOfDomain
        )
    ) 

 

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

If you want the number of asterisks to match the first part, then try

Masked = 
VAR _Email = SELECTEDVALUE ( Emails[Email] )
VAR _Len = LEN ( _Email )
VAR _Pos = SEARCH ( "@", _Email ) - 1
VAR _Mask = REPT ( "*", _Pos )
RETURN
    IF ( _Len > 0, _Mask & RIGHT ( _Email, _Len - _Pos ) )

 

If you'd prefer an even more anonymous fixed-length mask, then you can simplify it to

Masked = 
VAR _Email = SELECTEDVALUE ( Emails[Email] )
VAR _Len = LEN ( _Email )
VAR _Pos = SEARCH ( "@", _Email ) - 1
RETURN
    IF ( _Len > 0, "*****" & RIGHT ( _Email, _Len - _Pos ) )
Vijay_A_Verma
Super User
Super User

Use this

 

Masked Email = REPLACE([EMail],1,FIND("@",[EMail])-1,REPT("*",FIND("@",[EMail])-1)) 

 

You can also use variable and write in DAX short line syntax

 

Masked Email = 
VAR _PositionOfDomain = FIND("@",[EMail])-1
RETURN
    REPLACE(
        [EMail],
        1,
        _PositionOfDomain,
        REPT("*",_PositionOfDomain
        )
    ) 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.