DynamicUnits

Dynamic format string with automatic K/M/bn/tn suffix, rounding, and decimal places based on value magnitude. This function automatically scales numbers and applies appropriate suffixes (K for thousands, M for millions, etc.) while supporting currency symbols and custom prefixes/suffixes.

Syntax

DaxLib.FormatString.DynamicUnits ( format_value, currency_symbol, currency_position, [custom_prefix], [custom_suffix] )

Definition

DAX
// Dynamic format string with automatic K/M/bn/tn suffix, rounding, and decimal places based on value magnitude
// Supports dynamic currency conversion
(
    // The value to format
    // Expects a numeric value or measure reference
    // Recommended: SELECTEDMEASURE()
    format_value: EXPR,

    // The currency symbol you want to use
    // Expects a symbol like "$"
    // Enter "" for none
    // Use DaxLib.FormatString.Component.GetCurrencySymbol for dynamic currency conversion
    currency_symbol: STRING,

    // Whether the currency should be a prefix or suffix
    // Expects "PREFIX" or "SUFFIX"
    // Enter "" for none
    // Use DaxLib.FormatString.Component.GetCurrencyPosition for dynamic currency conversion
    currency_position: STRING,

    // Custom prefix (optional)
    // Enter "" for none
    // Note: Value is string-safe; no need for """"
    custom_prefix : EXPR,

    // Custom suffix (optional)
    // Enter "" for none
    // Note: Value is string-safe; no need for """"
    custom_suffix : EXPR
)
=>
    VAR _NumberFormat =
        DaxLib.FormatString.Component.DynamicUnits( "#,##0", format_value )

    VAR _CurrencySymbol =
        currency_symbol

    VAR _CurrencyPosition =
        currency_position

    VAR _Prefix =
        IF ( _CurrencyPosition = "PREFIX", _CurrencySymbol & " ", "" ) &
        DaxLib.FormatString.Component.MakeStringSafe( custom_prefix )

    VAR _Suffix =
        IF ( _CurrencyPosition = "SUFFIX", " " & _CurrencySymbol, "" ) &
        DaxLib.FormatString.Component.MakeStringSafe( custom_suffix )

    VAR _FormatString =
        _Prefix & _NumberFormat & _Suffix

    RETURN
        _FormatString

Parameters

Parameter Type Description
format_value EXPRESSION The value to format. Recommended: SELECTEDMEASURE()
currency_symbol STRING Currency symbol to display, or empty string "" for none
currency_position STRING "PREFIX" or "SUFFIX" for currency symbol placement
custom_prefix EXPRESSION Optional custom prefix text to add before the formatted value
custom_suffix EXPRESSION Optional custom suffix text to add after the formatted value

Example

DaxLib.FormatString.DynamicUnits ( SELECTEDMEASURE(), "$", "PREFIX", "", "" )

Use this function in a measure's formatStringDefinition to create dynamic scaling with currency support.

Related Functions