Forum Discussion
JFAschoon
Helper I
2 years agoConverting Hexadecimal to Decimal
Good all. Ive got the following syntex to convert a 2 digit HexaDecimal(2E) to Decimal value which works 100% fine. Know im sitting with a 4 digit HexaDecimal(d2da) in a column which i would li...
hnguy71
Super User
2 years ago
I believe it would be easier and more dynamic if you did it inside power query.
Since you already have a hex conversion table, within PowerQuery should be easy enough:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMnV0UorViVYyMwBTJgaGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hex = _t]),
// Hex to Decimal Conversion Starts Here
ConvertHex = Table.AddColumn(Source, "ConvertHex", each
Table.Group(
Table.AddColumn(
Table.AddColumn(
Table.ExpandTableColumn(
Table.NestedJoin(
Table.AddIndexColumn(
Table.FromList(
Text.ToList(Text.Reverse([Hex]))
),
"Index", 0, 1, Int64.Type
),
{"Column1"}, HexTable, {"ID"}, "HexTable", JoinKind.LeftOuter
),
"HexTable", {"Value"}, {"Value"}),
"Group", each 1
),
"AddMeUp",
each Number.Power( 16, [Index]) * [Value]
),
{"Group"}, {{"Decimal", each List.Sum([AddMeUp]), type number}})),
ToDecimal = Table.ExpandTableColumn(ConvertHex, "ConvertHex", {"Decimal"}, {"Decimal"})
in
ToDecimal
Sample Output: