Forum Discussion

amaaiia's avatar
amaaiia
Skilled Sharer
2 years ago
Solved

Decimal column to hexadecimal with Dataflow Gen2

I am trying to add a new column to my table via Dataflow Gen2, so that my new column HEXNumber has to be as my old column DECNumber converted to Hexadecimal. So first, I've duplicated DECNumber and renamed it as HEXNumber, so for the moment HEXNumber=DECNumber. Now, for HEXNumber to be in hexadecimal, I'm trying with:

 

 

Table.TransformColumns(#"Renamed columns", {{"HEXNumber", each Number.ToText(_, "x") , Text.Type}})

 

 

 

But it's not working. If I change _ to a random number (45), it works, the HEXNumber column is 45 converted to Hexadecimal.

 

 

Table.TransformColumns(#"Renamed columns", {{"HEXNumber", each Number.ToText(45, "x") , Text.Type}})

 

 

 

But what I need is to convert each Decimal number into Hexadecimal, not always 45. I don't know what do I have to write where _ is written.

  • _ usually identifies the entire row.  You would need to use something like _[DECNumber] or just [DECNumber]

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFVitWJVjKzAFMmRmDK0NAYTBsbGCjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DECNumber = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"DECNumber", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "HEXNumber", each Number.ToText([DECNumber],"x"))
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

1 Reply

  • _ usually identifies the entire row.  You would need to use something like _[DECNumber] or just [DECNumber]

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFVitWJVjKzAFMmRmDK0NAYTBsbGCjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DECNumber = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"DECNumber", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "HEXNumber", each Number.ToText([DECNumber],"x"))
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.