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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kenchan
Frequent Visitor

Remove Text Between - Power BI

I am working on removing some text with pattern below "[cig ...]"; "[http ...]"; "[data ...]"; by creating 3 fucntions. Attached 1 at the bottom as reference. However, when I apply the function, some of the cell get the error (An error occurred in the ‘’ query. Expression.Error: The 'count' argument is out of range. Details: -2360)

 

May I know how can I solve this error? 

 

Remark:
Code of the fucntion learnt from another export:
 https://stackoverflow.com/questions/60640977/power-query-remove-text-between-delimiters

 

Error Message:

kenchan_1-1655497960490.pngkenchan_2-1655497972519.png

 

 

 

 

 

Function:

= (txt as text) =>
[
fnRemoveFirstTag = (HTML as text)=>
let
OpeningTag = Text.PositionOf(HTML,"[cid"),
ClosingTag = Text.PositionOf(HTML,"]"),
Output =
if OpeningTag = -1
then HTML
else Text.RemoveRange(HTML,OpeningTag,ClosingTag-OpeningTag+1)
in
Output,
fnRemoveHTMLTags = (y as text)=>
if fnRemoveFirstTag(y) = y
then y
else @fnRemoveHTMLTags(fnRemoveFirstTag(y)),
Output = @fnRemoveHTMLTags(txt)
][Output]

4 REPLIES 4
Anonymous
Not applicable

There's probably some limit, like 32,7xx characters.

But couldn't you use those tags as the delimiter, use Text.BetweenDelimiters to get your substrings, and then use those each of those substrings as a parameter to Text.Replace, and replacing with nothing?

Im not at my desk, but you seem to understand functions. Hopefully this gets you started, I'll be in later to check back.

 

--Nate

Thank you for your insight. I try; I believe it solved part of my question. However, if the cell have happen the pattern twice, it may not able to handle at once time. Is there any fucntion which I can handle this? 

 

 

kenchan_0-1655581906266.png

 

PhilipTreacy
Super User
Super User

Hi @kenchan 

 

Please provide your file or at least sample data to run this code against.  Hard to debug it without the data it's using.

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thank you for your response; I attached the link for the data.

 

Step to get the error:

I would like to remove the the strings( "[cid ...]"; "[http ...]"; "[data ...]") in each cells of the file. I simply import the file into power bi; copy and paste the function below and create a new col and apply the function. However, I encounter the error "The 'count' argument is out of range". Thank you for your help and support.

 

Link of Data 

 

the function for removing [cid ...]

Function:

= (txt as text) =>
[
fnRemoveFirstTag = (HTML as text)=>
let
OpeningTag = Text.PositionOf(HTML,"[cid"),
ClosingTag = Text.PositionOf(HTML,"]"),
Output =
if OpeningTag = -1
then HTML
else Text.RemoveRange(HTML,OpeningTag,ClosingTag-OpeningTag+1)
in
Output,
fnRemoveHTMLTags = (y as text)=>
if fnRemoveFirstTag(y) = y
then y
else @fnRemoveHTMLTags(fnRemoveFirstTag(y)),
Output = @fnRemoveHTMLTags(txt)
][Output]

 

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors