Creating dynamic titles for charts in Power BI adds polish to any report. Whilst some situations call only for a simple change, scenarios involving multiple parameters or filters require a flexible approach. For example, a chart looking at “Profit by Category – Last 3 Months” may have a field parameter for the measure being visualised and a numeric parameter for the number of months. This blog will demonstrate how to approach this tricky issue.

 

Set Up

As a starting point, let’s overview what we have and what we’re trying to do:

  • We have a simple numeric range parameter (controls the number of months our calculations look back – see image below).
  • We have a field parameter with the measures we wish to visualise.
  • We have a chart which uses the field parameter (along with the slicers on our page to affect what is being shown).

This measure allows a numeric range parameter to filter the number of months considered in the calculation.

We can see that Power BI automatically adjusts the chart’s title based on the selected measure. However, it doesn’t make any changes for the number of months. So we’re going to construct a new measure to adjust the chart’s title based on both of these parameters. If you require assistance setting up field parameters and numeric ranges, check out this video.

Dynamic Title Measure

There are many ways to approach this, so I’ll demonstrate a method that offers flexibility:

1. Go to your measures table and select New Measure.

2. Write the following DAX, replacing the measures and months parameter to correctly reference the parameters in your data model (this will be explained in the next section).

Dynamic Title (category bar chart) =
VAR FilterParam = MAX(‘Measures Parameter'[Measures Parameter])
VAR MonthParam = SELECTEDVALUE(‘Months Parameter'[Months Parameter])
RETURN
IF(
    MonthParam = 1,
    FilterParam & ” by Category – Last Month” ,
    FilterParam & ” by Category – Last ” & MonthParam & ” Months”
)

3. Select your chart, go to format your visual, then General, and turn off Title.

 

4. Now, go to Insert, and bring on a text box just above your chart. Resize as needed.

 

5. Click into your text box, in the options that appear click + Value, and start typing your dynamic title measure into the field under ‘How would you calculate this value‘. A preview should appear under Result. If the preview is blank or shows an error symbol, the dynamic title measure needs fixing.

 

6. As demonstrated in the video above, test your new title by changing the parameters in your report. Notice the word “months” in the title drops the letter s when the parameter is set to 1. These small details instill a sense of professionalism in your report.

 

Why does the dynamic title measure work?

Power BI at times can feel temperamental with how DAX works. However, there is logic behind every error… as frustrating as it can be. The main point I’ll focus on here is why MAX was used for the field/measures parameter instead of SELECTEDVALUE which was used for the numeric range parameter. Ultimately, the answer comes down to the nature of field parameters and numeric fields in Power BI.

‘Months Parameter'[Months Parameter Value] is a single-value numeric field selected from a slicer. Since only one value is selected at a time, SELECTEDVALUE will simply return the chosen value. Selecting multiple values would simply result in a BLANK, but that’s fine since we’re forcing a single selection in our report.

‘Measures Parameter'[Measures Parameter] is a field parameter for measures, meaning it’s not a normal column but instead acts as a switch between different measures. Instead of returning a single value, field parameters reference measures, functioning more like metadata than a numeric or text column. Therefore, SELECTEDVALUE won’t work as expected on field parameters. Admittedly, I am not overly sure of the logic as to why MAX works here instead, but what’s important to know is that MAX seems to extract the selected measure name from the parameter table, creating a nifty work-around to the previous issue.

Thank you for reading! Hopefully you got some useful tips. If you’d like to read more, please visit my page for more content on Power BI, Tableau, and other analytic tools.

 

Kyle Stanford
Author: Kyle Stanford