Forum Discussion
Extracting HTML Code from Power Bi
- 1 year ago
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.
Hi LoMorrissey
You're trying to create a custom column in Power Query that extracts meaningful text from rows containing HTML content, while preserving rows that already contain plain text. Your current code attempts to parse HTML when the Final Decision Notes column starts with a < character (which typically indicates HTML), and otherwise returns the original value. However, you're using Table.Combine(...) inside a row-level expression, which is designed to return a table, not a value, and that causes inconsistency—Power Query expects each row to return a scalar (like a single text value), not an entire table.
What you're missing is the extraction of text from the HTML table structure into a single value per row. Also, you need to ensure the output is consistently a single text string, regardless of whether the input is HTML or plain text.
Here’s a corrected version of your logic:
= if Text.StartsWith([Final Decision Notes], "<") then
let
html = "<div>" & [Final Decision Notes] & "</div>",
divTable = Html.Table(html, {{"Text", "div"}}),
brTable = Html.Table(html, {{"Text", "br"}}),
allText = List.Combine({divTable[Text], brTable[Text]}),
mergedText = Text.Combine(List.Select(allText, each _ <> null), " ")
in
mergedText
else
[Final Decision Notes]