Forum Discussion

willatkinson's avatar
willatkinson
Icon for Helper II rankHelper II
8 months ago
Solved

Previous YTD measure

Hi,   We have a YTD measure as follows which works perfectly:   Count of Case reference YTD = TOTALYTD(COUNTA('Table'[Case reference]), 'DDT'[Date (DDT)])     How can we create a new measure...
  • Mauro89's avatar
    Mauro89
    8 months ago

    willatkinson Your measure uses TODAY() which gives a fixed date, so it returns the same value regardless of the visual context. To make it work month-by-month in a visual, you need to use the date context from your visual instead of TODAY().

    Replace with this:

    Count of Case reference Previous YTD = 
    CALCULATE(
        COUNTA('Table'[Case reference]),
        FILTER(
            ALL('DDT'[Date (DDT)]),
            YEAR('DDT'[Date (DDT)]) = YEAR(MAX('DDT'[Date (DDT)])) - 1 &&
            'DDT'[Date (DDT)] <= DATE(
                YEAR(MAX('DDT'[Date (DDT)])) - 1, 
                MONTH(MAX('DDT'[Date (DDT)])), 
                DAY(MAX('DDT'[Date (DDT)]))
            )
        )
    )

    How this works:

    • MAX('DDT'[Date (DDT)]) gets the current date from your visual's filter context
    • For each month in your visual, it calculates YTD for that same month in the previous year
    • Example: If looking at March 2025, it shows Jan-Mar 2024

       

    To use in a visual:

    • Create a line/column chart
    • X-axis: Month (from your date table)
    • Y-axis: Your new Previous YTD measure
    • Each month will show the cumulative total up to that month in the prior year

    This replaces the static TODAY() with dynamic date context from your visual.

     

     

    Best regards!

    PS: If you find this post helpful consider leaving kudos or mark it as solution

     

  • Ashish_Mathur's avatar
    8 months ago

    Hi,

    Assuming you have a Calendar Table and you have a year slicer and you have months dragged to a Table/Matrix visual

    C = COUNTA('Table'[Case reference])

    YTD C = calculate([C],DATESYTD(Calendar[Date],"31/12"))

    YTD C (PY) = calculate([YTD C],samperiodlastyear(calendar[Date]))

    Hope this helps.