Forum Discussion

Soumargha's avatar
Soumargha
New Member
2 years ago
Solved

Date Slicer Default

I have a requirement where the Date slicer has to be blank by default but whenever date is entered in the To field, it should limit to 12 months from the selected date. Request your help on this. 

    1. Create a Date Table: If you haven't already, create a date table in Power BI that spans a wider range of dates than you'd typically need (e.g., several years before and after your dataset). This will be useful for creating the date slicer.

    2. Add a Slicer to the Report Page:

      • Drag the "Date" field from your date table into the report canvas.
      • This will create a slicer with a list of dates.
    3. Modify the Date Slicer for Default Behavior:

      • Go to the Format pane (paint roller icon).
      • Under the "General" section, look for the "Selection controls" option.
      • Set the "Show "Select All" option" to Off.
      • This ensures that when you load the report, no dates are pre-selected in the slicer.
    4. Create Measures for Date Range Calculation: You'll need to create measures that determine the 12-month range based on the selected "To" date.

    Min Date =
    IF(
    ISBLANK(MIN('DateTable'[Date])),
    BLANK(),
    DATEADD(
    MAX('DateTable'[Date]),
    -12,
    MONTH
    )
    )

     

    1. Here, if no date is selected, the measure returns blank. Otherwise, it returns a date 12 months before the maximum date in your dataset.

    2. Filter the Data:

      • Create relationships between your date table and your main data table using the "Date" column.
      • Use the measure you created to filter your data table. For instance, you can set up a visual-level filter or a page-level filter based on this measure to ensure only data within the last 12 months appears when a date is selected.
    3. Test the Slicer:

      • Go back to your report and test the slicer behavior. When you load the report, the slicer should not have any dates selected by default. When you select a date in the "To" field, the visuals connected to your data table should automatically adjust to show data only from the past 12 months.

    By following these steps, you should be able to achieve the desired behavior where the Date slicer is blank by default and limits the data to the past 12 months when a date is selected.

1 Reply

  • 123abc's avatar
    123abc
    Icon for Community Champion rankCommunity Champion
    1. Create a Date Table: If you haven't already, create a date table in Power BI that spans a wider range of dates than you'd typically need (e.g., several years before and after your dataset). This will be useful for creating the date slicer.

    2. Add a Slicer to the Report Page:

      • Drag the "Date" field from your date table into the report canvas.
      • This will create a slicer with a list of dates.
    3. Modify the Date Slicer for Default Behavior:

      • Go to the Format pane (paint roller icon).
      • Under the "General" section, look for the "Selection controls" option.
      • Set the "Show "Select All" option" to Off.
      • This ensures that when you load the report, no dates are pre-selected in the slicer.
    4. Create Measures for Date Range Calculation: You'll need to create measures that determine the 12-month range based on the selected "To" date.

    Min Date =
    IF(
    ISBLANK(MIN('DateTable'[Date])),
    BLANK(),
    DATEADD(
    MAX('DateTable'[Date]),
    -12,
    MONTH
    )
    )

     

    1. Here, if no date is selected, the measure returns blank. Otherwise, it returns a date 12 months before the maximum date in your dataset.

    2. Filter the Data:

      • Create relationships between your date table and your main data table using the "Date" column.
      • Use the measure you created to filter your data table. For instance, you can set up a visual-level filter or a page-level filter based on this measure to ensure only data within the last 12 months appears when a date is selected.
    3. Test the Slicer:

      • Go back to your report and test the slicer behavior. When you load the report, the slicer should not have any dates selected by default. When you select a date in the "To" field, the visuals connected to your data table should automatically adjust to show data only from the past 12 months.

    By following these steps, you should be able to achieve the desired behavior where the Date slicer is blank by default and limits the data to the past 12 months when a date is selected.