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

YTD measure

Hello, 

 

Hope you're doing well.

 

Is there anay way to filter data using time intelligence ? I want to calculate the sum of the sales of last year starting from the 1st january 2019 until the a complete month. Lets pretend we are still in august, I want to cumulate the sales and compare oranges to oranges (Sales from 1st Jan 2019 to 31st Aug 2019 vs Sales from 1st Jan 2020 to 31st Aug 2020) and make it automatic by using a calendar table.

 

Happy new year.

 

Regards,

 

Othman

 

 

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table and establish a relationship from the Date column in your base data table to the date column in your Calendar Table.  In the Calendar Table, write calculated column formulas to extract Year, Month Name and Month number.  Sort the Month Name column by Month number.  Create 2 slicers - one for Year and another for Month Name.  In the Year slicer, select 2020 and in the Month Name slicer, select August.  Write these measures

Measure 1 = sum(data[sales])

Measure 2 = calculate([measure 1],datesytd(calendar[date],"31/12"))

Measure 3 = calculate([measure 2],sameperiodlastyear(calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Anonymous , use this in return, if date table is not in context

return
 CALCULATE(Sales[Sales],DATESYTD(DATEADD('Date'[Date],-1,YEAR)),'Date'[Date]<=_max)
amitchandak
Super User
Super User

@Anonymous , You might have force it by today, max date or selected date,

 

YTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('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
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)

 

YTD QTY forced=
var _max = maxx('order',[Order date])
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('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)

 

in place of today or maxx('order',[Order date])

you can take selected date maxx(allselected('Date'), 'Date'[Date])

Anonymous
Not applicable

Hi @amitchandak,

 

It shows me blank. I've done something wrong ?Capture d’écran 2020-12-29 162203.jpg

Hi @Anonymous ,

 

You could also refer to this blog:

https://www.kasperonbi.com/get-the-ytd-of-the-same-period-last-year/ 

 

Happy new year.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@Anonymous - So yes you can use things like PARALLELPERIOD or DATEADD. You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.