Forum Discussion
Deliver Message To User If Too Many Items Selected Else Bar Chart
Hi all,
I have a Bar Chart on my report page
But it doesn't look good if a user selects multiple channels
I want to deliver a message if channel count > 1, else deliver bar chart
How can I do that?
Thanks
w
- Anonymous1 year ago
Hi tecumseh ,
Thanks for hnguy71's reply!
If you mean that when the user makes multiple selections, a pop-up warning will appear, or the original bar chart will be changed to a card chart to display information, then I'm sorry that this is not possible in Power BI.
I can give you a workaround:
Here is my sample data:Use this DAX to create a measure:
Sum of Value = VAR _sum = CALCULATE( SUM('Table'[Value]), ALL('Table'), 'Table'[Channel] <= SELECTEDVALUE(Slicer[Channel]) && 'Table'[ID] = MAX('Table'[ID]) ) RETURN IF( COUNTROWS(VALUES(Slicer[Channel])) > 1, BLANK(), _sum )Then create the bar chart (column chart):
Use this DAX to create another measure:
ShowMessage = IF( ISFILTERED(Slicer[Channel]), IF( COUNTROWS(VALUES(Slicer[Channel])) > 1, "Please select only one channel to view the bar chart.", BLANK() ), "Please choose one channel" )Then create a Card(New) and put the measure into it:
Click Card > Visual > Callout values > Values > enter a space in the field under Show blank as:
Then go to Cards > Background > Change Transparency to 100%:
Also close the Border:
Then overlap the Card (New) and the bar chart:And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- AnonymousNot applicable
Hi tecumseh ,
Thanks for hnguy71's reply!
If you mean that when the user makes multiple selections, a pop-up warning will appear, or the original bar chart will be changed to a card chart to display information, then I'm sorry that this is not possible in Power BI.
I can give you a workaround:
Here is my sample data:Use this DAX to create a measure:
Sum of Value = VAR _sum = CALCULATE( SUM('Table'[Value]), ALL('Table'), 'Table'[Channel] <= SELECTEDVALUE(Slicer[Channel]) && 'Table'[ID] = MAX('Table'[ID]) ) RETURN IF( COUNTROWS(VALUES(Slicer[Channel])) > 1, BLANK(), _sum )Then create the bar chart (column chart):
Use this DAX to create another measure:
ShowMessage = IF( ISFILTERED(Slicer[Channel]), IF( COUNTROWS(VALUES(Slicer[Channel])) > 1, "Please select only one channel to view the bar chart.", BLANK() ), "Please choose one channel" )Then create a Card(New) and put the measure into it:
Click Card > Visual > Callout values > Values > enter a space in the field under Show blank as:
Then go to Cards > Background > Change Transparency to 100%:
Also close the Border:
Then overlap the Card (New) and the bar chart:And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- tecumsehResolver III
Thanks Anonymous
Works great!
- Bibiano_GeraldoSuper User
Hi tecumseh ,
That's a great idea from Anonymous ! I'd like to expand on it by providing a more detailed explanation while considering the user experience. The goal is to prevent the card from overlapping the column chart when the user wants to make a selection and make the column chart dissapear completely if more than one value was selected in the slicer.
Step 1: Create a Measure to Check Slicer Selection
First, create a measure to check if the slicer has exactly one selected value:
isOneSelected = IF( HASONEVALUE(financials[Product]), // Use the same field from your slicer that filters the bar chart 1, 0 )Step 2: Modify the Sales Amount Measure
Now, suppose your bar chart displays the total sales amount by country. Modify the sales amount measure as follows:
Sales Amount = IF( [isOneSelected] = 1, SUM(financials[Sales]), BLANK() )This ensures that sales data is only displayed when a single selection is made.
Step 3: Create a Measure for Text Output
Next, create a measure to show a message when multiple selections are made:
TextOutPut = IF( [isOneSelected] = 0, "Multiple selections not allowed", "" )Step 4: Add a Card Visual for the Message
- Insert a Card Visual into your report.
- Add the TextOutput measure to it.
- Disable the Category Label in the formatting settings.
- Customize the background and text color as needed this card will serve as the background for the bar chart.
Step 5: Overlay the Column Chart on the Card Visual
- Create a Column or Bar Chart with the same size as the card visual.
- Set the X-axis to the Country column.
- Set the Y-axis to the Sales Amount measure.
- Disable the chart's background (since the card visual will act as the background).
At this point, the column chart is there, but it looks like nothing has changed. However, the labels are still visible.
Step 6: Hide the Labels When No Selection Is Made
To hide the labels dynamically:
- Select the Column Chart.
- Go to Title > Text Color and click on the fx button.
- A new window will appear.
- In Format Style, choose Rules and base the rule on the isOneSelected measure.
- Follow the instructions in the image below (refer to your guide).
Step 7: Hide the X-Axis Title Using the Same Logic
- Expand the X-axis settings.
- Click on the fx button for the title color.
- Apply the same rule as before.
Final Result
At this point, the bar chart should disappear completely when multiple selections are made.
Now, just add a slicer, and your final result should look like this:
- Bibiano_GeraldoSuper User
However, as hnguy71 mentioned, if your goal is simply to force the user to select only one value in the slicer, you can achieve this with a built-in setting:
- Select your Slicer.
- Go to Slicer Settings.
- Enable the Single Select option.
This approach ensures that the user can only select one value at a time, preventing multiple selections automatically.