- April 25, 2019
- Posted by: Siva Mani
- Category: Power BI
At times, you get requirements like, to set a dynamic title based on a slicer/filter selection or demand to transfer the selection as a URL parameter. This blog will serve you to set dynamic titles for visuals.
There are several alternatives to accomplish this requirement using a measure and a Card visual. In this case, you have to disable the title in the visual supposedly to show dynamic title and add a card visual with the measure to display the title. It requires attention on the formatting side such as font size, family, color and placing the title. It will be bit tricky to manage, plus, a time-consuming exercise.
Here is an alternate method for solving the same requirement without adding another visual to display the dynamic title.
Power BI released this interesting feature with Power BI desktop April 2019 update:
Conditional Formatting for visual titles
With this new feature, you can now set dynamic titles for visuals without adding a Card. Here’s a simple example, with steps, to create a dynamic visual title:
I will be using a slicer with Cities for this example.
Step 1: Creating a measure to display selected City names. Here is the DAX calculation,
List of City values =
VAR __DISTINCT_VALUES_COUNT =
DISTINCTCOUNT ( ‘STORE'[City] )
VAR __MAX_VALUES_COUNT =
CALCULATE ( DISTINCTCOUNT ( STORE[City] ), ALL ( STORE[City] ) )
VAR __MAX_VALUES_TO_SHOW = 3
VAR __SELECTED_COUNTRY_NAMES =
IF (
__DISTINCT_VALUES_COUNT > __MAX_VALUES_TO_SHOW,
CONCATENATE (
CONCATENATEX (
TOPN ( __MAX_VALUES_TO_SHOW, VALUES ( ‘STORE'[City] ), ‘STORE'[City], ASC ),
‘STORE'[City],
“, “,
‘STORE'[City], ASC
),
“, and More…”
),
CONCATENATEX (
VALUES ( ‘STORE'[City] ),
‘STORE'[City],
“, “,
‘STORE'[City], ASC
)
)
RETURN
IF (
__MAX_VALUES_COUNT = __DISTINCT_VALUES_COUNT,
“Sales by City”,
“Sales by “ & __SELECTED_COUNTRY_NAMES
)
The above DAX measure performs the following functions,
- If no Cities were selected, it will display “Sales by City”
- If 3 or less than 3 Cities were selected, it will display “Sales by <City1, City2, City3>”
- If more than 3 Cities were selected, it will display “Sales by <City1, City2, City3>, and more…”
Step 2: Launching the conditional formatting dialog – Go to Format (Visual Property pane) -> Title -> Right click on the “Title Text” area
Select “Conditional Formatting” to launch the conditional formatting dialog.
Step 3: Adding the measure in Condition formatting
Select the measure in Based on field drop-down menu.
Click OK.
Refer the below gif,
With the above steps, you can set the dynamic titles for visuals. At some cases, you will not be able to view all the selected values, when you have a drop-down slicer or a list slicer with many values.
Please feel free to reach Cittabase for more information. Visit our blogs for more topics on Power BI.
2 Comments
Comments are closed.
Hi Siva, how can we acheive same for Hierarchy Slicer ?
@disqusKumar:disqus, The specified steps in the blog are applicable for Hierarchy Slicer as well. Please do give a try and post your queries here if you need assistance.