Skip to main content

Dynamic card upon slicer selection in Power BI

Case – I have to create a dynamic card and it should display the product name and product price when I choose a specific product from slicer. We will see what is the card and slicer that I’m talking about when we move along.

Why this has happened

I have a product table which has to be presented in a user friendly manner. I wanted something like this to happen if user selects “Pen” from the slicer “One pen is Rs.15”



What I wanted to do next

You can see my product table in the above image, now I want to add a column which displays something similar to “One pen is Rs.15” for each row corresponding to their Product Name and Product Price in this table and I have shown it below.



As you can see above I have selected the column from examples option which is in the top left of Add column task bar of the query editor. If you don’t understand tap the below task bar and see it for yourself.



Once I have placed the example and pressed enter the following table is my result for it.



Now I’m done with query editor and time to play with the report. I need to add two visuals in my report one is a “slicer” which is much like a combo box where it allows me to select any product of my choice and the other one is a card which is going to display the price of one product.


In the above image you can see some default visualizations which you can use in your report also both slicer and card which I’m talking about is also there, try to find it yourself before going to the next line.

Slicer is the first one in the fifth row and card is the fourth one in the fourth row.


Once I have selected both visuals it will be shown like the above image where the one in the left is slicer and the one in the right is card.

Then I placed the Product name on the field of slicer like I have shown below


After placing the Product name, the slicer visual became a combo box containing all the products name on it like I have shown below.


Can you recall the column from example that we created in the beginning, now it is time to implement that on the normal card and make it a dynamic card as shown below.


You can notice when I’m selecting different products then the content displayed in the card is changing accordingly. I did this by doing a simple thing as shown below.



As you can notice in the above image I simply placed the column I created using the column from example which is named "Merged" and placed it on the field of the card.

Secret - Here there is an issue see it for yourself.



Did you notice that i haven't selected any product from the slicer but still it is showing data for an A4.

 As long as a product is selected it displays the data but what happens when nothing is selected, it is going to show the first row of the column “Merged” which we created using column by example since I have selected the option First in my fields to show as default.

How I want it to be – I want to display “Select a product” when nothing is selected and that is the right thing to do.

My way of doing it – I thought of creating a new measure and placing it in the field of card in order to solve this issue and it is below.



You can see a New Measure option in the second from top right and I wrote a simple dax statement to solve this issue. The statement is below for you

Measure = IF (HASONEVALUE ('Product'[ProductName]),
SELECTEDVALUE ('Product'[Merged]),
"Select a Product")

The dax statement I implemented above is much similar to an “If condition”, here I want to check if there is a value for product name by using “Has On Value” and if there is a value then display the corresponding value you find in the column by example using “Selected Value” else display “Select a Product”, If you don't understand read it again.

After placing the measure i created to the field of card it worked as I expected it to be when nothing is selected as shown below. 


If you select only one product then it will show the unit price of that product without any issues as shown below.


If you try to select multiple products as shown below then you will be notified to "select a product" which implies that you have selected multiple products so select only one.



What is happening – Power BI visuals are connected dynamically so if we choose something specific in a visual all the other visuals will be filtered accordingly and same thing is happening in this scenario where we choose a product name from the slicer and it is filtering the “column by example” we created and finds the row which matches that product and displaying it hence it is dynamic and easy to track the price of a unit product as I wanted it to be.




Comments

  1. Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog onpower bi online course

    ReplyDelete

Post a Comment

Popular posts from this blog

Choosing color scheme for Power BI reports

Choosing beautiful colors for an attention seeking Power BI report is always challenging. Sometimes we may have an important message but it might go unseen if proper color scheme is not used, so it is important to create reports which are informational and visually appealing. In this blog our main objective is to get an idea about selecting appropriate color scheme and tools that can be beneficial to do this. What is a color scheme? As you all know not all colors look great together and you can tell stories by just having only two colors, have a look at the following image, there in the middle you can see a circle with same color and same dimension, only thing that changes is the back ground, but depending on the back ground the way you see those circles are totally different. Some small circles appear softer, some appear sharper, and some are brighter also you might notice movements or depth effect too. It is important to choose colors wisely to serve the purp...

Ragged hierarchy in Power BI

Case- I have a data set which has to be visualized in a ragged hierarchy. What is ragged hierarchy A ragged hierarchy is a user defined hierarchy with an uneven number of levels.   You can see the above table which has 5 levels of hierarchy. In the first level we only have “World” as a category then moving forward to the next level we have two categories  namely “UK” and “USA” likewise the level of hierarchy is drilling down up to five levels with an uneven amount of categories. Creating a hierarchy in Power BI In the above image  you can notice that I have right clicked the “level 1” column which has to be the first level of our hierarchy, Once it is right clicked there you will notice “New hierarchy” as the second option then you will have to click that in order to create a new one. As you can notice in the above image once I have created a new hierarchy then a new column is created named “Level 1 Hierarchy” in that I have d...

Five tips to enhance a tableau model with usability features.

In the previous blogs I was more focused in Power BI since i work with it day to day, but this time we are going to dig into increasing the usability features of tableau. This blog revolves around the end-user simplicity, if a model is hard to comprehend then it will be a disaster, so we should deploy some means to stay simple. So without further ado lets head on to the first topic of the day. Configuring table and  column  properties. A model can consist of many tables but the important fact is they have to be unique and it is better if we can have a table description to elaborate on whats it about. This can be also considered as an internal documentation, when a project member is changed it is easy to pick up and continue. We use connections to load data for the tables and we have a connection name for it but once if we set the source it cannot be changed in the latter part, so be mindful because once you are dropping a connection you are losing all th...