cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Zyg_D
Responsive Resident
Responsive Resident

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
Responsive Resident
Responsive Resident

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
Responsive Resident
Responsive Resident

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
Responsive Resident
Responsive Resident

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. 

amitchandak
Super User
Super User

Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!