Custom Data format strings in Power BI

With custom data format strings in Power BI Desktop, we can customize how fields appear in visuals and make sure our reports look just the way we want them to.

Let’s we have the following Countries table.

Publish report to Power BI service

Step 1: Format strings exist on three levels: • Model: We can set a format string for fields in the model or use a dynamic format string to format our measure. Anywhere we use that field the format string is applied, unless overridden by a visual or element level format string.

• Visual: We can set format strings on any column, measure, or visual calculation that is on our visual, even if they already had a format string. In that case the model level format string is overridden, and the visual level format string is used. If we change the aggregation on a field, which invalidates a previously set visual level format string, the format string is removed. Visual level format strings for fields are persisted for fields, but not for visual calculations. If we set a visual level format string on a field and then remove and readd that field to the same visual, the visual level format string is reinstated. In contrast, for a visual calculation, the format string isn't reinstated.

To add a visual level format string To create a visual level format string, first add the field or visual calculation to our visual. Then, with our visual selected, open the format pane and go to the General section of the format pane. Find the Format data settings and configure the format string there:

Publish report to Power BI service

Let’s apply the format code #,##0,,, Bn. This will format the values how it presents in the visual as shown in the image below:

Publish report to Power BI service

• Element: We can set a format string for data labels and for specific elements of the new card and the new slicer visuals. Any format string we set here overrides the format string set on the visual and model level.