Power BI custom visual dynamic format API

From API version 4.2, developers can create reports with dynamic string formats support.

Enable the dynamic format support for visual

To allow the visual to operate with dynamic format strings, the following fields should be added in the capabilitites.json:

"objects": {
    "general": {
        "properties": {
            "formatString": {
                "type": {
                    "formatting": {
                        "formatString": true
                    }
                }
            }
        }
    },
}

How to use the dynamic string format

When dynamic string format is enabled, the custom visual receives format strings through the update() options as shown in the screenshot.

Screenshot of update options content with dynamic format strings.

There are two arrays inside of options.dataViews[0].categorical.values[0]:

  1. values - values from the dataset
  2. objects - objects with general.formatString property

Each object corresponds to a value. As an example value 12519995905.9842 from the screenshot has the format ¥ #,0. To apply this format to the value, you can use the format method from powerbi-visuals-utils-formattingutils.