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
AliH
Frequent Visitor

DAX YTD Help

Hi All,

 

I'm struggling to figure out how to do a bespoke YTD calculation, essentially what we are trying to achieve is that for any given filter year, display the equivalent YTD for that year.

For examples:

 20152016201720182019
 Turnover £Turnover YTD £Turnover £Turnover YTD £Turnover £Turnover YTD £Turnover £Turnover YTD £Turnover £Turnover YTD £
Product 11005020010015075300150350350
Product 2402050251005018090200200
Product 320020030022540028080075010001000

 

So for the current year the Turnover £ and YTD £ will be the same, but for previous years it will be the equivalent time period for the filter year.

Here are the current measures:
Turnover £:=Orders[Order Value]-Credits[Credit Value]

I think I need my YTD measure to be something like CALCULATE(Orders[Turnover £], Dates[DayofYear] <= lastdate(Orders[Invoice Date])) But obviously this isn't how it is done.

 

Does anyone have any pointers please?

 

Thanks you in advance,

 

Alister

 

6 REPLIES 6
TomMartens
Super User
Super User

Hey,

 

I recommend to start with this article, almost everything timerelated is covered here: https://www.daxpatterns.com/time-patterns/

 

Regards,Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

 

Thanks for the response. I've read through that before and it is a great article. What I found there only worked for the current year, but when another year was the filter, the measure displayed all of that year, instead of the equivalent YTD - I maybe should have changed the title of this post.

 

I'll have another read and see what I can figure out. I was hoping that this was a common one with an obvious answer I am missing.

 

Many thanks,

 

Alister

Anonymous
Not applicable

Hi there.

 

Mate, if you say YTD, it's obvious that the total value of any measure for the whole year will be equal to the YTD (of the measure in question) for the same year. This follows from the very definition of YTD. So, either you want to calculate something different than YTD or... you should give us a clear example of what it is you want.

 

Otherwise, we'll be chasing our tail, so to speak.

 

Best

Darek

Hi Darek,

I probably could have explained it better, but I don't know the term _equivalent YTD period_. So the equivalent time period that would be YTD this year, 1st Jan to 3rd July (at time of posting), for ny selected year.

The following is almost there:

 

CALCULATE ( [Turnover £], DATESBETWEEN ( Dates[Date], FIRSTDATE(Dates[Date]), DATE(YeaR(max(Dates[Date])),month(today()),day(today())) ) )

 

I'm now working on trying to amend the dateto in the datesbetween function to be using a constant date based on the lastdate of another datefield. CALCULATE(LASTDATE(Orders[Invoice Date]), ALL....)) but it isn't working quite right yet.

Many thanks,

 

Alister

Anonymous
Not applicable

I guess you want something like this:

[YTD with TODAY shifted as upper limit] :=
var __today = TODAY()
var __todaysYear = YEAR( __today )
var __visibleYear = SELECTEDVALUE( 'Dates'[Year] )
var __oneYearVisible = HASONEVALUE( 'Dates'[Year] )
var __numberOfYearsBackFromToday = __todaysYear - __visibleYear
var __upperDayLimit = EDATE( __today, -12 * __numberOfYearsBackFromToday ) 
var __ytd =
    CALCULATE(
        [My Measure],
        DATESYTD( 'Dates'[Date] ),
        'Dates'[Date] <= __upperDayLimit
    )
return
    if( __oneYearVisible, __ytd )

Best

Darek

Thanks, I'll dissect and have a go.

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