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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sardo
Regular Visitor

Convert HTML column to plain/formatted text in Power BI

I need to conver HTML column in plain text. I've watched some tutorials and added a custom column with the following coding in Power Query: Html.Table([HTML text],{{"Plain text",":root"}})

This does not work for me, as I have some empty cells (null) in the "HTML text" column and causes an error when creating and trying to expand the table.

I also tried to conver the HTML column into a formatted text (instead of plain) and didn't work.

 

Hope you can help me with this, thank you.

4 REPLIES 4
Anonymous
Not applicable

Hi @sardo 

 

Can you provide some dummy data to show what you want to achieve? Perhaps you want to extract a table between <table> tags from the HTML code? Or perhaps you want to remove all tags in some HTML code? Do you have HTML code in the [HTML text] column or have a html file in this column?

 

Best Regards,
Jing

Hi Jing,

I'm connected to Salesforce Object and this is an HTML field.

When I use the HTML Content Custom Visual, it shows me the data correctly with the right formatting, but I can't add any more fields and I need the content to be used in a Table. 

I successfully added a custom column in Power Query by using the Html.Table([HTML text],{{"Plain text",":root"}}) code, but it's a plain text and hard for the customer to read.

sardo_1-1709744059717.png

 

 

sardo_0-1709743983925.png

 

Hope this clarifies. Thank you.

Sahir_Maharaj
Super User
Super User

Hello @sardo,

 

Can you please try the following:

 

1. Before converting HTML to text, you should replace or remove null values to prevent errors during the conversion process (Use the "Replace Values" in Power Query)

2. Extract text from the HTML using M code

let
    HtmlToText = (html as text) as text =>
    let
        // Replace HTML tags with empty strings
        Step1 = Text.Replace(html, "<", " <"),
        Step2 = Text.Split(Step1, "<"),
        Step3 = List.Transform(Step2, each if Text.StartsWith(_, "/") or Text.Contains(_, ">") then "" else _),
        TextResult = Text.Trim(Text.Combine(Step3, ""))
    in
        TextResult
in
    HtmlToText

3. Use the custom function you've defined by referencing your HTML column: HtmlToText([YourHtmlColumnName])

 

Note: If your conversion results in a table, you might need to expand it. Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi Sahir, 

Thank you so much for your response.

Can you please guide me where can I add that code in the "Replace Values" in Power Query?

sardo_0-1709551841792.png

sardo_1-1709551903981.png

 

Helpful resources

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