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
Niels_T
Post Patron
Post Patron

Forced LY YTD measure

Hello,

 

In my previous post I was looking for a measure that would allow me to have LY YTD  in a forced manner, meaning that it would stop counting when it reaches the current dat:e. For example:

 

  • LY YTD: It would show me the LY results of ALL months
    • For example LY April is 200 and May 400. LY YTD shows 200 in April and May in 400 but, I only want it to reveal the 200 in April and not the 400 in May because we aren't in May yet

I used the following measure:

 

Last Year Sales (YTD) =
var _max = eomonth(date(year(today())-1,month(today()),day(today())),0)
return
if(max('Calendar'[Date])<=_max, TOTALYTD(Sum('Credit Memo + Invoice'[Amount]),dateadd('Calendar'[Date],-1,year),'Calendar'[Date]<=_max))
 
However this only displayed LY YTD of the PREVIOUS year and not the current year. So it showed me values in 2020 about the data in 2019.

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Niels_T , In the case of YTD if you select a date then it can work based on that for this year and last year. If you do not select a date you can YTD for each year or LYTD for each year

 

This will control YTD even beyond current year

 

YTD Corrected =
var _max = format(today(),"MMDD")
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),format('Date'[Date],"MMDD")<=_max)

or
YTD Corrected =
var _max = format(today(),"MMDD")
return
if(format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])),blank())

 

 

 

LYTD

 

YTD Corrected =
var _max = format(today(),"MMDD")
return
calculate(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),format('Date'[Date],"MMDD")<=_max)

 

or

 

LYTD Corrected =
var _max = format(today(),"MMDD")
return
if(format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year))),blank())

 

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Niels_T , In the case of YTD if you select a date then it can work based on that for this year and last year. If you do not select a date you can YTD for each year or LYTD for each year

 

This will control YTD even beyond current year

 

YTD Corrected =
var _max = format(today(),"MMDD")
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),format('Date'[Date],"MMDD")<=_max)

or
YTD Corrected =
var _max = format(today(),"MMDD")
return
if(format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])),blank())

 

 

 

LYTD

 

YTD Corrected =
var _max = format(today(),"MMDD")
return
calculate(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),format('Date'[Date],"MMDD")<=_max)

 

or

 

LYTD Corrected =
var _max = format(today(),"MMDD")
return
if(format(max('Date'[Date]),"MMDD")<=_max, calculate(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year))),blank())

 

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.