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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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