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

Calendar table for YTD and LYTD calculations

Hi,

 

I am trying to implement YTD and LYTD, I have fact table which has invoicedate. Do I still need to create Date Calendar table?

 

I used YTD calculation as like below:

 

YTD  = TOTALYTD(SUM('Sales Objects'[Sales]),'Sales Objects'[invoicedate])  Sales has data for till today and this formula works fine, but I have forecast as well till this year end.

 

YTD  = TOTALYTD(SUM('Sales Objects'[Forecast]),'Sales Objects'[invoicedate]) -- When I use this formula its calculating entire year, it supposed to do till today.

 

Not sure why its differentiates between Sales and Forecast.

 

Thanks,

1 ACCEPTED SOLUTION

Put another way, the formula needs to be told what "Today" is to calculate YTD.  If you don't "tell" it, it will use the max value in your calendar table to compute the YTD value.

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

I would definitely use a separate calendar table and relate your SalesObjects table to it on InvoiceDate. That's how the time intelligence functions were designed to work. There may be something weird going on with the context or something not having a separate date table.


@ 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...
Anonymous
Not applicable

Forecast values are not correct using this formula, still its calculating entire year, not the Year to Day forecast.

 

YTD = TOTALYTD(SUM('Sales Objects'[Forecast]),'Sales Objects'[invoicedate])
YTD = TOTALYTD(SUM('Sales Objects'[Forecast]),'DateKey'[Date])

 

Not sure where is the mistake. any help

 

Thanks,

Do you have a filter/slicer or month or date on rows / columns somewhere in your visual (from Calendar table)?  TOTALYTD internally converts the DAX to the logical equivalent of this and needs to figure out max value in current filter context:

 

 

=
CALCULATE (
    SUM ( 'Sales Objects'[Forecast] ),
    FILTER (
        ALL ( 'DateKey' ),
        'DateKey'[Date] <= MAX ( 'DateKey'[Date] )
            && YEAR ( 'DateKey'[Date] ) = YEAR ( MAX ( 'DateKey'[Date] ) )
    )
)
Anonymous
Not applicable

No, but how this matters as long as formula is bringing right results. I still see the same issue with your fomula as well.

 

Thanks,

Put another way, the formula needs to be told what "Today" is to calculate YTD.  If you don't "tell" it, it will use the max value in your calendar table to compute the YTD value.

Anonymous
Not applicable

I did it exactly and looks working...

Anonymous
Not applicable

I checked without date calendar table and used invoice date from Sales Objects and it is showing correct results. Just wanted to understand what is the point to bring calendar table?

Hi @Anonymous,

Usually, if you use the 'Sales Objects'[invoicedate], it easy to effect by row context and filter context by the table itself. For some intelligence function, which need the continuous date. If you use separate calendar table, it have continuous date without context.

More details for DAX context, plesae review this article.

In addition, please mark the right reply as answer, and welcome to share your workaround, more people will benefit from it.

Thanks,
Aneglia

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.