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
stino123
Helper II
Helper II

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

 

Discount YTD PY = CALCULATE([Discount ex VAT],DATESYTD(DATEADD(Kalender[Date],-1,year)))
 
Where the discount function is:
 
Discount ex VAT =
SUMX(FACT_Orders,(FACT_Orders[Discount Amount]/((IF(FACT_Orders[Tax Price]=0,1,1+FACT_Orders[Tax Rate])))))
 
Could someone please explain how to make a YTD PY work? My function will return the full year value of last year rather than the ytd value of previous year.
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @stino123 ,

I created some data:

vyangliumsft_0-1648516589699.png

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:

vyangliumsft_1-1648516589701.png

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

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @stino123 ,

I created some data:

vyangliumsft_0-1648516589699.png

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:

vyangliumsft_1-1648516589701.png

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

stino123
Helper II
Helper 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?

johnt75
Super User
Super User

Try

Discount YTD PY = CALCULATE([Discount ex VAT], SAMEPERIODLASTYEAR(DATESYTD(Kalender[Date])))
amitchandak
Super User
Super 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)

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.

Top Solution Authors