Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ignasivb
Regular Visitor

YTD calculation not working properly

Hi all,

 

I am trying to make a very simple exercise with a verys imple model using the TOTALYTD DAX formula but there is something not working properly for me.

 

I have created the following measure: 

YTDSales = TOTALYTD(SUM(OrderDetail[Sales]), OrderHeader[OrderDate])
 
When I use it in a simple table, adding OrderDate as a field and not as a hierarchy, plus my new KPI, it works fine (please see screenshot 1 below). However, when I use OrderDate as a hierarchy, it simply doesn't (see screenshot 2).
 
Same applies to other visualizations. If I create a line chart with the OrderDate as a field (thus having all the values day by day) the calculation works fine, but if I try to group it by, say, months, again the YTD logic is not working whatsoever.
 
Any ideas on what am I doing wrong? I would like to understand where is my mistake and also how can I fix.
 
Here is the pbix file in case it helps.
 
Thank you very much.
 
 
Screenshot 1Screenshot 1Screenshot 2Screenshot 2
 
 
2 ACCEPTED SOLUTIONS

That was very helpful! So apparently all that I was missing to make my thing work is to add ".[Date]" to my formula. Tried it and worked like a charm. Thanks!

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the OrderDate column to the Date column of the Calendar Table.  In the Calendar Table, write calculated column formulas to extrat Year, Month name and Month number.  Sort the Month name by the Month number.  To every visual/filter, drag any date related field only from the Calendar Table.  Write these measures:

Measure =  SUM(OrderDetail[Sales])

YTD measure = calculate([measure],datesytd(Calendar[Date]),"31/12")

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ignasivb
Regular Visitor

Thank you all for your messages. Does this mean I cannot use the TOTALYTD function unless I visualize the information at a date level (i.e. I cannot use it in a table grouping sales by month)?

it is possible like this:

2023-02-18_22-55-07.png

Ahmedx
Super User
Super User

Is this what you are looking for?
https://dropmefiles.com/4jfWh
2023-02-18_20-37-54.png2023-02-18_20-37-07.png2023-02-18_21-01-03.png

Padycosmos
Solution Sage
Solution Sage

That was very helpful! So apparently all that I was missing to make my thing work is to add ".[Date]" to my formula. Tried it and worked like a charm. Thanks!

sudhav
Helper V
Helper V

I think you have to use ALL function. just try it, i am not sure.

YTDSales = TOTALYTD(SUM(OrderDetail[Sales]), ALL(OrderHeader[OrderDate]))

 

If I answered your question, accept it as solution and give kudos!

FreemanZ
Super User
Super User

hi @ignasivb 

Because TOTALYTD = CALCULATE + DATESYTD. In case of date hierarchy, you would need CALCULATE + DATESMTD, or CALCULATE + DATESQTD, so TOTALYTD is the same.

Hi @FreemanZ ,

 

Not sure how to apply this. I tried this measure and it won't work either:

 

ytd3 = CALCULATE(SUM(OrderDetail[Sales]), DATESYTD(OrderHeader[OrderDate]))

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.