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

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


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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