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
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

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

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.

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.

Top Solution Authors