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
dokat
Post Prodigy
Post Prodigy

Prior Year Measure

Hi,

 

I have below sample table where i am trying to calculate YoY Volume Sales difference. I tried below formula however it sums up all the values between 2020 thru 2017, not just 2020 value.

 

2020 = CALCULATE(SUM('P&L'[Values]), SAMEPERIODLASTYEAR('P&L'[CALENDAR YEAR]))

2019 = CALCULATE(SUM('P&L'[Values]), SAMEPERIODLASTYEAR('P&L'[CALENDAR YEAR],-2,year))

 

Can anyone have a solve for this problen?

 

Calendar YearCustomerP&LValues
2017ACME MARKETSVolume Sales300396404
2018ACME MARKETSVolume Sales323496404
2019ACME MARKETSVolume Sales457496404
2020ACME MARKETSVolume Sales789189639
2021ACME MARKETSVolume Sales679762927
1 ACCEPTED SOLUTION
bcdobbs
Super User
Super User

Hi,

SAMEPERIODLASTYEAR works with dates ideally in a date table. You however have data already agregated at the year level.

 

So to get the data for 2020 you can just do:

2020Vals = 
	CALCULATE(
		SUM('P&L'[Values]), 
		'P&L'[CALENDAR YEAR] = 2020
	)

 

For something a bit more dynamic:

PreviousYearVals = 

VAR LatestVisibleYear = 
	MAX ( 'P&L'[CALENDAR YEAR] )

RETURN
	CALCULATE(
		SUM('P&L'[Values]), 
		'P&L'[CALENDAR YEAR] = LatestVisibleYear - 1
	)

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

1 REPLY 1
bcdobbs
Super User
Super User

Hi,

SAMEPERIODLASTYEAR works with dates ideally in a date table. You however have data already agregated at the year level.

 

So to get the data for 2020 you can just do:

2020Vals = 
	CALCULATE(
		SUM('P&L'[Values]), 
		'P&L'[CALENDAR YEAR] = 2020
	)

 

For something a bit more dynamic:

PreviousYearVals = 

VAR LatestVisibleYear = 
	MAX ( 'P&L'[CALENDAR YEAR] )

RETURN
	CALCULATE(
		SUM('P&L'[Values]), 
		'P&L'[CALENDAR YEAR] = LatestVisibleYear - 1
	)

 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
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.