Search code examples
powerbipowerbi-desktop

How can I use two slicers in Power BI to select the two columns to be used on a column chart?


I am trying to use two slicers in Power BI to select the StartYear and EndYear columns for a column chart. The only two bars on the chart will be the sum of revenue for the selected two years.

I've tried using two separate tables connected to a common one, with one-to-many relationships and cross filtering in one direction, but that won't work. (https://i.sstatic.net/8jtVJITK.png)

This is what I want the chart to look like, with two single-select slicers instead of one multi-select.(https://i.sstatic.net/KhJP5nGy.png)


Solution

  • First, remove your relationships (but keep your "flanking" tables), they just make this harder for you, since if you select different years you effectively exclude all your fact table rows from the evaluation.

    Then you can use a measure that looks something like this:

    Revenue = 
    VAR _min = SELECTEDVALUE ( StartYear[Year] )
    VAR _max = SELECTEDVALUE ( EndYear[Year] )
    RETURN
    IF ( 
        SELECTEDVALUE ( IncCAGRTable[Year] ) IN { _min,_max } ,
        SUM ( IncCAGRTable[SumRevenue] )
    )
    

    I haven't tested this since I don't have access to a Windows box at the moment.