Show or Hide a Power BI Visual Based on Selection - Excelerator BI

Show or Hide a Power BI Visual Based on Selection

Edit: 17 Jan 2020 – New Content by Jason Cockington
Interact with the Hidden Visual
– Check Filtered Measure
– Filter Matrix to Render Blank

 

I have written a few articles in the past that toy with the ideas of changing visibility and text colour based on selection.  I started to wonder if it was possible to make a visual appear (or not) based on a selection from the user.  There is no out of the box way to do that today. It is possible to use bookmarks to show and hide an object, but the user must click a specific button to do this. I want the user to be able to interact with a report and see (or not see) a chart based on some valid selection across the report.  Microsoft is already working on building expression based formatting across the breadth of Power BI however as of now the only item you can change is the header in a chart and more recently the background in a card.

Solution Overview

My solution to solve this problem involves.

  • Create a card to work as a mask for the visual.
  • Create a measure to display a user message on the card based on the user selection.
  • Create a measure to render the visual blank when nothing is selected
  • Write a measure that returns either the background colour or “transparent” based on the user selection, and set that to conditionally format the background colour of the card.

Requirement

I have a sample report below.  I want the matrix on the left to appear if the user selects an item in the category slicer on the right.  If there is nothing selected in the slicer, I don’t want to see the matrix at all, but instead see some instructions on what to do.

Hidden Visual Live Connection

Transparent Colours

The key to this solution is the expression based formatting of colours using DAX.  As I described in my article about conditional based text colours linked above, you can set the result of a measure as being any HEX colour you want using conditional colour formatting.  But as it turns out, you can change the transparency of a HEX colour like #FFFFFF by adding an optional additional 2 characters to the end (00 being 100% transparent).  So while #FFFFFF is white, #FFFFFF00 is 100% transparent (white).

The next trick was to have a box that I could colour white or transparent – enter the Card.

Create the User Instructions

The first thing I had to do was to create a measure that displayed a message to the user on the card.  I wanted to show the matrix when the user had selected an item in the Product[Category] slicer and display the message otherwise. This was easy as follows.

Message = 
   IF(
      ISFILTERED(Products[Category]),
      "",
      "You must first select a Product Category from the slicer to see the results"
   )

Write the Check Filtered Measure

The next thing I needed to do was write a measure that would make the matrix appear blank when no selection in the slicer had been made.

Check Filtered = 
   IF(
      ISFILTERED(Products[Category]),
      1,
      0
   )

Filter the Matrix to Render Blank

Select the matrix, and place the [Check Filtered] measure onto the “Filters on this visual”, and set the “Show items when the value: is 1”.  This renders the matrix with just 2 rows visible.  This means there is no need to cover the entire matrix with the card layer, we can just cover over the top two rows, to achieve the same visual effect. This is important as it means that the visual will render larger than the card when displaying information, which will enable click interactivity with the displayed cells for further cross-filtering the report.

Check Filtered

Blank Matrix

Create a Card to Work as a Mask

Next, I placed a card visual with the measures [Message] placed in the  “Values” section.  I made the card just big enough to cover the blank visual (top 2 rows). I turned off the card category label. Now the trick is to use conditional formatting for the card background colour using rule based expressions.

Power BI Online Training

Write the Transparent Measure

This was also pretty easy.  I wanted to show the matrix when the user had selected an item in the Product[Category] slicer and hide the matrix otherwise.  The measure I wrote therefore was this.

Make Transparent = 
      IF(
         ISFILTERED(Products[Category]),
         "#FFFFFF00",
         "White"
      )

In other words, if there is a value selected in the slicer, make the “colour” transparent, otherwise make it white (the colour of the report background) so that it hides the matrix.

Format the Card

Then I applied the measure to format the card background colour.  To do this, click on the Card, then select format\Background and switch it on. Then click on the ellipses on the right-side of Color as shown below.

Cond Formatting Card Background

Click on Conditional formatting, Select Format by as “field value” and then select the measure.

Cond Formatting Card Background 2

