Forum Discussion

ignasivb's avatar
ignasivb
Regular Visitor
3 years ago
Solved

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 2
 
 

9 Replies

    • ignasivb's avatar
      ignasivb
      Regular Visitor

      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!

  • 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!

  • 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.

  • hi ignasivb 

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

    • ignasivb's avatar
      ignasivb
      Regular Visitor

      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]))
  • ignasivb's avatar
    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)?