Forum Discussion

ashamsuzzoha's avatar
ashamsuzzoha
Icon for Advocate II rankAdvocate II
5 years ago
Solved

How can I toggle line/columns on line charts?

I have the following line and column chart and the user is requesting the ability to toggle columns/lines on and off. How do I do that? The columns on all on the same table. I made a disconnected tab...
  • TomMartens's avatar
    TomMartens
    5 years ago

    Hey ashamsuzzoha , 

    you can achieve this, by creating a table that represents the measure name, this table fills the slicer that allows users to select what they want to see on the visual. but is otherwise unrelated to your data model.
    All the measures have to be assigned to the visual in advance 🙂 as it's still valid what I said above, that you can't programmatically assign a measure / column to a visual.

    Assuming that there is a measure called Measure 1, you have to do 4 things

    • add the value "Measure A" to the visual
    • add a row to the unrelated table that is populating the "Measure slicer"
    • create a slicer based on the unrelated table
    • adjust your measure in a way that it reflects the selection inside the slicer (see the DAX below)

    As the measures might be used outside of the context of the visual we are currently talking about, the DAX statement that toggles the "visibility" has to be a little more generic.

    If I implement something like this, I consider it useful to remember that the selection of all items from a slicer means basically the same as no item is selected in regards to the rows that will be filtered, but can mean a great difference to use this information for toggling the visibility of a measure.

    Another aspect to keep in mind, is the fact that visibilty of a measure means leveraging the fact that visuals (most of them) honor the value BLANK() in one way or the other.
    In the sample report (see link below), the measure name will always appear in the legend of the line and stacked column chart no matter if a measure returns a value.
    Here is the DAX statement for one measure:

     

     

    Measure 1 = 
    var measureTableIsFiltered = ISFILTERED( 'unrelated table' )
    var filteredMeasure = VALUES( 'unrelated table'[Measure] )
    return
    IF( NOT( measureTableIsFiltered ) || "Measure 1" in filteredMeasure
        ,
        // the below DAX computes the actual measure - here a simple constant value
        1
        // the above DAX computes the actual measure - here a simple constant value
        , BLANK()
    )

     

     


    Here you will find a sample pbix file
    A screenshot of what's inside the pbix (the card visuals are just used for decoration and testing):

    Hopefully, this provides what you are looking for, if not create a pbix that contains sample data but still reflects your data model. Upload the pbix to onedrive or dropbox and share the link. If you are using Excel to create the sample data share the xlsx as well.

     

    Regards,

    Tom

  • Anonymous's avatar
    Anonymous
    5 years ago

    ashamsuzzoha 
    You can achieve this only for measures, you may create a disconnected slicer table including measure using IF(Contains()....). See attached example pbix.

     


    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.