Importantly, the order of the visuals (front to back) needs to be:

  1. The card
  2. The visual to show/hide.

The Final Result

And here is the final result.

Hidden Visual Live Connection

You can download my sample workbook here.

85 thoughts on “Show or Hide a Power BI Visual Based on Selection”

  1. Hello, your solution looks great! and it’s exactly what I need, however I can’t use “checkfiltered” measure as a filter on my card (or any) visualization, would you have any idea why?

    Thank you!

    1. Jason Cockington

      Hi Rita,
      You can’t use the “CheckFiltered” measure on a card because a card only displays a single value, and thus can’t be filtered.
      The “Message” measure goes onto the card, and the card background is formatted with the “Make Transparent” measure.
      The “CheckFiltered” measure goes onto the chart/matrix you wish to hide.
      Hope this helps.

  2. It’s all clever stuff…….but the key thing I think when reading this (as someone who uses Power BI, Tableau and Business Objects) is why on earth is there not a native hide function in Power BI?! Personally, I find PBI to be a distant 3rd to the other tools I mentioned.

    1. The answer is simple: Power BI is 4 years old, Tableau is 16 years old and Business Objects is 26 years old. I am sure Power BI will have a native hide function in the future as Microsoft continues to develop the product over the years ahead.

  3. Hi Matt,
    This solution worked great for me. I have a quick question, though. I am using this solution to mask a bar chart until a selection is made. However, I think because it covers the bar chart area, I am losing the “mouse over” tool-tip information on the bars in the chart. Do you know of a way to stop this from happening?

    Thanks!

    1. Jason Cockington

      Hi Shannon,
      The challenge you have here, is that you are trying to hide the entire chart until a selection is made.
      The solution to give you this effect, but still allow you to maintain interactivity with your bars, is to only hide the elements of the blank Bar Chart, prior to selection.

      1. Write an additional Message measure, that renders a blank card

      Message Blank = 
         IF(
            ISFILTERED(Products[Category]),
            "",
            ""
         )

      2. Apply formatting to Message Blank card:
      – remove category label
      – conditionally format background colour with Make Transparent measure, as you did with your original Message card.
      3. Resize your original Message card to just cover the Bar Chart Title, and place a Message Blank card over each of the axis of your chart, so that the space where the bars render remains uncovered.

      Now, when nothing is selected in your slicer, you will see your message. Then when you select a value in your slicer, the Message card and the Message Blank cards will become transparent, so your Bar Chart will appear to have materialised based on the selection, and your bars will remain fully interactive, allowing you to mouse over for tool-tips, or click a bar for cross-filtering.

  4. Hi, I created all the measures as per the instructions here. I have 4 filters which I need to have selected for a visual to appear or become active. the check Filtered and the Message work fine, however I am not able to select the Make Transparent measure as a field in the background color conditional formatting options. It seems to be grayed out. any idea why?

  5. Hi Matt, This is great! Can you help me with my situation where in I have a bar chart for annual revenue with 7 bars by the top 7 clients and I only wish to highlight and display the name of the selected client from a filter, while not revealing the names of the other 6 clients, but showing their revenue stats?

    1. For customer presentations? I can’t think of any way to selectively show or hide one of the labels. I think you may have to turn off the labels for customer and add a manual text box. I guess yo could add 7 text boxes manually, and conditionally for at each of them to have the text transparent or black. Or maybe create 7 blank cards and control which of them are shown or hidden. You would have to manually place them over the customer names however, and that would be an issue if the chart redraws.

  6. Hi Matt, Thank you for the suggestion. I tried it and i was able to successfully hide a visual. But can you help me acheive the same functionality if i click on a scatter plot instead of filtering? I have a functionality where in i click on a data point in a scatter plot, i need to unhide the visual

  7. Hello Matt,

    Thank you for your interesting solution.

    I have tried to use it, but I faced with the following problem.
    The matrix(table) has no react on the filter “Check filtered”, being included in “Filters on this visual”.
    Moreover, if I change the values “0” and “1” in “Check filtered”, the matrix will be hidden forever without any reaction to check boxes.
    The picture of the described case is available by the link on google.drive: https://drive.google.com/open?id=1Y3kDvtsWiI9uDiBOUbutEEdXkBi9PUsX

    Thanks in advance for any help!

    1. Jason Cockington

      Hi Sergi,

      Looking at your image, it appears you have placed the Check Filtered measure onto your card.
      You need to place the measures as follows:
      1. Message – onto card fields
      2. Make transparent – onto card background, conditional formatting, field value
      3. Check filtered – onto matrix, filters on this visual

      If you’re still having trouble, check out this how-to video if you’re still having trouble.

  8. Hello, I’m having an issue with the Check Filtered measure – when I add this into “Filters on this visual” I can’t interact with it at all? it doesn’t seem to let me add any visual filters onto it, the drop down menus don’t populate and I can’t click in the boxes to enter text.

    1. Jason Cockington

      Hi Jace,
      Just double checking that you are placing the Check Filtered measure onto the Matrix and not the card.
      You can’t interact with measured filters on cards. If you click on the Message measure that is on the “Filters on this visual” of the card, you are not able to adjust its settings at all.
      In order to render the Matrix blank, it is the matrix that needs to be filtered by the Check Filtered measure.

      Check out this how-to video if you’re still having trouble.

      1. Thanks Jason,

        I had originally shown this as a card however I realised this was a limitation and changed it to a matrix, however I have just one measure in this under values and nothing in rows/columns – will this be the reason I can’t add a filter?

        1. Jason Cockington

          Hi Jace,

          Yes, that’s right. You need to have at least two values in the visual you are trying to hide (filter) with the Check Filtered. It doesn’t have to be a matrix, it could be a pie chart, column chart, or anything that takes at least two field values to display correctly.
          If you place something onto the rows, then the Check Filtered measure will work.

          If your target visual only requires the one value, and you just want to show or hide that, then skip the Check Filtered steps (skip: Write Check Filtered Measure & Filter Matrix to Render Blank), and just place the Message card over the entirety of the visual you are trying to hide.

  9. Jason Cockington

    Combining Matt’s solution with Maxim’s [Check Filtered] measure, allows for a more interactive experience for some visuals.
    With Matt’s matrix example, rather than covering the entire matrix with the message card, one only needs to cover the top two rows (those that would display when the matrix is blank thanks to [Check Filtered]).
    Then when the slicer is active and the card becomes transparent, it is possible to interact with the rest of the matrix and further cross-filter the report.

  10. Good solution, but the problem with it is that the card retains foreground focus and the control underneath is basically inoperable: no hover, selection, cross-filtering, …
    Anybody have a fix for that? AFAIK, the Z-order for visuals doesn’t change at run-time.
    The best I can come up with is covering options with bookmarks (no drop-downs obviously) and bookmarking the selection. Ugh.

      1. No kidding…this has been a thing in Qlikview (the old tool of choice at my company) for over a decade. I hope they implement it soon.

  11. Hi Matt,
    I have one challenge in our BI reporting.
    I have sales 1, sales 2, customer1, customer 2, item1, item 2 , date, sales lines 1, sales line2, sales history table
    Sales 1 joined with Sales lines 1 and Item 1 table. Sales line1 joined with date and customer 1 table
    Sales 2 joined with Sales lines 2 and Item 2 table. Sales line2 joined with date and customer 2 table
    Sales History joined with all the customer, item and date table.

    Have to combine Sales 1 & Sales 2 and sales history and report on this.
    What i did is: appended sales 1 and sales 2
    appended customer 1 and customer 2
    appended item 1 and item 2
    appended Sales line 1 and sales line 2
    Joined with the fact tables with respective dims above
    1st challenge: while joining the Sales history with Customer (Appended) i couldn’t make it active (seems data granularity issue)
    2nd challenge: sales history having the data until may 2019 remaining facts have data from June 2019.
    I used fiscal month as slicer. Since i couldn’t join the customer table when i use customer name and total sales from all 3 facts) the measure is not giving proper result.
    I would like to use different Customer copies one for Sales history and other for Sales table. and i want to choose customer name from either customer table joined to sales or customer table joined to sales history. Is that possible. also let me know is there any other alternative to face this issue.

  12. Hi Matt,

    I have a scenario when I have three constant lines (they do not come from Analytics) but rather a data columns (temperatures like extreme heat, comfortable low, comfortable high). On my slicer I have weather attributes (temperature, humidity, wind and pressure). I only want to display the three lines if the Temperature is selected. They do not belong to other attributes. How do I make them transparent? I can do any conditional formatting under the Data colors.

    Thanks,
    Stan

    1. The IF construct allows you to control 2 outputs; a null string or a custom message. SELECTEDVALUE will allow you to control one output only, with the other output being the value in case there is a single selection. I wanted to control both items. Yes you could use SWITCH(TRUE()), but that seems over kill unless you need more than 2 outputs

  13. Hi Matt.
    Solution work great, but there is one issue: if i want to hide matrix table, and show only if filterred, matrix table is not clickable (stepped layuot) or cant export to excel. The problem is that transparent visual is over matrix table, and that’s why user cant click on matrix table.
    Is it possible to solve it?
    Thx

    1. Yes, that is the issue. I don’t know of anyway to solve this particular problem. In the future I would expect that expression based formatting will solve the problem but as of today I don’t know of a solution

      You could take a different approach however. it is already possible to use expression based formatting to set the background colour of objects. I am not 100% sure but I think you can do this with a matrix and table (you definitely can with cards), you would have to check. So one idea would be to set the background colour of the matrix to be read if it is not correctly configured. Another approach would be to set the title of the chart to give a message instructing the user to select a value first

  14. Murray Foxcroft

    Cool and clever approach, but the transparent card gets in the way of interacting with the underlying visual. 🙁

  15. Hi Matt,

    Here is my solution:
    Check Filtered = IF(ISFILTERED(Products[Category]),1,0).

    Place the measure to Filters on this visual tab and in Show items when the value: is 1

    Hope it helps anyone.

  16. Hello Matt,

    I experimented with your hack to show or hide some menu buttons based on certain values in a table, to restrict access to certain pages in my report
    But one problem: if the button is visible and the transparancy is on of the card or shape (rectangle) that’s used to hide the menu-button, it’s not possible to use the click to another page , because you’re still clicking on the card that’s used to hide the button, and not the button itself.
    It’s the same if you hide for example a chart or table, it’s not possible to click in it to filter another visual

    Have you experienced the same problem and have maybe (hopefully) a solution?

    1. Yes, you are right – I found this too. In my example you can’t select the visual hidden then shown for the same reason. I realise my concept is a hack and it has some limitations. Microsoft has announced that it will continue to build out expression based formatting across the product. So I hope and expect that at some stage we will be able to use a measure to make any visual visible or not

    2. Hi, in my case I wanted to hide a table. The scroll wheel didnt work when it was fully placed over the table but when I leave a bit of space on the right side it does work when the white space is gone. Might help with your problem aswell if you tried to scroll on your visual.

  17. Hi Matt,

    Great article, I am uunable to locate ellipses on the right-side of Color on card visual. I am using May 2019 release of PowerBI

  18. Simon Schofield

    Hi there, is there a way to amend the ‘Make Transparent’ measure so that when a certain value is selected from the slicer the transparent treemap is activated, rather than no value being selected from the slicer. Cheers

  19. Hello! A great tip, thanks for it!! Do you think the same would be possible if one bar in a bar chart is selected. With that I mean if a user would click on a bar, more details would appear (the treemap would become transparent) depending on the selection of the bar. (each bar has a unique ID).
    Thanks million times!

    1. You would have to test it. I am expecting more expression based formatting to come to Power BI in the future, so hopefully at some stage this will be a feature rather than a hack.

  20. My guess is that you have cross filtering set to “highlight”. If that is the issue, change “edit interactions” to “filter”. It is on one of the menus visible when you select the matrix.

  21. Hi, Instead of Slicer selection, I tired with Matrix row selection. With the Matrix row selection, I am not able to achieve the same thing. Could you please let me know how to use with Matrix row selection (SelectedValue) instead of a Slicer? Thank you in Advance.

  22. Pete Watridge

    Hi Matt — really enjoy your articles — have your website on my regular “to read” list. Your insight of using Treemap as a controllable color shape was brilliant and an eye opener for me. I had a project where I needed the background color of a matrix to be controlled by filters. So I adapted your approach: I made the background of the grid 100% transparent — and then put the treemap “background” behind it that responded to the filters via DAX formula. It worked perfectly. Never would have thought of using treemap as a controllable background without this article. Many thanks!

  23. Dang: This doesn’t work for me when saved to the PBI service and rendered in IE (version 11.0.120).
    Works fine in chrome. But our users have IE as the default.

    Anyone manage to get it working in IE?

  24. Hey Matt…I just spent ages trying to replicate your trick to no avail, until I finally realised that I was trying to trigger it from a Table (not a Slicer) and the default behaviour was to crossfilter the Treemap rather than filter it. Meaning it didn’t work. Perhaps you could include another step in your instructions above showing how to change the “Edit Interactions” behaviour of the TreeMap from Crossfilter to Filter, so this cool trick can be used for other types of trigger visuals.

    But I love it, man.

    1. Another way to accomplish this is to use visual level filters combined with dynamic titles. Create a measure that is 1 if filtered, 0 if not. Drag that measure to filter pane and set to only show when measure=1.

      You can also use that measure within the dynamic title to have it display a message. I use this for data tables when I don’t want all of the information showing until a user has filtered it.

      1. @Stu I use that trick too. But this method of obscuring both the data and the headers means you can do additional stuff like overlay different types of visuals on top of each other, and trigger a bookmark-like experience from a Slicer, which is very cool (and should be allowed natively).

  25. Is it possible to do the trick on two slicers with an OR function or similar? So the message would disappear if one selected the first slicer or if they just selected the second slicer?

  26. Hi Matt – Great Article, when i was experimenting with the file i realized that instead of writing the hex code for transparent as #FFFFFF00, one could just write “transparent” and it works.

  27. Could this work to highlight a sub-group in a scattergram? i.e. make the unselected sub-groups more transparent than the selected one.

    1. The principle of a measure that formats a data point is the same, I think. So as long as you can write the DAX, you will be able to do what you suggest. But what you will need to do is have your slicer either with an inactive relationship, or no relationship at all, otherwise the slicer will filter the visual. I assume that changing the cross filter behaviour between slicer and visual will not work in this case, but I can’t be sure.

      1. Great thanks, I solved it as you say by overlaying two scattergrams with the same set axes and one which has an inactive relationship to the slicer

  28. This is awesome Matt! I’ve been trying to find a way to do this as well, the treemap approach is pretty brilliant.

    One thing to note regarding optimization: the matrix is still calculating even though you can’t see it. That means a potentially large DAX query is still running in the background…possibly slowing down other visuals.

    You may want to adjust your matrix measure to the following:
    [Matrix Measure with Check] :=
    IF(
    ISFILTERED( Products[Category] )
    ,[Matrix Measure]
    ,BLANK()
    )

    This will return BLANK() if there’s no selection, saving the other measure from being evaluated.

    1. Yes, this would be another approach. I was really trying to find a problem to match my solution – the idea of using transparency to hide or show an object on the canvas. I am sure my solution has other applications too. For example, you could create an instructions section on the page, and overlay multiple text boxes with multiple instructions, all set to transparent text and transparent background. When certain conditions are met, you could display the appropriate instruction by changing the transparency.

  29. Nice workaround. Coming from the Qlikview world and having used that for the past 8 years, it’s amazing to me that simple SHOW/HIDE conditions are not available yet in PBI. This conditional formatting they are starting to roll out makes me feel like they are starting to get it and PBI is getting more and more Qlik like with every release.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top