Forum Discussion
Dynamic URL based on slicer selection
Hi AndyDD_UK ,
Yes, you can make the URL dynamic based on the slicer selections in Power BI. To achieve this, you need to construct the URL dynamically using DAX expressions that concatenate the slicer values (like year, month, and country) to the base URL.
Dynamic URL =
VAR SelectedYear = SELECTEDVALUE('Dim Calendar'[Year], "2023") -- Default to "2023" if no selection is made
VAR SelectedMonth = SELECTEDVALUE('Dim Calendar'[CalendarMonth], "01") -- Default to "01" if no selection is made
VAR SelectedCountry = SELECTEDVALUE('Dim Country'[Country], "USA") -- Default to "USA" if no selection is made
VAR BaseURL = SELECTEDVALUE('Dim Item'[URL], "") -- URL from the Dim Item table
RETURN
IF(
BaseURL <> "",
BaseURL & "?year=" & SelectedYear & "&month=" & SelectedMonth & "&country=" & SelectedCountry,
BLANK()
)
Now, in your matrix or table visual, you can add this measure to the column where you want the dynamic URL to appear.
To make this a clickable link:
- Go to the Format pane.
- Enable URL icon (or the “Web URL” under cell element option), depending on the visual.
- Set the URL field to the Dynamic URL measure.
Now, when users click on the URL icon, the correct report will open with the country, year, and month values passed as query parameters.
Example URL Output:
If the URL in 'Dim Item'[URL] is http//:example.com and slicer selection are:
- Year: 2023
- Month: 01
Country: USA
The final dynamic URL will look like:
https://example.com/report?year=2023&month=01&country=USA
This will pass the slicer values to the linked report.
Please accept this as solution if it helps you. Appreciate Kudos.
Thanks for this. Can't get it work though...
I created the measure but it's not possible to add it as a column or row in the matrix.
Also, I cannot get the Cell elements Web URL to pick up on the measure.
Are you able to advise next steps ?