Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
I am playing around in the Adventure Works PBIX. One scenario I am testing is when the dates don't align exactly in the fact table. For example, I edited the fact table and deleted all the rows for Bikes sales in June 2020 (the latest month of sales). This means that Bikes don't have any June 2020 sales loaded as of yet while the other Categories do.
Now, I want to create a YTD chart that plots against the prior year. I can easily create the following measures:
Sales_YTD_1 = CALCULATE(SUM('Sales'[Sales Amount]), DATESYTD('Date'[Date]))
Sales_PY_YTD_1 = CALCULATE(SUM('Sales'[Sales Amount]), SAMEPERIODLASTYEAR(DATESYTD('Date'[Date])))
The next thing I do is create an unconnected copy of the Date table and a new column simply Year = YEAR('Date'[Date]). Then, I created the following plot using the above two measures in the Y-axis and Month from the unconnected Date table for the X-axis with a filter applied to the chart on Year = 2020. I also have a slicer on the page for Category.
Now, there are a couple of things I don't like about this plot.
1. I don't like the way the Sales_YTD_1 flatlines for the rest of the year.
2. I don't like how I have to hard code the value 2020 in the filter on Year
So, I decided to create my own DATESYTD function, if you will. First, I created a measure that will return the MAX OrderDateKey from the fact table that is filter-context sensitive (important since the Bikes no longer have orders past May 2020). Next, I created a measure that returns the year of the MAX OrderDateKey:
LatestOrderDateKey = MAX('Sales'[OrderDateKey])
LatestOrderDateYear = MAXX(FILTER('Date', [DateKey] = [LatestOrderDateKey]), [Year])
And, they both work as expected.
Next, I updated my Sales_YTD_1 measure with the following:
It sort of works. No more flat lining. So, that is good. But, it is no longer cumulative and I don't understand why. In fact, I don't understand what it is about DATESYTD inside CALCULATE that even tells it to do a cumulative summation. I tried wrapping YTD_Months with DATESYTD() but that just breaks it.
Furthermore, PowerBI won't let me enter a measure as a filter value for my chart. So, I don't know how to make the Year filter dynamic and tied to the measure I created.
Maybe I am doing this all wrong. As always, any help is greatly appreciated!
Solved! Go to Solution.
@WishAskedSooner try something like this, replace table and column names as per your model
YTD Last Transaction Date =
VAR __LastTransactionDate = CALCULATE ( MAX ( Sales[OrderDate] ), ALL () )
RETURN
CALCULATE (
[Sales],
DATESYTD (
CALCULATETABLE (
VALUES ( 'Calendar'[Date] ),
KEEPFILTERS (
'Calendar'[Date] <= __LastTransactionDate
)
)
)
)
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@WishAskedSooner try something like this, replace table and column names as per your model
YTD Last Transaction Date =
VAR __LastTransactionDate = CALCULATE ( MAX ( Sales[OrderDate] ), ALL () )
RETURN
CALCULATE (
[Sales],
DATESYTD (
CALCULATETABLE (
VALUES ( 'Calendar'[Date] ),
KEEPFILTERS (
'Calendar'[Date] <= __LastTransactionDate
)
)
)
)
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@parry2k , thank you so very much for your thoughtful reply. I am marking it as a solution. I had to make some edits to get it working properly in my model. Here is the final measure that I came up with using your example:
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the September 2025 Power BI update to learn about new features.