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
ton-v
Frequent Visitor

Same period last year

Hello everyone,

 

i have searched already in several forums but i didnt find what i need.

 

i have 3 tables

 

one for budget, one sales and a date tabes ( unique rows) and marked as date table

 

I want to calculate YTD and PY values : 

 

YTD: =calculate(sum(sales),datesytd(dates)) working easy fine

 

PY : =CALCULATE([YTD];SAMEPERIODLASTYEAR(Dates[Date])) not working

 

YTD claculates until the month of mai which is normal but for PY i get the YTD of the whole year but i want also until Mai 2019.

 

I dont want to put slicers on my graf.

 

my graf is like that 

 

POS | YTD values | PY values | Budget YTD

 

 

i really dont want to put slicer because that would just mean that sameperiodlastyear is useless.

 

The question :

 

How can i calcualte YTD PY for the same periods as actual year ?

Thank you in advance 

1 ACCEPTED SOLUTION
ton-v
Frequent Visitor

Here is the solution :

 

1) Create mesure to find max month 

2) PY:=Var MaxMonth = [max month ytd]
return(
CALCULATE([YTD];DATEADD(Dates[Date];-1;YEAR);'BDD Global SAP'[MonthNumber]<=MaxMonth))

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@ton-v , Try training measure or Last YTD

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

YTD QTY = TOTALYTD(Sum('order'[Qty]),'Date'[Date])
LYTD QTY = TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year))
Previous Year = CALCULATE(SUM('order'[Qty]), PREVIOUSYEAR('Date'[Date]))


YTD QTY forced= 
var _max = today()
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max = date(year(today())-1,month(today()),day(today()))
return
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)


YTD QTY forced= 
var _max = maxx('order',[Order date])
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max1 =maxx('order',[Order date])
var _max = date(year(_max1)-1,month(_max1),day(_max1))
return
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)

//Only year vs Year, not a level below

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Sorry i tried but this does not work.

 

The py is showing me the whole year and i dont want the whole year.

 

as said before i could slice months but i donth one to use slicers.

 

I have on a table sales for 2020 until Mai and the whole year 2019.

 

YTD is working normaly .

 

But for PY i get the whole year 2019 but i dont want the whole year i want sales from january 2019 to max month 2020 .

 

Btw thank you for your respons and yes i have a data table and marked it as data table. my data table is from 01.01.2016 to 31.01.2021

 

ton-v
Frequent Visitor

Here is the solution :

 

1) Create mesure to find max month 

2) PY:=Var MaxMonth = [max month ytd]
return(
CALCULATE([YTD];DATEADD(Dates[Date];-1;YEAR);'BDD Global SAP'[MonthNumber]<=MaxMonth))

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.