DynamicCurrency
Get currency format string based on currency code with appropriate symbol placement and decimal places.
Syntax
DaxLib.FormatString.DynamicCurrency ( currency_code, decimal_places )
Definition
DAX
// Get currency format string based on currency code
// Returns appropriate number format with currency symbol placement
(
// Currency code (ISO 4217 three-letter code)
// Examples: CAD, EUR, GBP, JPY, etc.
// Expects a column reference used for selecting a currency in the report, like 'Exchange Rate'[Currency Code]
currency_code: ANYREF,
// Base format string
// Recommended: "#,##0"
decimal_places: INT64
)
=>
VAR _BaseFormat =
DaxLib.FormatString.Component.DecimalPlaces( "#,##0", decimal_places )
VAR _CurrencyPosition =
DaxLib.FormatString.Component.GetCurrencyPosition ( currency_code )
VAR _CurrencySymbol =
DaxLib.FormatString.Component.GetCurrencySymbol ( currency_code )
VAR _Prefix =
IF ( _CurrencyPosition = "PREFIX", _CurrencySymbol & " ", "" )
VAR _Suffix =
IF ( _CurrencyPosition = "SUFFIX", " " & _CurrencySymbol, "" )
VAR _Format =
_Prefix & _BaseFormat & _Suffix
RETURN
_Format
Parameters
| Parameter | Type | Description |
|---|---|---|
currency_code |
REFERENCE | ISO 4217 three-letter currency code (e.g., "USD", "EUR") |
decimal_places |
NUMBER | Number of decimal places |
Example
DaxLib.FormatString.DynamicCurrency ( SELECTEDVALUE( 'Currency'[Code] ), 2 )
Use this function in a measure's formatStringDefinition to create dynamic currency formatting based on selected currency.
Related Functions
- Component.GetCurrencyFormat - Core currency formatting
- Component.GetCurrencySymbol - Get currency symbol
- Component.CurrencyTable - Currency reference table
- Component.DecimalPlaces - Decimal places formatting