Sub topic 12
Dynamic button text and destinations with DAX
This chapter assumes you can create buttons, assign actions, and write basic DAX measures in Power BI Desktop. It builds on the earlier chapters on button actions and button states.
Why make a button dynamic
A button's text and its action are usually fixed. That works for a "Show filters" toggle, but it falls short when the button should react to the report's state. A single button can show the current selection, or lead to a different page depending on what the user chose.
Power BI supports this through conditional formatting. Properties that show an fx option can be driven by a DAX measure. The measure is evaluated in the current filter context, so its result changes as slicers change.
Dynamic button text
Select the button, open Format button, expand Style, turn on Text, and choose fx next to the text field. Set Format style to Field value and pick a measure that returns text.
This measure shows the current category, or a default label when nothing is filtered:
Button Label =
IF (
ISFILTERED ( Product[Category] ),
"Clear filter: " & SELECTEDVALUE ( Product[Category], "Multiple" ),
"All categories"
)The measure works in three steps:
ISFILTEREDchecks whether anything filtersProduct[Category].- If so,
SELECTEDVALUEreturns the single selected category. It returns"Multiple"when more than one is selected. - If not, the button reads "All categories".
Dynamic destinations
A page navigation button can also take its destination from a measure. Select the button, set Action to Page navigation, and choose fx next to Destination. The field you pick must return the exact name of a report page.
This measure assumes a disconnected 'View' table with a Level column, and report pages named Detail and Summary:
Target Page =
IF (
SELECTEDVALUE ( 'View'[Level] ) = "Detail",
"Detail",
"Summary"
)A user picks a level in a slicer on 'View'[Level]. The same button then leads to Detail or Summary. Because the table is disconnected, the slicer doesn't filter other visuals. It only supplies a value for the measure to read.
Common errors
| Symptom | Likely cause |
|---|---|
| Button text is blank | The measure returns blank, or the format style isn't set to **Field value**. |
| Navigation does nothing | The returned text doesn't exactly match a page's display name. Check spelling and spaces. |
| Label always says "Multiple" | Several values are selected, or the measure reads a column with several rows in context. |
| Destination never changes | The slicer sits on a connected table, or no value is selected, so `SELECTEDVALUE` returns blank. |
Rename a page and you break the destination measure. The measure holds the page name as plain text, so Power BI can't update it for you.
Dynamic or bookmark-based?
Bookmarks and dynamic buttons solve different problems. Use a bookmark to restore a fixed arrangement of visuals, such as a hidden panel. Use a dynamic measure when the answer depends on data or a selection. You can combine them: a bookmark button handles the panel, and a measure keeps its label current.
Exercise
A page navigation button uses the measure Target Page to choose its destination. After you rename the page "Summary" to "Overview", the button stops working when 'View'[Level] isn't "Detail". What is wrong, and how do you fix it?
Show answer
The measure still returns the text "Summary", which no longer matches any page name. Edit the measure so it returns "Overview" in the second branch of the IF.
Exercise
Write a measure that shows "Region: West" when only West is selected in Sales[Region], and "All regions" otherwise.
Show answer
Region Label = IF ( ISFILTERED ( Sales[Region] ), "Region: " & SELECTEDVALUE ( Sales[Region], "Multiple" ), "All regions" ). Assign it to the button text through fx and Field value.