05-01-2020 22:10 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 DEC2OCT.
DEC2OCT = VAR __DecimalNumber = MAX('Table'[Decimal]) RETURN IF( __DecimalNumber = 0, "0", VAR __Table = ADDCOLUMNS( GENERATESERIES(0,LOG(__DecimalNumber,8),1), "Oct",MOD(TRUNC(__DecimalNumber / POWER(8,[Value])),8) ) RETURN CONCATENATEX(__Table,[Oct],"",[Value],DESC) )
NOTE: Does it support negative numbers you may ask. The answer is no. And the reason is that the way Excel does negative numbers with these conversion functions fails to make a single lick of sense. If you want it to be negative, multiple the result by -1 because otherwise its just stupid. I mean, 1001 decimal is 1751 octal so why is -1001 decimal 7777776027 octal versus just simply -1751. I mean if that made even a modicrum of sense, then -1001 decimal should be written 9999998998 decimal, right? Except; oh that's right, it's not because that makes zero sense whatsoever and if you wrote it that way people would look at you funny and think you were a complete and utter idiot. Not even "new math" and "common core" changed how negative numbers are written so; you know, the idiots have already given it their best shots...