However, the customer was very clear – they don’t want the icons to appear when there isn’t the detail available to view. Currently in Power BI there isn’t a native way to make an icon be visible or hidden based on data.
Whilst it’s not a perfect work around, the technique described here describes how to make a bookmark show or not show depending on the data. In the example shown in the video below, there is information about customers – sales and orders. All of the customers have sales data, but not all have order information. There is a Power BI button that navigates to an order detail page using bookmarks. We don’t want the button to show if there is no order information.
We achieve this by using an image for the icon and put a blank button on top. The URL for the icon is a DAX measure, which checks to see if there is order information present. If there is it returns the URL of the image, and if not, returns an empty string. It’s not perfect, as the button still works, even if the icon is not showing, but hopefully it will deter most people from clicking.
We couldn’t put a blank image over a Power BI button to hide or show it, as the z-index would prevent the button being triggered ever – the image visual would be on top of the button.
I’m hoping that once expression based formatting is available, it will be possible to achieve this without needing a workaround, but if not it might be possible to improve the workaround.
Here are the steps to implement the workaround:
- Create bookmark on the detail page
- Create a measure using DAX to return the image URL:
for this example –
Icon = IF (COUNTROWS(Orders) > 0, "https://<imageurl>", "")
- On the summary page, add the image. I used the Image by Cloudscope custom visual. Use the new Icon measure we created in the Image URL field.
- Add a button and place it on top of the image. In the formatting options, set the Action Type to Bookmark and select the bookmark you created in step 1.
Turn off Border to hide the box surrounding the button.
Also I feel I need to credit David Elderveld, as I’ve just discovered his blog post here on a very similar technique for using data driven images.