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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
IMCODEV
New Member

Formula for replacing first instance of a character from the right

Hello,

 

I'm tryting to format:

tim_cook_apple.com  ==> tim_cook@apple.com

 

Background

a ShareGate data report displays all external accounts in SPO as "i:0#.f|membership|tim_cook_apple.com#ext#@apple.onmicrosoft.com", which I am trying to extract the user Email from.  

After some transforming I got the string to trim into "tim_cook_apple.com". 

 

I am trying to reference the first underscore from the right and then use the substitute function to replace the underscore with @.  However the search, find functions always targets the first instance from the left.  How can I reference the first instance fo the underscore from the right?

 

Thank you

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@IMCODEV Try this:

New Column =
  VAR __Num = LEN([Column]) - LEN(SUBSTITUTE([Column],"_",""))
RETURN
  SUBSTITUTE([Column],"_","@",__Num)

 



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

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@IMCODEV Try this:

New Column =
  VAR __Num = LEN([Column]) - LEN(SUBSTITUTE([Column],"_",""))
RETURN
  SUBSTITUTE([Column],"_","@",__Num)

 



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...

@Greg_Deckler  Thank you for the feedback.  I tried your formula, however I got the following error.

 

error.PNG

The error was caused from entries that were not in Email format.  Therefore the entries had no underscore which resulted in a 0 value being returned for the _num value.  As a workaround, I just created another column using the subsitiution function to swap the 0 for a valid value of 1.  Afterwards, the formula which @Greg_Deckler worked and I achieved my goal.

 

Thank you

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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