Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
o59393
Post Prodigy
Post Prodigy

Calculate YTD for Previous Year

Hi all

 

I need to calculate the YTD from PY, in this case from Jan 2021 to Aug 2021.

 

The table is the following:

 

PlacePeriodUnits
A1/1/2021         19,652,771
A2/1/2021         22,247,912
A3/1/2021         25,950,207
A4/1/2021         20,442,619
A5/1/2021         18,639,247
A6/1/2021         28,158,195
A7/1/2021         22,852,969
A8/1/2021         23,274,828
A9/1/2021         28,972,763
A10/1/2021         23,825,102
A11/1/2021         25,176,135
A12/1/2021         36,040,867
A1/1/2022         24,884,169
A2/1/2022         25,043,001
A3/1/2022         30,881,156
A4/1/2022         25,377,539
A5/1/2022         25,415,291
A6/1/2022         31,557,732
A7/1/2022         24,007,911
A8/1/2022         22,339,903

 

The solution would be:

 

o59393_0-1659981602910.png

 

 

 

The measures I have are:

 

Units YTD = calculate(SUM(Units),DATESYTD(Query1[Period)])
 
Units YTD PY= CALCULATE([Units YTD],SAMEPERIODLASTYEAR(Query1[Period]))
 
For the Units YTD PY measure, I am getting the full 2021 result which is incorrect.
 
How can I get it ok?

Thanks.
3 REPLIES 3
lbendlin
Super User
Super User

- in your calendar table add a column "IsPastPY"  that tags which months should be considered.  (test if the date is older that one year before today)

- add that tag as a filter. 

 

Units YTD PY= CALCULATE([Units YTD],SAMEPERIODLASTYEAR(Query1[Period]),IsPastPY=TRUE())

 

- make sure your calendar table is in import mode and is refreshed frequently (daily/)

Hi @lbendlin 

 

The datasource is a SQL file with thousands of rows that I can't edit and also contains all the data, no calendar table. Adding a column would add memory to the BI I think.

 

Is there any way to do it without adding columns?


Thanks!

Those are not valid reasons. Always have a calendar table in your data model.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.