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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@IMCODEV Try this:

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

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@IMCODEV Try this:

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

 


@ 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!:
The Definitive Guide to Power Query (M)

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors