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
Harry_Tran
Helper III
Helper III

YTD vs Last Year YTD

Hi everyone,

I need to compare TotalSale YTD vs TotalSale Last Year YTD.

For exmple, if today is Jan 18 2022, then I would like to compare TotalSale this year from 1/1/2022 to 1/17/2022 to TotalSale Last Year from 1/1/2021 to 1/17/2021.

 

My mesure are:

TotalSale YTD = TOTALYTD ([Totalsale], DATESYTD (CALENDAR[Date])

TotalSale LY YTD = CALCULATE ([TotalSale YTD], SAMEPERIODLASTYEAR (CALENDAR[Date])

 

Thank you

 

The issue that I have is when I apply these measures above to te metric (regions as rows and date as columns) , the TotalSale LY YTD would be the Sum of whole last year and TotalSale YTD shows the right number for current year but it shows the total for last year

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Harry_Tran ,

I created some data:

vyangliumsft_0-1642748220710.png

Here are the steps you can follow:

1. Create measure.

TotalSale YTD =
CALCULATE(SUM('Table'[rand]),FILTER(ALL('Table'),'Table'[Date]>DATE(YEAR(TODAY()),1,1)&&'Table'[Date]<TODAY()))
TotalSale LY YTD =
CALCULATE(SUM('Table'[rand]),FILTER(ALL('Table'),'Table'[Date]>DATE(YEAR(TODAY())-1,1,1)&&'Table'[Date]<DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))))

2. Result:

vyangliumsft_1-1642748220713.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Harry_Tran ,

I created some data:

vyangliumsft_0-1642748220710.png

Here are the steps you can follow:

1. Create measure.

TotalSale YTD =
CALCULATE(SUM('Table'[rand]),FILTER(ALL('Table'),'Table'[Date]>DATE(YEAR(TODAY()),1,1)&&'Table'[Date]<TODAY()))
TotalSale LY YTD =
CALCULATE(SUM('Table'[rand]),FILTER(ALL('Table'),'Table'[Date]>DATE(YEAR(TODAY())-1,1,1)&&'Table'[Date]<DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))))

2. Result:

vyangliumsft_1-1642748220713.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Ashish_Mathur
Super User
Super User

Hi,

ENsure that the Calendar Table goes only till today, not till December 31, 2022.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
OwenAuger
Super User
Super User

Hi @Harry_Tran 

I suggest you follow the approach discussed in this article:

https://www.sqlbi.com/articles/hiding-future-dates-for-calculations-in-dax/

 

The short description is:

1. Add a DatesWithSales column to your CALENDAR TABLE (adjust column names as required):

DatesWithSales =
    'CALENDAR'[Date] <= MAX ( Sales[Date] )

 2. Rewrite any time intelligence measures in this sort of form, using TotalSale LY YTD as an example:

(I have put all the date shifting in one measure rather than referencing TotalSale LY)

TotalSale LY YTD =
CALCULATE (
    [Totalsale],
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DATESYTD ( 'CALENDAR'[Date] ) ),
        'CALENDAR'[DatesWithSales] = TRUE
    )
)

 

Does this work for you? 

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
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.