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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Zyg_D
Continued Contributor
Continued Contributor

HTML symbol decimal values translated to actual symbols

E.g., in I can have this string value in the column: 

Раrtizаn

I would like this value to appear as 

Partizan

Is it possible to transform a string which can contain any number of any HTML symbol (not using R or Py) ?

 

1 ACCEPTED SOLUTION
Zyg_D
Continued Contributor
Continued Contributor

Html.Table works brilliantly! Full inspectable code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDAyUzY0MDWzhrPNjayLSjKrkPl5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "HtmlStep", each Html.Table([col1],{{"HtmlDecoded",":root"}})),
    #"Expanded HtmlStep" = Table.ExpandTableColumn(#"Added Custom", "HtmlStep", {"HtmlDecoded"}, {"HtmlDecoded"})
in
    #"Expanded HtmlStep"

html.PNG

 

Or without a new column: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDAyUzY0MDWzhrPNjayLSjKrkPl5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}}),
    Decoded = Table.TransformColumns(#"Changed Type", 
        {{ "col1", each Table.FirstValue(Html.Table(_,{{"HtmlDecoded",":root"}})) }} )
in
    Decoded

1col.PNG

 

View solution in original post

4 REPLIES 4
Zyg_D
Continued Contributor
Continued Contributor

Html.Table works brilliantly! Full inspectable code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDAyUzY0MDWzhrPNjayLSjKrkPl5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "HtmlStep", each Html.Table([col1],{{"HtmlDecoded",":root"}})),
    #"Expanded HtmlStep" = Table.ExpandTableColumn(#"Added Custom", "HtmlStep", {"HtmlDecoded"}, {"HtmlDecoded"})
in
    #"Expanded HtmlStep"

html.PNG

 

Or without a new column: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDAyUzY0MDWzhrPNjayLSjKrkPl5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}}),
    Decoded = Table.TransformColumns(#"Changed Type", 
        {{ "col1", each Table.FirstValue(Html.Table(_,{{"HtmlDecoded",":root"}})) }} )
in
    Decoded

1col.PNG

 

PhilipTreacy
Super User
Super User

Hi @Zyg_D 

Yes you can do this, here's the M code to copy/paste into a blank query, and a sample PBIX file

 

let
    Codes = [1056 = "P", 1072 = "a"],
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wiik1MDAyUzY0MDWzhrPNjayLSjKrkPl5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Text = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.RemoveMatchingItems(Text.SplitAny([Text],";&#"),{" "})),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Combine(List.Transform([Custom], each try if Number.From(_) > 0 then Record.Field(Codes,_) else null otherwise _ ))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"})
in
    #"Removed Columns"

 

I've created a Record with the codes for P and a , you will need to add whatever other codes you need to this.  You could use a List or a Table Column just as well, but the above code will need to be modified to accomodate this.

 

The code splits the text into separate codes and letters, replaces the code with the letter from the Codes Record then recombines everything.

html-codes.png

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Zyg_D
Continued Contributor
Continued Contributor

Thanks, @PhilipTreacy 

This may work, but I would need to know beforehand which HTML codes I may get. Sadly I don't know what users will provide me with.

I know there is a DAX function UNICHAR, which decodes all those numeric values into symbols, but I don't know how to deploy it so that it would read any number of occurrences. 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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