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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
amulyaaregunta
Frequent Visitor

POWERBI DAX

amulyaaregunta_0-1615239332274.png

CONVERT THE ABOVE COLUMN TO DECIMAL VALUES WHICH ARE NOW IN HEXADECIMAL FORM, LIKE FOR EXAMPLE 0x40 should get value 64 ( by substitue 0x to space). I WANT ONLY IN DAX NOT IN POWER QUERY OR M.

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @amulyaaregunta 

 

Download example PBIX with code

 

Do you just need this conversion for 2 digit hex numbers?  This code works only for 2 digits as shown in your example but can be expanded for more digits.

Firstly, create a new table 

 

HexTable = {
                ("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)
                }

 

 

Rename the text column Hex and the numeric column Decimal

Then create a column in your table containing the hex - change the VAR statements with 'Table'[Hex] to match your own table and column names.

 

HexToDecimal = 

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

RETURN 

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

 

hextod.png

Regards

Phil



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!


View solution in original post

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @amulyaaregunta 

 

Download example PBIX with code

 

Do you just need this conversion for 2 digit hex numbers?  This code works only for 2 digits as shown in your example but can be expanded for more digits.

Firstly, create a new table 

 

HexTable = {
                ("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)
                }

 

 

Rename the text column Hex and the numeric column Decimal

Then create a column in your table containing the hex - change the VAR statements with 'Table'[Hex] to match your own table and column names.

 

HexToDecimal = 

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

RETURN 

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

 

hextod.png

Regards

Phil



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!


Hi  @PhilipTreacy 

 

Im still new to this power BI. Just one question how do i add another 2 digits to the Hexdec conversion syntex.

Example: d2da

 

Regards 

Johan

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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