Forum Discussion
Power Query: remove all text between delimiters
- 8 years ago
you can use recursion in PowerQuery
crate a blank query and paste this code into editor, then call this function on your HTML column(txt as text) => [ fnRemoveFirstTag = (HTML as text)=> let OpeningTag = Text.PositionOf(HTML,"<"), 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]EDIT - typo in syntax
Hey Interkoubess,
This formula (with minor changes) is working, but it will only give you the first text. The problem is, that there are more between in a record, and every record is different (so, like in my sample data, the first record has 5 TEXT parts, the second one 3 TEXT parts etc).
What do you think the general solution should be?
Regards,
Andris
you can use recursion in PowerQuery
crate a blank query and paste this code into editor, then call this function on your HTML column
(txt as text) =>
[
fnRemoveFirstTag = (HTML as text)=>
let
OpeningTag = Text.PositionOf(HTML,"<"),
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]EDIT - typo in syntax
- pAAmckelvey6 years agoFrequent Visitor
Stachu ,
I'm new to calling functions on columns so please bear with me.
The statement " then call this function on your HTML column" confuses me a little bit. The query solution you provided has been created in my project and is called "RemoveHTML".
The column with the HTML is called "Comments" and the table it is located in is called "Issues".
Do I create a function from the Query first? If so, the system wants me to create a parameter as it says the Query doesn't include a parameter.
Not sure what my next steps are, any assistance is appreciated.
Patrick
- Stachu6 years agoCommunity Champion
pAAmckelvey in the Issues table you need to create a new column with this syntax:
RemoveHTML([Comments])- Anonymous6 years agoNot applicable
I am just getting into functions myself and have been working on a problem to remove HTML tags from within a comments column.
I tried using the Function as you outlined, but I keep getting an error that I am passing a parameter to a functions that expects 0 parameters.
(1) In my steps, I created a blank query and copied your code into it.
(2) I then created a function from the blank query.
(3) Created a Custom Column and added the syntax you outlined in your response. (Probably where I am going wrong.)
(4) It then returns the error I mention above.
Any thoughts on what I might be doing wrong?
Thanks
Joe Mays
- Gill3 years agoNew Member
Hi Stachu , I'm new to using power query to extract data from sharepoint.
I followed your code to remove all the HTML but there is this error msg. Appreciate your help on this.
- Stachu3 years agoCommunity Champion
hi Gill
it seems you've put the code into the formula bar rather than an advanced editor:
https://learn.microsoft.com/en-us/power-query/power-query-ui#the-advanced-editor
- lawrence_sproul1 year agoNew Member
This is nice, but null values in the column produce errors.