RelativeToTarget.Percents

Dynamic format string generator for comparison values (in percent) with directional indicators. This function creates format strings that include visual symbols (arrows, triangles, etc.) to indicate whether values are positive, negative, or zero compared to a target.

Syntax

DaxLib.FormatString.RelativeToTarget.Percents ( position, decimal_places, symbol, [custom_prefix], [custom_suffix] )

Definition

DAX
// Dynamic format string generator for comparison values (in percent)
// Returns format string with directional indicators based on parameters
(
    // Position of comparison symbol
    // Expects "PREFIX" or "SUFFIX"
    position: STRING,

    // Number of decimal places
    // Expects an INT64 value from 0-9
    decimal_places: INT64,

    // Symbol style - number (1-9) or text:
    // 1 or "ARROWS": ↑/↓
    // 2 or "TRIANGLES": ▲/▼
    // 3 or "PLUSMINUS": +/-
    // 4 or "CHEVRONS": ˄/˅
    // 5 or "GREENRED": 🟢/🔴
    // 6 or "BLUEORANGE": 🔵/🟠
    // 7 or "BLOCKARROWS": ⬆/⬇
    // 8 or "CHECKCROSS": ✓/✗
    // 9 or "NONE": no symbol
    symbol: ANYVAL,

    // Custom prefix text (optional)
    // Enter "" to skip parameter
    // Enter SELECTEDVALUE( 'Exchange Rate'[Currency Symbol] ) for dynamic currency conversion
    //
    // Note: Value is string-safe; no need for """"
    custom_prefix: EXPR,

    // Custom suffix text (optional)
    // Enter "" to skip parameter
    // Enter SELECTEDVALUE( 'Exchange Rate'[Currency Symbol] ) for dynamic currency conversion
    // Enter " (" & FORMAT ( [PercentMeasure], "0.0%" ) & ")" to add a second value for context
    //
    // Note: Value is string-safe; no need for """"
    custom_suffix: EXPR
)
=>
    VAR _BaseFormat =
        DaxLib.FormatString.Component.DecimalPlaces( "#,##0", decimal_places ) & "%"

    VAR _Prefix =
        DaxLib.FormatString.Component.MakeStringSafe ( custom_prefix )

    VAR _Suffix =
        DaxLib.FormatString.Component.MakeStringSafe ( custom_suffix )

    VAR _PositiveSymbol =
        DaxLib.FormatString.Component.Symbols ( symbol, "POSITIVE" )

    VAR _NegativeSymbol =
        DaxLib.FormatString.Component.Symbols ( symbol, "NEGATIVE" )

    VAR _PositiveFormat =
        _Prefix
            & SWITCH (
                position,
                "PREFIX", _PositiveSymbol & " " & _BaseFormat,
                "SUFFIX", _BaseFormat & " " & _PositiveSymbol,
                _BaseFormat & " " & _PositiveSymbol
            )
            &
        _Suffix

    VAR _NegativeFormat =
        _Prefix
            & SWITCH (
                position,
                "PREFIX", _NegativeSymbol & " " & _BaseFormat,
                "SUFFIX", _BaseFormat & " " & _NegativeSymbol,
                _BaseFormat & " " & _NegativeSymbol
            )
            &
        _Suffix

    VAR _ZeroFormat =
        _Prefix
            &
            _BaseFormat
            &
        _Suffix

    RETURN
        _PositiveFormat & ";" & _NegativeFormat & ";" & _ZeroFormat

Parameters

Parameter Type Description
position STRING "PREFIX" or "SUFFIX" for symbol placement
decimal_places INT64 Number of decimal places (0-9)
symbol ANYVAL Symbol style: numbers 1-9 or text codes (see Symbol Styles below)
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.RelativeToTarget.Percents ( "PREFIX", 1, "TRIANGLES", "", "" )

Use this function to create directional formatting for percentage comparisons with symbols.

Related Functions