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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
priyanath1988
Helper III
Helper III

SAMEPERIODLASTYEAR not working as expected for filtered measure

Hi,

I am trying to create a measure that calculates the "amount" same period last year. Like below 

_A_PY =

var final =CALCULATE( (CALCULATE(SUM('A'[AMOUNT]),'A'[COUNTRY] ="USA")), SAMEPERIODLASTYEAR('calendar'[Date]))

return final

 

however it gives me same values for current and previous year

priyanath1988_0-1674755554857.png

Could you please explain what wrong am I doing?

 

Thanks

Priya

3 REPLIES 3
v-tangjie-msft
Community Support
Community Support

Hi @priyanath1988 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1675146691700.png

(2)We can create a table.

CALENDAR = CALENDAR(DATE(2021,1,1),DATE(2022,12,31))

vtangjiemsft_1-1675146744183.png

 

(2) We can create two measures.

Measure = CALCULATE(SUM(A[Amount]),FILTER('A','A'[Country]="USA"))
_A_PY = CALCULATE('A'[Measure], SAMEPERIODLASTYEAR('CALENDAR'[Date]))

 (3) Then the result is as follows.

vtangjiemsft_2-1675146897486.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

 

Best Regards,

Neeko Tang

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

@v-tangjie-msft Thank you so much for your response. I will apply this and let you know!

ribisht17
Super User
Super User

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.