Forum Discussion

tecumseh's avatar
tecumseh
Resolver III
1 year ago
Solved

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

  • Anonymous's avatar
    Anonymous
    1 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

  • Anonymous's avatar
    Anonymous
    Not 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.

  • 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:

    1. Select the Column Chart.
    2. Go to Title > Text Color and click on the fx button.
    3. A new window will appear.
    4. In Format Style, choose Rules and base the rule on the isOneSelected measure.
    5. 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_Geraldo's avatar
      Bibiano_Geraldo
      Super 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:

      1. Select your Slicer.
      2. Go to Slicer Settings.
      3. Enable the Single Select option.

      This approach ensures that the user can only select one value at a time, preventing multiple selections automatically.

  • Hi tecumseh ,

    Have you thought about disabling multi-select and force select on your users to only have one channel selected at a time?

    • tecumseh's avatar
      tecumseh
      Resolver III

      Thanks hnguy71 ,

      Users need to be able to select all channels to see company total.
      Looks like some great options on this thread to deliver a message to users to "disable" channel detail charts in these instances.