Display Custom Message in the Visual Until a Selec…


Every tool has got it’s own way to create and manage work-arounds based on the different requirements.

Today in this blog, I will be showing how one can implement a functionality, where the default view of a visual is required to be a custom message until the user makes a selection from the slicer.

 

Let us consider the following sample data:

s1.png

The sample data shows sales overtime for different product categories.

 

Now our task is to achieve the following functionality shown below:

s1gif1.gif

In the above short gif, we see that we need to have a default message on the report page asking user to select a value from the slicer provided. Once a value is selected in the slicer, the data displays in the table visual. If there is no slicer selection, user again gets a message to make selection.

 

Let us go through the simple steps on how we can achieve this brilliant workaround in Power BI.

 

First thing we will do is create a measure, that will check if a value is selected in the slicer or not.

Filter Selected =
IF (
    CALCULATE (
        HASONEVALUE ( ClothingSales[Category] ),
        ALLSELECTED ( ClothingSales )
    )
        TRUE (),
    1,
    2
)

 

The above measure is a simple IF statement which checks if we have got a selection in the slicer for the Category. If a value is selected, the measure returns 1 otherwise it returns 2.

 

Now we will move this measure to our table visual’s visual-level filter section and select the measure value = 1. This will make sure the table visual displays information only when a value is selected in the slicer.

We see as soon as we move the above measure with value = 1, the table visual gets empty.

See below:

s2.png

 

Now let us create a slicer for category as follows:

s3.png

 

As soon as we start making selection in the slicer, we start seeing that the data is getting displayed in the visual. When nothing is selected it remains empty. So the measure that we created above is working correctly:

s1gif2.gif

Our 50% task is already done. The only thing remaining is we need to display a custom message rather than empty visual to prompt the user when nothing is selected in the slicer.

 

For this we will create another measure as follows:

Is Filter Message =
IF (
    NOT ( ISFILTERED ( ClothingSales[Category] ) ),
    “Select a Value in the Category Slicer to Display the Information”,
    “”
)

 

The above measure checks whether we have got a filter on Category slicer or not. If we haven’t got a filter on category slicer, the measure will show the message – “Select a Value in the Category Slicer to Display the Information” otherwise it will show blank.

 

Create a card visual and move this measure to it as shown below:

s4.png

 

Now let us test if the card value is getting displayed correctly based on the slicer selection:

s1gif3.gif

 

We see that the measure used on the card visual works perfectly.

Now the only task remaining is move this card visual somehow over the table visual so it shows the message when nothing is selected, but becomes hidden/transparent as soon as a slicer value is selected and the table visual shows data rows.

I will try to show how we want to do it.

s1gif4.gif

 

I have placed the card visual just above the table visual. It shows me a message when I don’t select anything in my slicer. But, it hides my table information when I start making a selection in the slicer.

Now how should we solve this?

We have to basically come up with a way, where we can make our card visual transparent whenever a selection is made in the slicer.

 

Create one last measure to achieve this:

Make Transparent =
IF ( ISFILTERED ( ClothingSales[Category] ), “#FFFFFF00”, “#3A3A3A” )

 

In the above measure, I am just trying to give a background color to the card visual based on, if a selection is made in the category slicer.

If a selection is made in the slicer – This will display data in the table visual and I have to make the card transparent.

“#FFFFFF00” hexcode is for transparecy. The other hexcode in the measure “#3A3A3A” is for maintaining the background color of the card visual similar to my report page color. Now my report page color theme is black therefore I chose “#3A3A3A”. If you are working with white page background change it to “#FFFFFF”.

 

One last step to be achieved is use the above measure to drive the background color of the card visual. For this do the following:

s5.png

 

Once we click on the fx icon under Background for card visual, following window appears:

s6.png

Just select the options in the window as highlighted and then click OK.

 

Everything is done, let us see how the work-around is working.

s1gif5.gif

 

Voila! We have achieved a great workaround for this scenario.

 

I love all the different workarounds we can create in Power BI with less hassle. Hopefully this helps everyone out there.

 

– Pragati

 

 



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*