Sub topic 12
Dynamic button text and destinations with DAX
This chapter shows how to drive a button's text and its page navigation destination from DAX measures. It assumes you can write basic DAX measures, build a button with a Bookmark or Page navigation action, and use slicers. If you have not yet built a button action, review the chapters on buttons and button actions first.
Why make a button dynamic
A static button always says the same thing and always does the same thing. That is fine for "Back" or "Reset". It breaks down in two situations:
- The label should reflect the report's current state. A button that says "Clear filter" when nothing is filtered misleads the reader.
- The destination should depend on a choice. Two buttons that look the same but lead to different pages clutter the canvas.
Power BI handles both cases with conditional formatting. Instead of typing a fixed value, you bind a property to a field or a measure. The property is then evaluated for the current filter context each time the report renders.
How conditional formatting reaches a button
Select a button and open the Format pane. Properties that accept a measure show an fx icon next to them. Selecting fx opens a dialog where you set Format style to Field value and choose a measure. The measure must return a value of the type the property expects, usually text.
Two properties matter in this chapter:
| Property | Where to find it | What the measure must return |
|---|---|---|
| Button text | Style > Text > Text (fx) | Any text string |
| Page navigation destination | Action > Type = Page navigation > Destination (fx) | The exact name of a report page |
The next diagram shows the evaluation path from the user's selection to what the button shows or does.
Dynamic button text
The first example shows the current category selection on the button itself, and falls back to a default when nothing is filtered.
Button Label =
IF (
ISFILTERED ( Product[Category] ),
"Clear filter: " & SELECTEDVALUE ( Product[Category], "Multiple" ),
"All categories"
)Each function plays a distinct role:
ISFILTERED ( Product[Category] )returns TRUE when a filter is applied directly to that column. It tells the measure whether to show the "Clear filter" wording.SELECTEDVALUE ( Product[Category], "Multiple" )returns the single selected category. If more than one category is selected, or none is, it returns the second argument, here "Multiple".- The
&operator joins text.
To use the measure, select the button, open Style, expand Text, choose fx next to Text, set the format style to Field value, and pick Button Label.
Edge cases for the text measure
- Nothing selected.
ISFILTEREDis FALSE, so the button reads "All categories". The measure never reachesSELECTEDVALUE. - Several selected.
ISFILTEREDis TRUE andSELECTEDVALUEreturns "Multiple", so the button reads "Clear filter: Multiple". - Filter from another source.
ISFILTEREDchecks only filters on that column. If a different table filters Product indirectly, useISCROSSFILTEREDinstead. It returns TRUE when the column is filtered directly or through a relationship. - Long text. The button does not grow to fit. Long labels get clipped or wrapped depending on the button's size and text settings. Test with your longest category name.
A button label on its own does not clear anything. Pair the label with an action such as Clear all slicers, covered in the earlier chapter on assigning button actions. The label describes, and the action does.
Dynamic page navigation destination
A page navigation button normally points to one fixed page. With conditional formatting, the destination can come from a measure that returns a page name.
The setup uses a small disconnected table. Disconnected means it has no relationship to any other table, so it filters nothing. It exists only to hold the choices for a slicer. Create it with Enter data or with DAX:
View = DATATABLE (
"Level", STRING,
{ { "Summary" }, { "Detail" } }
)Add a slicer on 'View'[Level]. Then create the measure:
Target Page =
IF (
SELECTEDVALUE ( 'View'[Level] ) = "Detail",
"Detail",
"Summary"
)This measure assumes your report has pages named exactly Detail and Summary. The measure returns "Detail" when the slicer has Detail selected. In every other case, including no selection and multiple selections, it returns "Summary". That default is deliberate: the button always has a valid destination.
To wire it up:
- Select the button.
- In Format, open Action and turn it on.
- Set Type to Page navigation.
- Next to Destination, select fx.
- Set Format style to Field value and choose
Target Page.
What to check when the destination fails
The destination measure must return the page's display name, character for character. Common causes of a dead button:
- A page was renamed but the measure still returns the old name.
- The name has a trailing space or different capitalization.
- The measure returns BLANK. Add a fallback branch, as the example does.
- The page is hidden. Hidden pages can still be navigation targets, but confirm this in your own report before you rely on it.
A safer way to avoid typos is to define page names once in a table and read them from there, so a rename happens in one place.
Keep the label and the destination consistent
A button whose text says one thing and whose destination does another is a usability defect. If both come from the same slicer, build both measures from the same condition. Here is a label that matches the Target Page measure:
Navigate Label =
IF (
SELECTEDVALUE ( 'View'[Level] ) = "Detail",
"Go to Detail page",
"Go to Summary page"
)Because both measures test the same expression, the label and the destination change together.
Limits and gotchas
- Measures only, not columns for per-row logic. The button sits on the report canvas, not in a table row, so it needs a measure that evaluates in the report's filter context. A calculated column will not do this.
- Bookmarks interact with the slicer. If a bookmark captures the Data option, applying it resets the slicer and therefore the measure's output. If it does not capture Data, the slicer keeps its current value. Decide which behavior you want and check it. The earlier chapter on capture options explains the settings.
- Not every property supports fx. If you do not see the fx icon, the property is static in your version of Power BI Desktop.
- Service behavior. Dynamic text and destinations are evaluated in the Power BI service as well. Test there, because a published report can differ from Desktop in how slicer state is restored.
- Accessibility. Screen readers read the button's alternative text, not its dynamic label. Set Alt text in General to something that stays accurate, or bind it with fx as well.
Testing checklist
- Test with no slicer selection, one selection, and multiple selections.
- Click the button in each state and confirm it lands on the intended page.
- Rename a page and confirm the measure still matches.
- Apply any bookmarks that touch the slicer and re-check the label.
- Publish and repeat in the Power BI service.
Exercises
Exercise
A button uses the measure Button Label, and a user selects both "Bikes" and "Helmets" in the Category slicer. What text does the button show, and why?
Show answer
It shows "Clear filter: Multiple". ISFILTERED returns TRUE because the column is filtered. SELECTEDVALUE finds more than one value, so it returns its second argument, "Multiple".
Exercise
A dynamic page navigation button stops working after someone renames the page "Detail" to "Details". What is the cause and how do you fix it?
Show answer
The Target Page measure still returns the string "Detail", which no longer matches a page name. Update the string in the measure to "Details", or store page names in one table so the rename is made in a single place.
Exercise
Why does the Target Page measure return "Summary" in every case except when "Detail" is selected, instead of returning BLANK when nothing is selected?
Show answer
A BLANK result gives the navigation action no valid destination, so the button would do nothing. Returning "Summary" as the default guarantees the button always has a destination.