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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JFAschoon
Helper I
Helper I

Converting 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 like to use the same syntex but only modifying it to be able to do 4 hexadecimal digits.Ive Tried but failed badly. See example syntex below

 

HexToDecimal =

VAR _FirstHexDigit = RIGHT('CM18'[Hex],1)
VAR _SecondHexDigit = MID('CM18'[Hex],3,1)


RETURN

LOOKUPVALUE('HexTable'[Dec],'HexTable'[Hex], _SecondHexDigit)*16 +LOOKUPVALUE('HexTable'[Dec],'HexTable'[Hex], _FirstHexDigit)

 

thanks 

 

Regards 

Johan

7 REPLIES 7
Greg_Deckler
Community Champion
Community Champion

@JFAschoon Here is a DAX solution I created:

DECIMAL - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

i dont know what im doing wrong but i cant  get it to function

@JFAschoon Can you share sample data or your PBIX file?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Ahmedx
Super User
Super User

updated fanction

 

(HextoDecimal) =>
  List.Sum(
    [
      t = Splitter.SplitTextByRepeatedLengths(1)(HextoDecimal),
      dict = List.Buffer(
        {
          {"0", "0"},
          {"1", "1"},
          {"2", "2"},
          {"3", "3"},
          {"4", "4"},
          {"5", "5"},
          {"6", "6"},
          {"7", "7"},
          {"8", "8"},
          {"9", "9"},
          {"A", "10"},
          {"B", "11"},
          {"C", "12"},
          {"D", "13"},
          {"E", "14"},
          {"F", "15"}
        }
      ),
      f = (x) => List.Accumulate(dict, x, (s, c) => Text.Replace(s, c{0}, c{1})),
      ListTrans = List.Transform(t, (x) => f(x)),
      ListPower = List.Generate(() => List.Count(t) - 1, (x) => x >= 0, (x) => x - 1),
      ListDecimal = Table.FromColumns({ListTrans, ListPower}, {"decimal", "Power"}),
      addColumn = Table.AddColumn(
        ListDecimal,
        "DecimalSum",
        each Number.From([decimal]) * Number.Power(16, [Power])
      )[DecimalSum]
    ][addColumn]
  )

 

Ahmedx
Super User
Super User

I wrote you a function to convert HEX to decimal

(HextoDecimal) =>
  List.Sum(
    Table.AddColumn(
      
         [
          ListDic=
          [
            t = Splitter.SplitTextByRepeatedLengths(1)(HextoDecimal), 
            dict = List.Buffer(
              {
                {"0", "0"}, 
                {"1", "1"}, 
                {"2", "2"}, 
                {"3", "3"}, 
                {"4", "4"}, 
                {"5", "5"}, 
                {"6", "6"}, 
                {"7", "7"}, 
                {"8", "8"}, 
                {"9", "9"}, 
                {"A", "10"}, 
                {"B", "11"}, 
                {"C", "12"}, 
                {"D", "13"}, 
                {"E", "14"}, 
                {"F", "15"}
              }
            ), 
            f = (x) => List.Accumulate(dict, x, (s, c) => Text.Replace(s, c{0}, c{1})), 
            to = List.Transform(t, (x) => f(x))
          ][to],
          ListPower= 
          List.Generate( () => List.Count(ListDic)-1,
               (x)=> x >= 0,
               (x)=> x-1),
              ListDecimal= Table.FromColumns({ListDic,ListPower},{"decimal", "Power"})][ListDecimal]
        
      , 
      "DecimalSum", 
      each Number.From([decimal]) * Number.Power(16, [Power])
    )[DecimalSum]
  )


Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
HextoDecimal.pbix

hnguy71
Super User
Super User

@JFAschoon ,

 

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:

hnguy71_0-1697380550943.png

 

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:

hnguy71_1-1697380654629.png

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.