Forum Discussion

UncleLewis's avatar
UncleLewis
Icon for Responsive Resident rankResponsive Resident
3 months ago
Solved

Custom Date Period Slicer To Get Last Quarter

Hi,

Using PBID April 2026.

I'm trying to add an item to a slicer to filter a Stached Column Chart to show results for last quarter
Today is 5/22/2026 (Q2 - 2026) so I expect (Q1 - 2026)

However, this returns Q4 - 2025

ADDCOLUMNS(
PREVIOUSQUARTER(DATESYTD( Dates[Date] )),
"Type", "Last Qtr"
)

And this does not return anything in the Stacked Column Chart

ADDCOLUMNS(
PREVIOUSQUARTER( Dates[Date] ),
"Type", "Last Qtr"
)

 

What am I missing here?

Thanks,

w

  • Hi UncleLewis 

    The issue is that the slicer item only gives the user a selection. It does not automatically translate “Last Qtr” into the correct date range for the chart unless the slicer table is connected to the Date table in a way that actually filters the visual.

    PREVIOUSQUARTER is also context-dependent. In a calculated table, it is evaluated when the table is calculated/refreshed, not dynamically based on the visual context. That is why PREVIOUSQUARTER(DATESYTD(Dates[Date])) can return Q4 2025 instead of Q1 2026.

    If you want “Last Qtr” to mean the last completed quarter relative to today, I would usually use a disconnected period slicer and apply the logic inside the measure used by the stacked column chart.

    For example, create a simple slicer table with values such as “All” and “Last Qtr”. Then create a measure like this:

    Sales Selected Period =
    VAR SelectedPeriod =
    SELECTEDVALUE ( 'Period Slicer'[Period], "All" )

    VAR RefDate =
    TODAY()

    VAR CurrentQuarterStart =
    DATE (
    YEAR ( RefDate ),
    3 * INT ( ( MONTH ( RefDate ) - 1 ) / 3 ) + 1,
    1
    )

    VAR PreviousQuarterStart =
    EDATE ( CurrentQuarterStart, -3 )

    VAR PreviousQuarterEnd =
    CurrentQuarterStart - 1

    RETURN
    SWITCH (
    SelectedPeriod,
    "Last Qtr",
    CALCULATE (
    [Sales],
    DATESBETWEEN (
    Dates[Date],
    PreviousQuarterStart,
    PreviousQuarterEnd
    )
    ),
    [Sales]
    )

    Then use this measure in the visual instead of the original [Sales] measure.

    For example, if today is 5/22/2026, the current quarter starts on 4/1/2026, so the previous completed quarter is 1/1/2026 to 3/31/2026, which is Q1 2026.

    So the main point is that the slicer should capture the user’s choice, but the actual date filter should be applied either through a proper date mapping table/relationship or through the measure used in the visual.

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • To identify whether a date falls within the last quarter relative to the current date, the calculation must reference the current date and then derive the date range for the previous quarter. Below is a sample calculated table that includes a column implementing this logic.

    Dates = 
    VAR _today =
        TODAY ()
    VAR _startCurrentQ =
        DATE ( YEAR ( _today ), ( QUARTER ( _today ) - 1 ) * 3 + 1, 1 )
    VAR _startLastQ =
        EDATE ( _startCurrentQ, -3 )
    VAR _endLastQ =
        EOMONTH ( _startLastQ, 2 )
    RETURN
        ADDCOLUMNS (
            CALENDAR ( DATE ( 2025, 1, 1 ), _today ),
            "YYYYMM", FORMAT ( [Date], "YYYYMM" ), 
            "IsLastQuarter",
                IF ( [Date] >= _startLastQ && [Date] <= _endLastQ, "Last Qtr" )
        )
    

     

     

     

5 Replies

  • Hi UncleLewis 

    The issue is that the slicer item only gives the user a selection. It does not automatically translate “Last Qtr” into the correct date range for the chart unless the slicer table is connected to the Date table in a way that actually filters the visual.

    PREVIOUSQUARTER is also context-dependent. In a calculated table, it is evaluated when the table is calculated/refreshed, not dynamically based on the visual context. That is why PREVIOUSQUARTER(DATESYTD(Dates[Date])) can return Q4 2025 instead of Q1 2026.

    If you want “Last Qtr” to mean the last completed quarter relative to today, I would usually use a disconnected period slicer and apply the logic inside the measure used by the stacked column chart.

    For example, create a simple slicer table with values such as “All” and “Last Qtr”. Then create a measure like this:

    Sales Selected Period =
    VAR SelectedPeriod =
    SELECTEDVALUE ( 'Period Slicer'[Period], "All" )

    VAR RefDate =
    TODAY()

    VAR CurrentQuarterStart =
    DATE (
    YEAR ( RefDate ),
    3 * INT ( ( MONTH ( RefDate ) - 1 ) / 3 ) + 1,
    1
    )

    VAR PreviousQuarterStart =
    EDATE ( CurrentQuarterStart, -3 )

    VAR PreviousQuarterEnd =
    CurrentQuarterStart - 1

    RETURN
    SWITCH (
    SelectedPeriod,
    "Last Qtr",
    CALCULATE (
    [Sales],
    DATESBETWEEN (
    Dates[Date],
    PreviousQuarterStart,
    PreviousQuarterEnd
    )
    ),
    [Sales]
    )

    Then use this measure in the visual instead of the original [Sales] measure.

    For example, if today is 5/22/2026, the current quarter starts on 4/1/2026, so the previous completed quarter is 1/1/2026 to 3/31/2026, which is Q1 2026.

    So the main point is that the slicer should capture the user’s choice, but the actual date filter should be applied either through a proper date mapping table/relationship or through the measure used in the visual.

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Hello UncleLewis,

    PREVIOUSQUARTER() is using the current filter context, not today’s date. So if your model’s last date is in 2025, it will naturally return Q4 2025.

    The issue with DATESYTD() is that it creates a non-continuous date set, which breaks how time-intelligence functions like PREVIOUSQUARTER() evaluate dates.

    Make sure your Date table is continuous and marked as a proper Date table, then just use:

    PREVIOUSQUARTER(Dates[Date])

     

  • To identify whether a date falls within the last quarter relative to the current date, the calculation must reference the current date and then derive the date range for the previous quarter. Below is a sample calculated table that includes a column implementing this logic.

    Dates = 
    VAR _today =
        TODAY ()
    VAR _startCurrentQ =
        DATE ( YEAR ( _today ), ( QUARTER ( _today ) - 1 ) * 3 + 1, 1 )
    VAR _startLastQ =
        EDATE ( _startCurrentQ, -3 )
    VAR _endLastQ =
        EOMONTH ( _startLastQ, 2 )
    RETURN
        ADDCOLUMNS (
            CALENDAR ( DATE ( 2025, 1, 1 ), _today ),
            "YYYYMM", FORMAT ( [Date], "YYYYMM" ), 
            "IsLastQuarter",
                IF ( [Date] >= _startLastQ && [Date] <= _endLastQ, "Last Qtr" )
        )
    

     

     

     

  • v-dineshya's avatar
    v-dineshya
    Icon for Community Support rankCommunity Support

    Hi UncleLewis ,

    Thank you for reaching out to the Microsoft Community Forum. could you please try the proposed solutions shared by  danextian , Olufemi7  and Ritaf1983 ? Let us know if you’re still facing the same issue we’ll be happy to assist you further.

     

    Regards,

    Dinesh

    • v-dineshya's avatar
      v-dineshya
      Icon for Community Support rankCommunity Support

      Hi UncleLewis ,

      We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

       

      Regards,

      Dinesh