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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
LoMorrissey
New Member

Extracting HTML Code from Power Bi

I am attempting to extract HTML text by creating a custom column but keep the rows with regular text at the same time. I have used this code to remove the HTML text but am missing the part where it keeps the rows with regular text:

 

= if Text.StartsWith([Final Decision Notes], "<") then
Table.Combine({
Html.Table("<div>" & [Final Decision Notes] & "</div>", {{"Final Decision Notes", "div"}}),
Html.Table("<div>" & [Final Decision Notes] & "</div>", {{"Final Decision Notes", "br"}})
})
else
#table({"Final Decision Notes"}, {{ [Final Decision Notes] }})

 

What am I missing? 

5 REPLIES 5
Omid_Motamedise
Super User
Super User

you can define the following function and use it in your code

 

(inputText as text) as table =>
    if Text.StartsWith(inputText, "<") then
        Table.Combine({
            Html.Table("<div>" & inputText & "</div>", {{"Final Decision Notes", "div"}}),
            Html.Table("<div>" & inputText & "</div>", {{"Final Decision Notes", "br"}})
        })
    else
        #table({"Final Decision Notes"}, {{ inputText }})
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
v-karpurapud
Community Support
Community Support

Hi @LoMorrissey 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If your issue resolved, kindly mark the helpful response and accept it as the solution to assist other community members in resolving similar issues more efficiently. If not, please provide detailed information so we can better assist you.

Hi,

 

I asked one of my colleagues and he was able to give me this code which solved the issue: 

 


#"Added Custom" = Table.AddColumn( #"Replaced Value24" , "Custom", each if [Review Team Notes] = null or not Text.Contains([Review Team Notes], "<") then
    "<p>" & [Review Team Notes] & "</p>"
else
    [Review Team Notes]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] <> null then
Html.Table([Custom], {{"text", ":root"}})
else
[Custom]),
#"Expanded Custom.1" = Table.ExpandTableColumn(#"Added Custom1", "Custom.1", {"text"}, {"Custom.1.text"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"Review Team Notes", "Custom"}),
#"Renamed Columns12" = Table.RenameColumns(#"Removed Columns",{{"Custom.1.text", "Review Team Notes"}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns12",{{"Review Team Notes", type text}})
in
#"Changed Type2"

 

v-karpurapud
Community Support
Community Support

Hi @LoMorrissey 


Welcome to the Microsoft Fabric Community Forum.
 

The issue observed in Power BI, involving the extraction of HTML content while retaining plain text rows, is primarily due to inconsistencies in the conditional logic used within the custom column formula. The current implementation utilizes Html.Table to parse HTML content when the text begins with an HTML tag indicator (such as <), but fails to maintain a consistent output structure for rows containing plain text. This discrepancy can lead to schema misalignment during data transformation.

 

To address this, it is recommended to ensure that both HTML and non-HTML rows are returned in a uniform table format. This can be achieved by wrapping plain text rows in a table structure that mirrors the output of the HTML parsing logic.

 

= if Text.StartsWith([Final Decision Notes], "<") then

    Table.Combine({

        Html.Table("<div>" & [Final Decision Notes] & "</div>", {{"Final Decision Notes", "div"}}),

        Html.Table("<div>" & [Final Decision Notes] & "</div>", {{"Final Decision Notes", "br"}})

    })

else

    #table({"Final Decision Notes"}, {{ [Final Decision Notes] }})

 

For reference:
Html.Table - PowerQuery M | Microsoft Learn


Thank you for being part of Fabric Community Forum.

Regards,
Karpurapu D,
Microsoft Fabric Community Support Team.


lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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