Forum Discussion

YashikaAgrawal's avatar
YashikaAgrawal
Post Patron
5 months ago
Solved

Slicer visual default date logic not working

Hello, need help in slicer visual.   Created a measure as below   Last 13 months filter = var maxondate = calculate(max(table_name(file_load_date),all(table_name) var currentmonthdate = table_...
  • SamInogic's avatar
    5 months ago

    Hi,

     

    In Microsoft Power BI, the reason your approach doesn’t work is that slicers cannot be filtered by measures. Measures are calculated after filter context is applied, while slicers require columns. That’s why your measure works in a table visual but not in a slicer.

    To implement a dynamic “Last 13 Months” slicer, you need to use a calculated column in your date table instead of a measure.

    Recommended Solution (Calculated Column)

    Create a column in your Date table (or the table used in the slicer):

    Last13MonthsFlag =
    VAR MaxDate =
        CALCULATE(
            MAX('table_name'[File_load_date]),
            ALL('table_name')
        )
    RETURN
    IF(
        'DateTable'[Date] >= EDATE(MaxDate,-12)
            && 'DateTable'[Date] <= MaxDate,
        1,
        0
    )

    Then:

    1. Use DateTable[Date] in the slicer.
    2. Add Last13MonthsFlag to the Visual Level Filters of the slicer.
    3. Set the filter to = 1.

    Now the slicer will only show the last 13 months dynamically.

     

    Even Simpler Option (Recommended)

    If you have a proper date table, Power BI already provides a built-in filter:

    1. Select the slicer.
    2. Change slicer type to Relative Date.
    3. Set:
      • is in the last
      • 13
      • Months

    This is usually the cleanest solution.

    Hope this helps.

     

    Thanks!