Forum Discussion
PY YTD function is not working
Hey All,
I am trying to create last year YTD functions. the function I am trying to use is the following
- Anonymous4 years ago
Hi stino123 ,
I created some data:
Here are the steps you can follow:
1. Create measure.
Measure = CALCULATE( SUM('Table'[amount]), FILTER(ALL('Table'), 'Table'[date]>=DATE(YEAR(MAX('Table'[date]))-1,1,1)&& 'Table'[date]<=DATE(YEAR(MAX('Table'[date]))-1,MONTH(MAX('Table'[date])),DAY(MAX('Table'[date])))))2. Result:
If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
4 Replies
- amitchandakSuper User
stino123 , if you are using year to display or there is no date selected than dates ytd a year behind will give full year
You can force LYTD like
LYTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)
LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date])
var _max = date(year(_today)-1,month(_today),day(_today))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max) - johnt75Super User
Try
Discount YTD PY = CALCULATE([Discount ex VAT], SAMEPERIODLASTYEAR(DATESYTD(Kalender[Date]))) - stino123Helper II
johnt75 thanks for the help, however this returns the full year unfortunately.
amitchandak maybe I am misunderstanding but this returns "blank" while i know there is data LY YTD.Any other suggestions?
- AnonymousNot applicable
Hi stino123 ,
I created some data:
Here are the steps you can follow:
1. Create measure.
Measure = CALCULATE( SUM('Table'[amount]), FILTER(ALL('Table'), 'Table'[date]>=DATE(YEAR(MAX('Table'[date]))-1,1,1)&& 'Table'[date]<=DATE(YEAR(MAX('Table'[date]))-1,MONTH(MAX('Table'[date])),DAY(MAX('Table'[date])))))2. Result:
If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly