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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
fb198
Regular Visitor

Same Period Last Year breaks with non contiguous month values

Hi,

I'm trying to calculate the previous year's sales for selected months of the current year.
My LY Sales measure looks like this:
CALCULATE( [Total Sales], SAMEPERIODLASTYEAR(Calendar_Table[Date]))

I have Year and Month slicers on the page. When I choose a single month the measure works perfectly, or even months in continuity (Oct, Nov, Dec). However when I choose non continuous values like July and December, the measure breaks.

It should normally just be picking the previous year sales of the selected months and adding it up. Do you know what is the issue here and how it can be solved?

6 REPLIES 6
Anonymous
Not applicable

Hi @fb198 , hello speedramps  and johnt75, thank you for your prompt reply!

Based on your description, I have created a sample PBIX file for your reference.

vyajiewanmsft_0-1737437023165.png

Please check the attached file to see if it provides any clues for troubleshooting.

 

If you need further assistance, feel free to ask!

 

Best regards,

Joyce

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

 

speedramps
Super User
Super User

@fb198 

I am not convinced you are providing us with with the correct relationship because the error message says you have bidirectional relationship.

 

speedramps_0-1737389729802.png

 

Have you got a list of contigous dates in the calander for TY and LY?

 

I supect you either sending us the wrong relationship, or you have the wrong table column in your visual or there are other DAX measure or filters in your visual.

 

Try create a new report page, with new visual and slicer (dont copy and paste).

Add each item cartefully and try replicate the error.

 

 

 

 

 

 

speedramps
Super User
Super User

Check your relationship between the Calendar and Fact table.

It should be 1:M with Single cross filter direction

 

speedramps_0-1737388429611.pngspeedramps_1-1737388466688.png

 

I suspect you have a 1:1 relationship with Both which causes the contiguos error 

speedramps_2-1737388550010.png

 

speedramps_3-1737388587906.png

 

Please click [accept solution] and thumbs up. Thank you.

Thank you for your reply.

My Calendar table has 1:* relationship with the Sales Table. The calendar is also marked as the Date Table.

fb198_0-1737389272346.png

On choosing a single month

fb198_1-1737389313122.png


When I choose non contiguous months:

fb198_2-1737389337142.png

This is the error I'm seeing.

fb198_3-1737389383350.png

Thanks in advance for any help.

Kind Regards.

johnt75
Super User
Super User

I don't think that the problem is with the SAMEPERIODLASTYEAR function, that can handle discontiguous dates.

First check that your calendar table is marked as a date table, then you can run in DAX Query View

DEFINE
VAR _ThisYear = CALCULATETABLE(
	VALUES( 'Date'[Date] ),
	TREATAS( { DATE( 2025, 1, 1 ), DATE( 2025, 3, 1 ) }, 'Date'[Start of Month] )
)
VAR _LastYear = SAMEPERIODLASTYEAR( _ThisYear )

EVALUATE
ROW(
	"this year", COUNTROWS( _ThisYear ),
	"last year", COUNTROWS( _LastYear ),
	"min last", MINX( _LastYear, 'Date'[Date] ),
	"max last", MAXX( _LastYear, 'Date'[Date] )
)

Obviously you'll need to change the TREATAS to match your model and the dates you're having problems with. You should see the same row count for both this year and last year.

@johnt75  Thanks for the answer but I suspect that the relationship is wrong because it is generating a "contiguos" error.  That suggests it is a problem with the relationship rather than the dax measure. See my suggestion on how to fix it. ๐Ÿ˜€

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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