Power BI Blog: Dynamic Headings Based on Slicer Selection
17 October 2019
Welcome back to this week’s Power BI blog series. This week, we’re going to look at how to create dynamic headings that change depending on slicer selections.
We are going to work with the following dataset that contains the list of all of the branches in our hypothetical report:
In this case, each city in the table represents a branch.
We are going to create a dynamic title using the: IF, ISFILTERED, and FIRSTNONBLANK functions. We will create the following measure called ‘Page Title’:
Page Title =
IF(
ISFILTERED(Branches[City]),
FIRSTNONBLANK(Branches[City],1),
"No Branch Selected"
)
The condition in the IF function checks if there is a filter on the City column, if the City column is filtered then return with the name of the city, otherwise return with “No Branch Selected”.
The next step is to create a Card visualisation:
Drag our Page Title measure into the Card visualisation:
Now if we select a city on the slicer the card will display the corresponding city that is currently filtered.
You may be thinking, we can achieve the same effect by dragging the City field into the Card visualisation (right card):
That’s true, but with the measure we can make the card (on the left) more readable and user-friendly:
Page Title =
IF(
ISFILTERED(Branches[City]),
“Selected Branch: ” & FIRSTNONBLANK(Branches[City],1),
"No Branch Selected"
)
With the modification above the Cards now look like this:
One more benefit of having a measure displaying the current selection, is that when no selection is made the IF function picks it up and tells us that there is currently no selection/filter applied (left card). Contrast this to the City card (right card), which just shows the first city in the column:
There we have it, how to create a user-friendly and dynamic page title using measures.
That’s it for this week! Check back in seven days for more Power BI tips.
In the meantime, please remember we offer training in Power BI which you can find out more about here. If you wish to catch up on past articles, you can find all of our past Power BI blogs here.