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

TOTALYTD - wrong results

Hello community,

I was interested in "how to calculate year-to-date sales more efficient". Until today, I always said something like this: 

MaxDate = 29.09.2020

YearStart = 01.01.2020

Calculate(Sum(Sales), Filter( YearStart<=Date <= MaxDate))

 

But there must be a more elegant way to do this. I tried the DAX-Functions TOTALYTD & a combination of CALCULATE + DATESYTD like this: 

TOTALYTD

TOTALYTD( CALCULATE (Sum ( 'SALES'[Amount] ) ),'SALES'[Date] ) 

RESULT: Sum up whole year (500 instead of 350 till today)  

 

CALCULATE + DATESYTD

CALCULATE( Sum ( 'SALES'[Amount] ), DATESYTD ( 'SALES'[Date] ) )

RESULT: Sum up whole years (3000 instead of 350 till today)

 

What am I missing? Why is Power BI including all values till year-end and doesn't stop at todays date (29.09.2020)?  Thank you in advance!

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

@Anonymous 

To use Time intelligence functions, you need a Date Table as a Dimension table with continuous dates covering the range of dates in your model.

You then use the Dates Table [Date] field in the expressions instead of your Sales [Date]





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

3 REPLIES 3
PaulDBrown
Community Champion
Community Champion

@Anonymous 

To use Time intelligence functions, you need a Date Table as a Dimension table with continuous dates covering the range of dates in your model.

You then use the Dates Table [Date] field in the expressions instead of your Sales [Date]





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi PaulDBrown, 

 

thanks. Now, it calculcates the running total. But still till the end of year and not ytd.

 

Is a flag or explicit definition of todays date mandatory

 

1.PNG     2.PNG

I'd expect that the calculation ends up here...

@Anonymous 

Yes, if you want the measure to stop at Today's date you need to specify it (otherwise it will return the values included in the filter context). 
One way of doing this is:

today cutoff =
IF(MAX(Date[Date]<= TODAY(), [Sales Ytd TotalYtd])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






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.