Greg_Deckler's avatar
Greg_Deckler
Icon for Community Champion rankCommunity Champion
6 years ago

DECIMAL

In my recent quest to create or catalog as many DAX equivalents for Excel functions, was able to use BASE and BIN2DEC as references in order to create DECIMAL:

DECIMAL = 
    VAR __Text = MAX('Table'[Text])
    VAR __Radix = MAX('Table'[Radix])
    VAR __Dec2Base = 
        { 
            (0, "0"),
            (1, "1"),
            (2, "2"),
            (3, "3"),
            (4, "4"),
            (5, "5"),
            (6, "6"),
            (7, "7"),
            (8, "8"),
            (9, "9"),
            (10, "A"), 
            (11, "B"), 
            (12, "C"), 
            (13, "D"), 
            (14, "E"), 
            (15, "F"), 
            (16, "G"), 
            (17, "H"), 
            (18, "I"), 
            (19, "J"), 
            (20, "K"), 
            (21, "L"), 
            (22, "M"), 
            (23, "N"), 
            (24, "O"), 
            (25, "P"), 
            (26, "Q"), 
            (27, "R"),
            (28, "S"),
            (29, "T"),
            (30, "U"),
            (31, "V"),
            (32, "W"),
            (33, "X"),
            (34, "Y"),
            (35, "Z")
        }    
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                ADDCOLUMNS(
                    GENERATESERIES(0,LEN(__Text)-1,1),
                    "Text",MID(__Text,LEN(__Text) - [Value],1)
                ),
                "Text2Decimal",MAXX(FILTER(__Dec2Base,[Value2] = [Text]),[Value1])
            ),
            "Decimal",POWER(__Radix,[Value]) * [Text2Decimal]
        )
RETURN
    SUMX(__Table,[Decimal])

No RepliesBe the first to reply