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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Masaoka
New Member

SAMEPERIODLASTYEAR returns wrong sum when used with "today"

example:

 

- in a run-of-the-mill "orders" table I'm summing "orderedQuantity" over a period of "orderDate".

- orderDate is filtered using a relative filter of "Last 1 month"

- so far so good.

- i also made a measure called "quantity - last year" using sameperiodlastyear (* see below)

- when i sum "quantity - last year", i get bogus (=visibly inflated) numbers.

 

took me some time to figure out that the problem disappears when i exclude today from the date filter. (or when i filter the day using Between and choose the next-to-last day as the end date.)

 

interestingly, when graphed in a chart, the last year totals are always correct - each day's total is displayed correctly (see screen below). the problem is only manifested in a sum, such as on a Card.

 

any idea what i'm doing wrong? or if it is a bug?

 

Further details:

- the exact formula i use is as follows: quantity-LY = CALCULATE(SUM('table'[quantity]), SAMEPERIODLASTYEAR('table'[orderDate])) )

- the table i use is a view in MSSQL, imported data (not live connect)

- here's a screenshot where the problem is apparent: http://prntscr.com/voir5z

1 ACCEPTED SOLUTION

@Masaoka , Time intelligence function need continuous dates, so you use date from the date any date missed will lead to the wrong result or error

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Masaoka
New Member

makes sense.

i still think the app should at least indicate this problem.

 

thanks!

Masaoka
New Member

i see. you're right, that should work.

 

is this a bug? or is using the table's native date hierarchy not recommended for time intel funcions?

 

thanks!

 

@Masaoka , Time intelligence function need continuous dates, so you use date from the date any date missed will lead to the wrong result or error

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Masaoka , Try with date table

Year behind Sales = CALCULATE(SUM('table'[quantity]),dateadd('Date'[Date],-1,Year))
quantity-LY = CALCULATE(SUM('table'[quantity]), SAMEPERIODLASTYEAR('Date'[Date]))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.