Forum Discussion
Removing HTML Script from data in Query Editor
- 8 years ago
I transformed it into a proper function here :-) https://github.com/ImkeF/M/blob/master/Library/Text.RemoveHtmlTags.pq
I transformed it into a proper function here :-) https://github.com/ImkeF/M/blob/master/Library/Text.RemoveHtmlTags.pq
- jchungfluentco8 years agoFrequent Visitor
Thank so much for transforming into a proper function!
I just have some beginner level follow-up questions on how to implement the M script.
The data file I'm using is calle "SurveyResponses_Age&Vertical"
Should I be replacing Source = Text.From(HTML) to Source = Text.From(SurveyResponses_Age&Vertical) ?
Is it best to use the Advanced Editor, and if so, how what's the proper syntax for that?
Thanks!
- ImkeF8 years agoCommunity Champion
Please see if this video helps: https://www.youtube.com/watch?v=6TQN6KPG74Q
If not, please come back here.
- adamsjw658 years agoRegular Visitor
I am connecting to a SharePoint Online List. Is there a way to use this code to remove the HTML Script for the data when I load? Thanks.
- danilosg7 years agoRegular Visitor
Hello my friend!
I´m having the same issue. Did You get a solution?
Thanks.
Dan
- sampathK7 years agoMicrosoft Employee
Awesome , you made my day very easy and simple. Thank you so much...
- Anonymous6 years agoNot applicable
ImkeF Can you please provide guidance on where and how to insert this code? I am assuming it's to be inserted somewhere within the existing code found within the Advanced Editor?
- ImkeF6 years agoCommunity Champion
Hi Anonymous ,
you simply create a new query for this function like described here: https://www.youtube.com/watch?v=6TQN6KPG74Q
- Anonymous6 years agoNot applicable
ImkeF OK, thank you.
I am importing data fom ServiceNow and every column contains HTML markup. I included a snipped of the URL below.
Can your function transform all of the columns on import somehow?
let func = (HTML) =>
let
Check = if Value.Is(Value.FromText(HTML), type text) then HTML else "",
Source = Json.Document(Web.Contents("https://dev.service-now.com/api/now/table/project?sysparm_fields=assumptions%2Cbarriers%2Cbenefits%2Cbusiness_case%2Cbusiness_unit%2short_description")),
SplitAny = Text.SplitAny(Source,"<>"),
ListAlternate = List.Alternate(SplitAny,1,1,1),
ListSelect = List.Select(ListAlternate, each _<>""),
TextCombine = Text.Combine(ListSelect, "")
in
TextCombine,
documentation = [
Documentation.Name = " Text.RemoveHtmlTags"
, Documentation.Description = "Remove Html Tags"
, Documentation.LongDescription = " Removes all Html tags from a text"
, Documentation.Category = " Text.Modification"
, Documentation.Source = " Inspired by a solution from Bill Szysz"
, Documentation.Author = " Imke Feldmann: www.TheBIccountant.com & Mike Carlo: PowerBI.Tips"
, Documentation.Examples = {[
Description = "Function that enables one to pass in a column that has HTML tags."
, Code = "<div>my bit of text</div>"
, Result = "my bit of text "
]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
- Project246015 years agoNew Member
This did it for me, thanks to ImkeF for the many posts to help complement instrucitons for making use of it!
- Project246015 years agoNew Member
Many thanks ImkeF, documentation and instruction very helpful to execute.
- YevD5 years agoHelper I
Hi ImkeF,
I am having the same issue with a field in a table I am pulling from Salesforce object. Would you be able tell me what I'm doing wrong when trying to implement your code? Are there other lines I would need to modify besides source? I am pasting it below the exsisting code in the query for this particular table and getting "Token Eof expected" error. Sorry if these are overly basic questions, I'm only just beginning to learn power query so any help you can offer is much appreciated!
let Source = Salesforce.Data("https://login.salesforce.com/", [ApiVersion=48, CreateNavigationProperties=true]), Claims__c = Source{[Name="Claims__c"]}[Data], #"Renamed Columns" = Table.RenameColumns(Claims__c,{{"Name", "Claim Number"}, {"Claim_Notice_Date__c", "Claim Notice Date"}, {"Loss_Type__c", "Loss Type"}, {"Status__c", "Status"}, {"Date_of_Binding__c", "Date of Binding"}, {"Claim_Type__c", "Claim Type"}}), #"Inserted Merged Column" = Table.AddColumn(#"Renamed Columns", "Merged", each Text.Combine({[Status], " - ", Text.Proper([Loss Type])}), type text), #"Removed Columns" = Table.RemoveColumns(#"Inserted Merged Column",{"Merged"}), #"Inserted Merged Column1" = Table.AddColumn(#"Removed Columns", "Merged", each Text.Combine({[Status], " - ", [Loss Type]}), type text), #"Added Conditional Column" = Table.AddColumn(#"Inserted Merged Column1", "Ststus & Loss Type", each if [Merged] = "Open - Third Party" then "Open 3rd" else if [Merged] = "Open - First Party" then "Open 1st" else if [Merged] = "Closed - Third Party" then "Closed 3rd" else if [Merged] = "Closed - First Party" then "Closed 1st" else null, type text), #"Renamed Columns1" = Table.RenameColumns(#"Added Conditional Column",{{"Ststus & Loss Type", "Status & Loss Type"}}), #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns1",{"Status & Loss Type", "Merged"}), #"Inserted Merged Column2" = Table.AddColumn(#"Removed Columns1", "Merged", each Text.Combine({[Status], " ", [Loss Type]}), type text), #"Sorted Rows" = Table.Sort(#"Inserted Merged Column2",{{"CreatedDate", Order.Descending}}), #"Renamed Columns2" = Table.RenameColumns(#"Sorted Rows",{{"Merged", "Status & Loss Type"}}), #"Added Custom" = Table.AddColumn(#"Renamed Columns2", "Has Reserve?", each if [ET_Loss_Reserve__c] = null or [ET_Loss_Reserve__c] = 0 then "No" else "Yes"), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each [ET_Loss_Reserve__c]+[Paid_Loss__c]+[Paid_ALAE__c]+[Paid_Expense__c]), #"Renamed Columns3" = Table.RenameColumns(#"Added Custom1",{{"Custom", "Known Exposure"}}), #"Removed Columns2" = Table.RemoveColumns(#"Renamed Columns3",{"Known Exposure"}), #"Inserted Sum" = Table.AddColumn(#"Removed Columns2", "Addition", each List.Sum({[Paid_Loss__c], [Paid_Expense__c], [Paid_ALAE__c], [ET_Loss_Reserve__c]}), type number), #"Renamed Columns4" = Table.RenameColumns(#"Inserted Sum",{{"Addition", "Known Exposure"}}) in #"Renamed Columns4" let func = (HTML) => let Check = if Value.Is(Value.FromText(HTML), type text) then HTML else "", Source = Salesforce.Data("https://login.salesforce.com/", [ApiVersion=48, CreateNavigationProperties=true]), SplitAny = Text.SplitAny(Source,"<>"), ListAlternate = List.Alternate(SplitAny,1,1,1), ListSelect = List.Select(ListAlternate, each _<>""), TextCombine = Text.Combine(ListSelect, "") in TextCombine, documentation = [ Documentation.Name = " Text.RemoveHtmlTags" , Documentation.Description = "Remove Html Tags" , Documentation.LongDescription = " Removes all Html tags from a text" , Documentation.Category = " Text.Modification" , Documentation.Source = " Inspired by a solution from Bill Szysz" , Documentation.Author = " Imke Feldmann: www.TheBIccountant.com & Mike Carlo: PowerBI.Tips" , Documentation.Examples = {[ Description = "Function that enables one to pass in a column that has HTML tags." , Code = "<div>my bit of text</div>" , Result = "my bit of text " ]}] in Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))