Forum Discussion

Waseem's avatar
Waseem
Icon for Helper III rankHelper III
1 year ago
Solved

YTD for current and Last Year

Dear Community   I am stuck up on YTD calculation for a couple of days despite following previous posts/suggestions from experts.  I have data table with calculated date filed and values for some ...
  • v-hashadapu's avatar
    1 year ago

    Hi Waseem , Thank you for reaching out to the Microsoft Community Forum.

     

    Make sure you have a dedicated Date Table with a continuous range of dates that covers your data. If you don’t have one yet, create it. Once created, add useful columns like Year, Month, and MonthName. Go to the Modeling tab -> choose Mark as Date Table and select the Date column. Next, ensure there's an active relationship between the Date column in your fact table and the Date column in this Date Table. You can check and configure this in the Model view.

    Example DAX for date table: Date = CALENDAR(DATE(2020,1,1), DATE(2025,12,31))

     

    Make sure any slicers, especially those used to select a time period are built using columns from the Date Table, not from your fact table. If your slicer uses the fact table’s date or just the month name, Power BI will limit the filter context to that exact selection, breaking the expected YTD behaviour.

     

    Now, create your YTD measure using a standard time intelligence function like DATESYTD, which understands the year structure. Example:

    Sales_YTD_Advanced =

    CALCULATE(

        SUM('FactTable'[Value]),

        DATESYTD('Date'[Date]),

        ALLSELECTED('Date'[Month])

    )

     

    This measure should sum up all values from January 1 of the selected year up to the latest date in your selection.

     

    If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
    Thank you.