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

YTD Comparisons of Current, Last Year and 2 Years Prior with Irregular Calendar Years

I've been trying to get YTD measures to compare the current YTD against last year and 2 years ago YTDs.  I was able to get the current YTD, but have been having trouble with the other two.  2016 is made up of 14 months and goes from Nov 2015 through Dec 2016 and 2015 starts on Nov 2014 through Oct 2015.  

 

I have a table with account data that has dates and sales.  I have also created a calendar table with dates, months, years etc. that's linked to the sales table. I have the following measures:

 

Total Sales = SUM(Sales[Sales])

CY YTD = TOTALYYTD([Total Sales], Sales[Date]) 

 

When I try to get LY YTD, I can't seem to get the amounts from Nov and Dec 2015 to be included.  How can I get the time intelligence functions to adjust to these particular years?  Thanks for your time and help.  

 

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

I downloaded the YTD_test pbix sent by you.

 

The approach I had taken is as under.

 

1.  I changed your Dates table formation as  -  Dates = CALENDAR(MIN(Sales[Date]), MAX(Sales[Date]))

     This is the best way to create a calendar table based on the minimum and maximum date of the fact tables.

 

2.  Created a column called MonthNumber = Month(Dates[Date])

3.  Set the MonthName to sorted by column MonthNumber.

4.  Created a MonthSequentialNumber column

     MonthSequentialNumber = ('Dates'[Year] - MIN( 'Dates'[Year] )) * 12 + 'Dates'[MonthNumber]

    This generates a sequential number for each month and incremented by 1 for every month in the Dates table.

    In the sample file this number ranges from 11 to 45.

    To go back 1 year just need to subtract 12 from this. Similarly to go back 2 years subtract by 24 and so on.

 

5.  Created a measure called

     YTD1YearB4 = Calculate([Total Sales],Filter(ALL(Dates), Dates[Year] = Max(Dates[Year]) - 1  && Dates 

                                          [MonthSequentialNumber] <= Max(Dates[MonthSequentialNumber]) - 12) )

 

6. Created a measure called

    YTD2YearB4 = Calculate([Total Sales],Filter(ALL(Dates), Dates[Year] = Max(Dates[Year]) - 2  && Dates

                                                    [MonthSequentialNumber] <= Max(Dates[MonthSequentialNumber]) - 24) )

 

Depending on the Year selected it will report the 1year before and 2 year before total sales.

 

I have  uploaded the file in one drive. and the link is

 

https://1drv.ms/u/s!ApP3mBZyGaHfzyeQc9QxgrROjsFD

 

If this works for you please accept this as a solution and also give KUDOS.

 

Cheers

 

CheenuSing

 

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

View solution in original post

14 REPLIES 14

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.