Basic.Ordinals

Ordinal number formatting (1st, 2nd, 3rd, etc.).

Syntax

DaxLib.FormatString.Basic.Ordinals ( )

Definition

DAX
// Convert numbers to ordinal format
// Returns ordinal numbers like "1st", "2nd", "3rd", "21st"
() =>
    VAR _Num = ABS( SELECTEDMEASURE () )
    VAR _LastDigit = MOD( _Num, 10 )
    VAR _LastTwoDigits = MOD( _Num, 100 )

    VAR _Suffix =
        SWITCH (
            TRUE (),
            _LastTwoDigits >= 11 && _LastTwoDigits <= 13, "th",
            _LastDigit = 1, "st",
            _LastDigit = 2, "nd",
            _LastDigit = 3, "rd",
            "th"
        )

    RETURN
       "#,##0" & _Suffix

Parameters

This function takes no parameters.

Example

DaxLib.FormatString.Basic.Ordinals ()

Use this function in a measure's formatStringDefinition to apply ordinal number formatting.

Related Functions