Forum Discussion

PowerBI-Newbie's avatar
1 year ago

Two Period Slicers filtering data

Hi,

I'm looking to create two slicers, where the user selects Start Period and End Period (see below):

 

At the moment they're having to use a single slicer and multi-select the periods that way (see above picture) but I can see this causing issues long-term as the list of periods increases. I know there's the ability to use one date slicer that gives the user the ability to select the date range but the brief is that Date isn't to be used for filtering but rather Period, and when using Period the range option isn't available hence the need for two period slicers.

 

Another requirement is for the second slicer to be filtered based on the selection from the first slicer such that an earlier Period can't be selected on the 2nd slicer e.g. if the user selects Period 4 in slicer 1 and Period 3 in slicer 2 - this shouldn't happen so when the user selects Period 4 in slicer 1 then they can only see Period 4, Period 5, etc. If there's a way for the user to not be able to select from slicer 2 until a selection has been made from slicer 1 then that would resolve any issues in the event that they make a selection from slicer 2 first before slicer 1.

 

How can I implement the above? Any help is greatly appreciated.

10 Replies

  • Hi PowerBI-Newbie ,

     

    To create two slicers (Start Period and End Period) with the periods formatted as "23-24.01," "23-24.02," and so on, where the second slicer dynamically updates based on the selection in the first slicer, follow these steps:

    First, ensure you have a table, which we’ll call PeriodTable, that contains all the periods in the required format (e.g., 23-24.01, 23-24.02). This table should also include a numeric column PeriodOrder that assigns an order to each period (e.g., 1 for 23-24.01, 2 for 23-24.02, etc.). This numeric column will help in determining the filtering logic.

    In your Power BI model, create two measures. The first measure, SelectedStartPeriod, captures the order of the Start Period selected by the user. Use the formula:

    SelectedStartPeriod = MAX(PeriodTable[PeriodOrder])
    
    

    Next, create a second measure, EndPeriodFilter, which will filter the End Period slicer to show only periods greater than or equal to the Start Period. Use the following formula:

    EndPeriodFilter = 
    IF(
        ISFILTERED('PeriodTable'[PeriodOrder]) &&
        MAX('PeriodTable'[PeriodOrder]) >= [SelectedStartPeriod] &&
        NOT ISBLANK([SelectedStartPeriod]),
        1,
        0
    )
    

    Add both slicers to your Power BI report. For the Start Period slicer, drag the Period column from the PeriodTable and set it up as a dropdown or list slicer. For the End Period slicer, drag the Period column again, and apply the EndPeriodFilter measure as a visual-level filter, ensuring it only shows values where the measure equals 1.

    This setup ensures that the End Period slicer remains blank until a Start Period is selected, and it dynamically updates to only show periods that are equal to or later than the selected Start Period. For example, if "23-24.05" is selected in the Start Period slicer, the End Period slicer will only show "23-24.05" through "23-24.12."

    Finally, test the report to ensure that selecting a Start Period filters the End Period slicer correctly and that the End Period slicer remains non-functional until a Start Period is chosen. This approach is robust and accommodates your specific period format seamlessly.

     

    Best regards,

    • PowerBI-Newbie's avatar
      PowerBI-Newbie
      Helper IV

      Hi DataNinja777 , thank you for your response.

      Unfortunately that doesn't work for me as I get the following:

      It doesn't show anything greater in slicer 2 than what was selected in slicer 1. Are you able to send through pbix file please?

       

      Furthermore, and once this is resolved, how do I get this to filter the graphs that I have in my report?

  • hi PowerBI-Newbie 

     

    You will need to use two disconnected dates table - on for period 1 and another for period2. Using a related table will show just what is selected. And then refererence those tables to filter an aggregation.

     

    I'm using these measures below in the screenshot

    Value within Periods = 
    CALCULATE (
        [Sum of Value],
        KEEPFILTERS (
            DatesTable[Date] >= MIN ( Period1[Date] )
                && DatesTable[Date] <= MAX ( Period2[Date] )
        )
    )
    
    
    Filter from Period1 = 
    --as visual filter for Period2, not blank
    CALCULATE (
        COUNTROWS ( Period2 ),
        KEEPFILTERS ( Period2[Date] >= MIN ( Period1[Date] ) )
    )
    

    Refer to the attached pbix for the details.

    • PowerBI-Newbie's avatar
      PowerBI-Newbie
      Helper IV

      Hi danextian , thank you for your response.

      The periods come in the following format YY-YY:Period - 23-24:09 for example is Period 9 in the financial year 2023-2024. See below sample list:

       

      Whereas yours is in Month-Year format. How do I do what you did for my requirements in terms of periods?