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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
verschug
New Member

Excel Power Pivot - issue Function SAMPLEPERIODLASTYEAR only works with contiguous date selections

Hi all,

I have an error: Function SAMPLEPERIODLASTYEAR only works with contiguous date selections.

 

I have a sales table with monthly sales data for 3 years. 

I have added a date table. And added the relationship.

verschug_0-1738925709064.png

I created measures:

sqm:=sum([Surface])

sqm_prev_year:=CALCULATE([sqm];SAMEPERIODLASTYEAR('Calendar'[Date]))

 

Both measures are working fine when I use Year as row.

Or Year as column and YYYY-MM as row. 

verschug_1-1738925941740.png

But I need year as columns and month number as row. So I would have only 12 rows for the 12 months. Adding the month number to the pivot table results in following error. Calculation error in measure Function SAMPLEPERIODLASTYEAR only works with contiguous date selections.

verschug_2-1738926072610.png

What is the problem? 

Kr, Guy Verschueren

 

 

 

 

 

 

4 REPLIES 4
verschug
New Member

Hi danextian,

* I also just noticed that the Grand Total for the measure sqm_prev_year does not summarize but is the data of the last mont. Can this be solved? 

verschug_0-1739185995795.png

Kind regards, Guy

Anonymous
Not applicable

Hi @verschug ,

 

danextian's workaround is great.

Could you please tell us if you have solved your problem?

If so, it's good to accept the reply as solution. More people will benefit from it because of this.

If not, please feel free to tell us.

 

Best Regards,
Stephen Tao

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

danextian
Super User
Super User

Hi @verschug 

Try this formula:

=CALCULATE (
    [Total Revenue],
    FILTER (
        ALL ( DatesTable ),
        DatesTable[Year]
            = MAX ( DatesTable[Year] ) - 1
            && DatesTable[Month Short] = MAX ( DatesTable[Month Short] )
    )
)

 

danextian_1-1738943164017.png

Please see the attached excel file.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi danextian,

 

This solution works fine for the measure "sql_last_year".  Thanks. 

 

But I still have another similar problem in my report.

I have a measure to calcualate the YTD value

=> sqm_YTD:=CALCULATE([sqm];DATESYTD('Calendar'[Date]))

And also a measure to calucalate the prev year YTD value

=> calculate sqm_YTD_PrevY:=CALCULATE([sqm_YTD];SAMEPERIODLASTYEAR('Calendar'[Date]))

And this last one also gives the same error concerning the SAMEPERIODLASTYEAR. 

* Do you also know an alternative formula? 

* Do you know why these measures are not working anymore, while they did work fine in the past?

 

Kind regards, Guy 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.