Sub topic 13
Setting Data Type and Format for Results
This chapter assumes you can create a visual calculation in the calculation editing experience. It also assumes you know the basics of DAX measures and of formatting fields in Power BI Desktop. Here you will learn how to control how a visual calculation's result is typed and displayed.
Why the result needs formatting
A visual calculation returns a value, and Power BI picks a default data type and format for it. The default is often wrong for your purpose. A share of total such as DIVIDE([Sales Amount], COLLAPSEALL([Sales Amount], ROWS)) returns a decimal like 0.2371. Without a format, the visual shows that raw number instead of a percentage.
Formatting changes only how a value is displayed. It does not change the value. A percent-formatted cell still holds 0.2371, and any later calculation that refers to it uses that number.
Where the settings live
You set the format in the calculation editing experience, not in the model. Visual calculations are not part of the model, so the Model view and the Column tools ribbon do not apply to them.
- Select the visual and choose New calculation to open the editing experience.
- Write or select the visual calculation.
- Use the Data type and Format controls for that calculation.
- Pick a data type (for example, decimal number or whole number), then a format (for example, percentage).
- Set the number of decimal places if the format offers it.
You can also select the calculation field in the visual's field list and adjust the format from there.
A worked example
Suppose a matrix shows Category on rows and Sales Amount as a value. You add this calculation:
Percent of grand total = DIVIDE([Sales Amount], COLLAPSEALL([Sales Amount], ROWS))The cell for a category with 2,371 in sales, out of a total of 10,000, shows 0.2371. To fix the display:
- Set the format to Percentage.
- Set the decimal places to 1.
The cell now reads 23.7%. Doing the same for a running sum is a different choice:
Running sum = RUNNINGSUM([Sales Amount])This result is a currency amount, so use a currency or fixed-decimal format with the same number of decimals as Sales Amount.
Choosing a data type
The data type affects how the result is displayed and which formats are offered. A short guide:
| Calculation | Typical result | Suggested format |
|---|---|---|
| `RUNNINGSUM([Sales Amount])` | Amount | Currency, matching the source measure |
| `MOVINGAVERAGE([Sales Amount], 3)` | Decimal amount | Currency or decimal, 2 places |
| `[Sales Amount] - PREVIOUS([Sales Amount])` | Signed amount | Currency or decimal, negatives visible |
| `DIVIDE([Sales Amount], COLLAPSE([Sales Amount], ROWS))` | Fraction | Percentage, 1 place |
A moving average can produce fractions of a currency unit even when the source values are whole numbers. If you format it as a whole number, the display rounds, which can make neighboring cells look equal when they are not.
Common errors
- Percentages shown as decimals. The calculation is correct. The format is still general. Set it to Percentage.
- Multiplying by 100 and then formatting as a percent. This shows
2371%instead of23.7%. Leave the value as a fraction and let the format do the scaling. - Mismatched decimals. The source measure shows two decimals and the calculation shows none. Set both to the same precision so columns look consistent.
- Expecting the format to carry over. A visual calculation does not always inherit the format of the measure it uses. Check each new calculation.
Exercise
A visual calculation DIVIDE([Sales Amount], COLLAPSE([Sales Amount], ROWS)) displays 0.18 in a cell. You want the cell to show 18.0%. What do you change, and what do you not change in the DAX?
Show answer
Set the calculation's format to Percentage with 1 decimal place in the calculation editing experience. Do not multiply the DAX result by 100. The value stays 0.18, and the percentage format scales it for display.
Exercise
A three-row moving average of whole-number sales shows identical values in adjacent cells after you format it as a whole number. Why might this happen, and how do you check it?
Show answer
The moving average can be fractional, and the whole-number format rounds it for display, so different values can look the same. Change the format to a decimal with two places and compare the cells.