Component.DynamicUnits
Get dynamic unit suffix (K, M, B, T) based on value magnitude. Returns appropriate scaling suffix for large numbers.
Syntax
DaxLib.FormatString.Component.DynamicUnits ( value )
Definition
DAX
// Helper function to dynamically round and format values
(
// Base format string
base_format: STRING,
// Expects a valid format string base, i.e. "#,##0"
// The value to format
// EXPR because it must be able to handle SELECTEDMEASURE() and arbitrary expressions
format_value: EXPR
)
=>
VAR _CurrentValue =
format_value
VAR _Format =
base_format &
SWITCH (
TRUE (),
_CurrentValue <= 1E3, ".",
_CurrentValue <= 1E4, ",.00 K",
_CurrentValue <= 1E5, ",.0 K",
_CurrentValue <= 1E6, ",. K",
_CurrentValue <= 1E7, ",,.00 M",
_CurrentValue <= 1E8, ",,.0 M",
_CurrentValue <= 1E9, ",,. M",
_CurrentValue <= 1E10, ",,,.00 bn",
_CurrentValue <= 1E11, ",,,.0 bn",
_CurrentValue <= 1E12, ",,,,. bn",
_CurrentValue <= 1E13, ",,,,.00 tn",
_CurrentValue <= 1E14, ",,,,,.0 tn",
_CurrentValue <= 1E15, ",,,,,. tn"
)
RETURN
_Format
Parameters
| Parameter | Type | Description |
|---|---|---|
base_format |
STRING | Base format string (e.g., "#,##0") |
format_value |
EXPR | Value to format and evaluate for unit scaling |
Example
DaxLib.FormatString.Component.DynamicUnits ( "#,##0", SELECTEDMEASURE() )
Use this function to create dynamic scaling format strings based on value magnitude.
Related Functions
- DynamicUnits - Main dynamic units format function
- Basic.FileSize - File size formatting with similar scaling