Power BI 2023 retrospective: Keep measures numeric with dynamic format strings
Revisit the April 2023 dynamic format feature with a DAX pilot that keeps revenue, count and conversion values numeric while giving each an appropriate display.
Archive retrospective · Topic year 2023
In this article
What changed in the April 2023 preview
Power BI Desktop introduced dynamic format strings for measures in its April 2023 preview. The feature lets a report change how a number is displayed without converting the numeric measure into text. A card might show revenue, an order count, or a conversion rate as the reader changes a selection. Those quantities use different display conventions. A chart can still consume the result as a number. DAX FORMAT returns formatted text. It can be appropriate for a heading or a sentence, where text is expected, but a numeric chart field has different requirements. This example separates the expression that computes the value from the expression that returns a display format. Keeping those responsibilities visible lets a report author distinguish an incorrect calculation from a formatting mistake.
Create a small model with two regions
Create PilotPerformance and MetricChoice as two tables in a blank Desktop report. PilotPerformance contains revenue, visits and orders for North and South. For this exercise an order counts as a conversion. In a production model, the definition should state whether conversion is measured by visitor, session, order, or another event. The source data here already contains net revenue in one currency. Leave MetricChoice disconnected. It supplies the metric name, without filtering individual performance rows itself. Use its Metric column in a single-selection slicer. If you want a region filter, create that slicer from PilotPerformance. The selected region changes which rows are included. The selected metric changes which calculation the measure uses. With no region filter, total revenue is 2,000, orders total five and visits total 40.
PilotPerformance =
DATATABLE (
"Region", STRING, "NetRevenue", INTEGER,
"Visits", INTEGER, "Orders", INTEGER,
{
{ "North", 1200, 10, 2 },
{ "South", 800, 30, 3 }
}
)
// Create this as a separate table with no relationship.
MetricChoice =
DATATABLE ( "Metric", STRING, { { "Revenue" }, { "Orders" }, { "Conversion" } } )
Give the measure a value expression and a format expression
Create Pilot Metric as a measure before setting its format to Dynamic. The value expression reads the one selected metric. It then returns net revenue, total orders or orders divided by visits. DIVIDE returns blank for a zero denominator by default. The measure also returns blank when its metric is ambiguous. Those decisions keep an unknown value visually separate from a genuine zero. Switch to the separate format expression field and enter the second expression. The revenue mask includes a literal EUR prefix and two decimal places. The order mask uses whole numbers and the conversion mask displays a percentage with one decimal place. Doubled quotation marks inside a DAX string preserve the quotes around literal text in the returned mask. The exact separator glyphs in the visual may follow the report locale.
// Measure expression
Pilot Metric =
SWITCH (
SELECTEDVALUE ( MetricChoice[Metric] ),
"Revenue", SUM ( PilotPerformance[NetRevenue] ),
"Orders", SUM ( PilotPerformance[Orders] ),
"Conversion",
DIVIDE ( SUM ( PilotPerformance[Orders] ), SUM ( PilotPerformance[Visits] ) ),
BLANK ()
)
// Separate dynamic format expression on the same measure
SWITCH (
SELECTEDVALUE ( MetricChoice[Metric] ),
"Revenue", """EUR ""#,0.00",
"Orders", "#,0",
"Conversion", "0.0%",
"#,0.00"
)
Check the weighted total against the two regions
With both regions included, Revenue should return the number 2,000 and Orders should return five. Conversion uses five divided by 40, which yields the fraction 0.125 and displays as 12.5 percent. North on its own has a 20 percent rate from two orders and ten visits. South has a ten percent rate from three orders and 30 visits. Averaging the two displayed percentages gives 15 percent, which is not the correct combined rate for these observations. Try all three metric choices in the card and, separately, in a visual that requires a numeric value. A formatted caption alone is insufficient to show that the model keeps the value numeric. Also change the region filter and confirm the expected fraction before depending on the percentage shown in a report.
Choose a consistent unit for each visual
This pilot gives its reader one metric at a time. Putting currency and a percentage on the same numeric axis can be hard to interpret, even though both are numbers. If simultaneous comparison is required, keep units and scales clearly identified. Assigning a currency format also performs no conversion. Amounts must be converted according to the model’s currency rules before applying a shared display label. Test what happens if the slicer is cleared, more than one metric reaches the filter context, or a saved bookmark is opened. SELECTEDVALUE supplies no unique name in those ambiguous states, and the example returns blank. Give the visual an accessible title or explanation that reflects the selected metric where possible. Readers should be able to tell which unit is in use without relying on a colored symbol.
Review which format ultimately appears
If the visual displays a different result from the expected format, inspect the selected metric and the two expressions separately. Then check visual overrides and display units. Model, visual and element settings can affect the final number presentation. An automatic display-unit abbreviation can be useful in a production chart, but it may hide what is being checked in this simple exercise. Use an explicit scale while you validate the fixture. The release archive establishes the April 2023 origin, while the current Microsoft Learn article documents the workflow and its limitations. Keep the selected metric, expected numeric result and expected display unit in your report test notes. That makes it possible to repeat the check after a measure, page or visual setting changes.
Reader discussion
What measurements drive your choice between Import and DirectQuery?
No comments yet. Be the first to contribute.
Write a comment