Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
05-01-2020 22:44 PM - last edited 05-04-2020 20:03 PM
In my recent quest to create or catalog as many DAX equivalents for Excel functions, we can make a slight modification to DEC2BIN to get DEC2HEX.
DEC2HEX =
VAR __DecimalNumber = MAX('Table'[Decimal])
VAR __Dec2Hex = { (10, "A"), (11, "B"), (12, "C"), (13, "D"), (14, "E"), (15, "F") }
RETURN
IF(
__DecimalNumber = 0,
"0",
VAR __Table =
ADDCOLUMNS(
ADDCOLUMNS(
GENERATESERIES(0,LOG(__DecimalNumber,16),1),
"HexInDecimal",MOD(TRUNC(__DecimalNumber / POWER(16,[Value])),16)
),
"Hex",IF([HexInDecimal] < 10,[HexInDecimal],MAXX(FILTER(__Dec2Hex,[Value1] = [HexInDecimal]),[Value2]))
)
RETURN
CONCATENATEX(__Table,[Hex],"",[Value],DESC)
)
NOTE: Does it support negative numbers you may ask. The answer is no. See DEC2OCT if you want the rant on the way Excel handles negative numbers in its conversion functions.
ALSO NOTE: You might also ask whether I know that hexadecimal is base 16 and not base 6 because I use hexagons in my image. The answer here is yes, which should be obvious from the fact that this function works versus does not work. But you go try to find a cool image of a hexadecagon and then come talk to me. Which begs the question. Two actually. First, did you know a shape with 16 equal sides was called a hexadecagon? No you did not. Two, shouldn't hexadecimal really be called hexadecadic (Greek) or sexadecimal (Latin)? Uh huh... Who's the idiot now? Oh yeah, those morons that named base-16 hexadecimal, that's who. I mean, sheesh, they couldn't even keep their etymological ancient language origins straight. Losers...
eyJrIjoiNTkyZDJlNDctY2Q3OS00MjQ0LTllYjQtYzMzMTNkOTI4ZmU1IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9
HOW TO GET HEX2DEC?
CONVERT HEX2DEC FOR THIS COLUMN(IGNORE 0x in start that i substitute with space)