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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
fabioRond
New Member

How to convert Hex to text and Hex to Datetime

Hi,

I have a data source from a DB that stores most of the data as a binary that were firstly converted into hex.

I am trying to find a formula to convert hex to text (ASCII) but I do not get what passages are required.

the format of the data is text in hex numbers and I would need to bring them to text ASCII ("4551303237" => "EQ027").

 

I tried to convert them to decimal and then to text but it does not work.

 

I tried this method from @Greg_Deckler 

https://community.powerbi.com/t5/Desktop/convert-from-hexadecimal-value-to-number/td-p/28435

 

then this

https://xxlbi.com/blog/converting-hexadecimal-to-decimal-numbers-in-power-query/

 

then this 

https://community.powerbi.com/t5/Desktop/convert-from-hexadecimal-value-to-number/td-p/28435

 

no luck so far even if with this page I get the conversion on the first attempt (http://www.unit-conversion.info/texttools/hexadecimal/)

 

I also tried using Text from or BinaryFormat.Text(2, TextEncoding.Ascii)

 

I was able to get a date out of the hex data using this formula but the year is not correct, probably because it should be DateTime. (40468AE5D5C2E02C =>13/02/1900)

Date.From( BinaryFormat.ByteOrder(BinaryFormat.Double, ByteOrder.BigEndian)( Binary.FromText([#"HEX(fom.Value)"], BinaryEncoding.Hex))) )  

 

Seems a trivial thing to do but I was not able to understand why Power Query is not covered

 

 

1 ACCEPTED SOLUTION

Found the solution probably could help someone else. @Greg_Deckler not sure if is the correct approach, hope make more sense to expert users .

= (textHEX as text , Loop as number , optional Value as text) =>
let
totalLoops = Text.Length(textHEX) ,
CurrentLoop = Loop + 2,
CurrentValue = Value & Character.FromNumber(Expression.Evaluate("0x" & Text.Range(textHEX, Loop, 2))),
output =
if CurrentLoop >= totalLoops
then CurrentValue
else @TestFunction(textHEX,CurrentLoop, CurrentValue)

in
output

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@fabioRond So you are starting with a hex value of 4551303237 and then you want to convert it to "text" of "EQ027"? I'm not sure how one equates to the other.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  That is done easily in MatLab with a simple conversion Base 16 (hexadecimal) and to char. so the 45 is translated to 69 and then converted to Ascii char "E". I am not so expert to reconstruct the same approach with a function in power query

Found the solution probably could help someone else. @Greg_Deckler not sure if is the correct approach, hope make more sense to expert users .

= (textHEX as text , Loop as number , optional Value as text) =>
let
totalLoops = Text.Length(textHEX) ,
CurrentLoop = Loop + 2,
CurrentValue = Value & Character.FromNumber(Expression.Evaluate("0x" & Text.Range(textHEX, Loop, 2))),
output =
if CurrentLoop >= totalLoops
then CurrentValue
else @TestFunction(textHEX,CurrentLoop, CurrentValue)

in
output

mh2587
Super User
Super User

referring this article may be you get some idea
https://dax.tips/2019/10/02/dax-base-conversions/


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



unfortunately is not helping

 

my data are already as hex which then is converted in MatLab directly into text using ASCII.

 

I am not using DAX but power query.

 

was trying to replicate the same step used with python using the BinaryFormat

https://www.adamsmith.haus/python/answers/how-to-convert-a-string-from-hex-to-ascii-in-python

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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