Forum Discussion

AlB's avatar
AlB
Icon for Community Champion rankCommunity Champion
7 years ago
Solved

SAMEPERIODLASTYEAR(DATESYTD( )) different from DATESYTD(SAMEPERIODLASTYEAR( ))??

Hi all,

This came up as I was trying to answer this post by hbolo (no need to read it to answer this question). Here is the pbix

We have a Date table with dates between 01/01/2018 and today (Jan 3rd, 2019).

We place Date[Date] (down to the day level) in the rows of a matrix visual and these two measures in values:

 

YTDPreviousYearRevenue =
CALCULATE (
    SUM ( Revenue[Revenue] );
    SAMEPERIODLASTYEAR ( DATESYTD ( 'Date Table'[Date] ) )
)
YTDPreviousYearRevenue_2 =
CALCULATE (
    SUM ( Revenue[Revenue] );
    DATESYTD ( SAMEPERIODLASTYEAR ( 'Date Table'[Date] ) )
)

where we are simply calculating the YTD revenue for the previous year.

 

For January 3rd, 2019 (the last day on the Date table),
[YTDPreviousYearRevenue_ 2] yields the correct result (i.e. the revenue for 1-3 Jan 2018).

However, [YTDPreviousYearRevenue] yields an incorrect result: the revenue for 1-31 Jan 2018. [YTDPreviousYearRevenue] is thus considering the full month of January 2018 while the YTD of 2019 is only 1-3 Jan, the first 3 days I would expect both measures to yield the exact same result.

Note that [YTDPreviousYearRevenue] yields the correct result for the 1st and 2nd Jan 2019. The only issue seems to be on the 3rd Jan 2019, the last day on the Date table.

 

Does anybody know what is going on?

Many thanks for your help
 
Note: I suspect it has to do with the Date table finishing on Jan 3rd, 2019 but do not know why. If the Date table is extended to include dates up to the end of 2019 this problem disappears.

  • marcorusso's avatar
    marcorusso
    7 years ago

    This is just another case where the Time Intelligence functions don't work as expected because the Date table is wrong.

    Remember: Time Intelligence functions are guaranteed to work *only* if the Date table is "complete" - meaning you need all the dates until the end of the year.

    Not doing that, what happens is that the year 2019 seems made by 15 days, so if you include all of them than it seems you have an entire month, or an entire year.... You are violating the assumption made by Time Intelligence and you cannot trust any result at that point.

     

20 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity Support
    hi, AlB I asked the Power BI TA team about this question. and if there is any feedback, I'll update it right here. Best Regards, Lin
  • Anonymous's avatar
    Anonymous
    Not applicable

    AlB v-lili6-msft marcorusso Greg_Deckler MFelix 

     

    I am encountering a similiar problem with my data set at the moment, and both of the formulas (attached) here are resulting a value that is until end of month, rather than (ie today up to 08/05/19). I am not sure if the reason for this is that i am using a relationship to connect my data table to a calendar table, as my data is not contiguous, so results in an error when a date slicer is used...

     

    I am using

    LY_YTD Event Type = CALCULATE(COUNT([Event Type]),DATESBETWEEN('Calendar'[Date],FIRSTDATE(DATEADD('Calendar'[Date],-365,DAY)),LASTDATE(DATEADD('Calendar'[Date],-365,DAY))))

     

    and i am getting the correct result, however it is quite ugly and seems to have some bugs,

    ie. if i change the date range to all of 2018, it outputs a value that is the sum of 2018 and 2019 to date..

    Do you know of any other formulas that work for calculating sum of same period last year to the current date?

    I want to be able to create some extra graphs from this and a better formula would be helpful

     

    YTDPreviousYearRevenue =
    CALCULATE (
        SUM ( Revenue[Revenue] );
        SAMEPERIODLASTYEAR ( DATESYTD ( 'Date Table'[Date] ) )
    )
    YTDPreviousYearRevenue_2 =
    CALCULATE (
        SUM ( Revenue[Revenue] );
        DATESYTD ( SAMEPERIODLASTYEAR ( 'Date Table'[Date] ) )
    )