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
Anonymous
Not applicable

Custom YTD when end of year changes every year

I have a company calendar that adjusts year end date on the fly at the end of year, every year. Since I could not figure out a way to use that in calculations I made an excel sheet an manually input the calendar there so as to import it as a date table in my model. So far so good.

 

But I can't figure out how to write a custom YTD function for this kind of a calendar. Needless to say as I manually enter more dates in this file the custom YTD should work as well...

 

Since I am using a manual excel sheet as a date table I have no problems in making a Pivot Table filtered on Company Year and Company Month and Company Date - which means the totals in this pivot table will be a YTD. However, I don't know how to make a custom YTD function on this.

 

https://drive.google.com/file/d/10sLR_nDnHtQ-1OHPVuV8wjplH5toKi8g/view?usp=sharing

 

That is a link to my date table in excel.

 

Thanks.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try a formula like this for YTD

 

YTD= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Month] <= Max('Date'[Month]) ))
LYTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Month] <= Max('Date'[Month])))

 

 

If needed use week number in place of month 

 

To use day of year in ytd

create columns 

Year Start date =  minx(filter(Date, [Year] =earlier([Year])),[Date])

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

YTD= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Try a formula like this for YTD

 

YTD= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Month] <= Max('Date'[Month]) ))
LYTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Month] <= Max('Date'[Month])))

 

 

If needed use week number in place of month 

 

To use day of year in ytd

create columns 

Year Start date =  minx(filter(Date, [Year] =earlier([Year])),[Date])

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

YTD= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))

Anonymous
Not applicable

That worked. Thanks!

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.