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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
subjoin50
Frequent Visitor

Replace special character by opposite character in Nth position string of a string in Power Query

I have multi-string text data in one column separated by unknown number of whitespaces. I want to replace ending special character on 3rd string from left by minus (-) if it ends with plus (+) and vice versa but rest of the string should remain unchanged. I tried split column and replace but couldn't figure it out. Here is an example of input and output column.input Image.jpg

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this cod

[
    f = Text.Range([Input Column],
Text.PositionOfAny([Input Column],{"-","+"},Occurrence.Last),1),
to = Text.Replace([Input Column],f,if f ="-" then "+" else "-")][to]

Screenshot_1.png

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

pls try this cod

[
    f = Text.Range([Input Column],
Text.PositionOfAny([Input Column],{"-","+"},Occurrence.Last),1),
to = Text.Replace([Input Column],f,if f ="-" then "+" else "-")][to]

Screenshot_1.png

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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