Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ptmuldoon
Resolver I
Resolver I

SAMEPERIODLASTYEAR Contigous Date Issue

I am receiving a "only works with contigous data selections" when using the SAMEPERIODLASTYEAR function, and can't seem to figure out what is causing it.  Varous google searches seem to always suggest making sure all dates are there and a 1 to many relationship, which I do have.

 

I have a calendar table that is complete with no gaps or duplicates.  That calender table is actually being made via power query like such:

let
    //StartDate = #date(2019,1,1),
    StartDate = Date.FromText(Number.ToText(StartYear) & "0101"),
    EndDate = Date.AddMonths(StartDate,60),
    //EndDate = List.Max(PSData[Date]),
    NumberOfDays = Duration.Days(EndDate-StartDate)+1,

    DatesList = List.Dates(StartDate, NumberOfDays, #duration(1,0,0,0)),
    // Convert the list of dates to a table
    CalendarTable = Table.FromList(DatesList, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(CalendarTable,{{"Date", type date}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([Date]), Int64.Type),
    #"Inserted Quarter" = Table.AddColumn(#"Inserted Month", "Quarter", each Date.QuarterOfYear([Date]), Int64.Type),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Quarter", "Day of Week", each Date.DayOfWeek([Date]), Int64.Type),
    #"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Week", "Day Name", each Date.DayOfWeekName([Date]), type text),
    #"Inserted End of Month" = Table.AddColumn(#"Inserted Day Name", "End of Month", each Date.EndOfMonth([Date]), type date),
    #"Inserted Day of Year" = Table.AddColumn(#"Inserted End of Month", "Day of Year", each Date.DayOfYear([Date]), Int64.Type),
    #"Inserted Week of Year" = Table.AddColumn(#"Inserted Day of Year", "Week of Year", each Date.WeekOfYear([Date]), Int64.Type)
in
    #"Inserted Week of Year"

 

My Calendar table has a 1 to many relationship to a data table.

 

ptmuldoon_0-1702309773136.png

 

And my DAX measures trying to compute the YTD Variance between this year and last year.

 

YTD Amount:=TOTALYTD ( 
      [Amount],
       'Calendar'[Date],
       "12/31"
)

YTD Amt Var to LY:=[YTD Amount] - 
	CALCULATE (
		[YTD Amount], SAMEPERIODLASTYEAR('Calendar'[Date]
		)
	)

 

And when I try to use the YTD Amt measure with a filtered date of January to November (excluding Dec), I get the contiguous date error message?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ptmuldoon You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
ptmuldoon
Resolver I
Resolver I

Well, very strange.

 

I ended up just deleting and redoing the relationship.  And then a refresh of data, and it worked.

Greg_Deckler
Super User
Super User

@ptmuldoon You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.