cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TradSag
Frequent Visitor

SAMEPERIODLASTYEAR not showing all records

Hi Team,
 
I have found a not expected behaviour using SAMEPERIODLASTYEAR function.
 
Context:
 
  • Account table containing fields: Date, Account, Account_Group and Amount fields.
  • Calendar table generated based on Account table Date field. This table is marked as Date table and linked to Account table.

image.png

 
I'm trying to compare the vaule from currently selected date versus previous year same value. For this I'm using SAMEPERIODLASTYEAR function in the following way: 
 
PY_Amount = CALCULATE(Sum('Account'[Amount]);SAMEPERIODLASTYEAR('Calendar'[Date]))
 
Issue:
 
As an example, selecting May 2019, this is the result:
 
image.png
If we check May data separatelly by year 2018 and 2019, we find the following:
 
image.pngimage.png
 
As you can check in the initial image (the one that shows Amount and PY_Amount), we don't find the record corresponding to account 88170000000 marked with a red box in 2018 image.
 
I assume that the record is not shown because we it does not exist in 2019 context, but how can we avoid this behaviour?
 
Thanks for the support,
 
Best regards
 
Best regards
1 ACCEPTED SOLUTION
TradSag
Frequent Visitor

Hi,

 

I have solved the issue.

 

I removed the configuration that makes Calendar table into Date table and use the formula as following:

 

PY_Amount = CALCULATE(Sum('Account'[Amount]);SAMEPERIODLASTYEAR('Calendar'[Date].[Date]))
 
Adding .[Date] option makes the issue to be resolved.
 
Thanks and regards

View solution in original post

3 REPLIES 3
TradSag
Frequent Visitor

Hi,

 

I have solved the issue.

 

I removed the configuration that makes Calendar table into Date table and use the formula as following:

 

PY_Amount = CALCULATE(Sum('Account'[Amount]);SAMEPERIODLASTYEAR('Calendar'[Date].[Date]))
 
Adding .[Date] option makes the issue to be resolved.
 
Thanks and regards
vanessafvg
Super User
Super User

try putting an all in

 

test =
CALCULATE (
    SUM ( 'Account'[Amount] ),
    ALL ( 'Calendar'[Date] ),
    SAMEPERIODLASTYEAR ( 'Calendar'[Date] )
)




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hi,

 

Thanks for the answer.

 

Unfortunately, this is not working. I'm getting same the exactly the same result.

 

Any ideas?

 

Thanks and regards

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors