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

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

Reply
davidtanchon
Frequent Visitor

How to calculate a measure based based of calculation on previous year

Hi ,

 I would like to calculate the Price gap between current year and previous year.

Price GAP Formula is  : (Product cost (Y) * Qty (Y)) - (Product cost (Y-1) * Qty (Y))

and Product cost formula is : Purchase Amount / Qty 

the detail of information is at order level, but the product cost should calculated at Item, Purchaser level and after agregated  

 

Is there formula dax to calculate this measure?

 

Thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @davidtanchon ,

 

Due to I don't know your data model, I build a sample to have a test.

1.png

Try this measure:

Price GAP Formula = 
VAR _CURRENTYEAR = SUM('Table'[Product cost])*SUM('Table'[QTY])
VAR _Previous = CALCULATE(SUM('Table'[Product cost])*SUM('Table'[QTY]),FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])&&'Table'[Year] = SUM('Table'[Year])-1))
RETURN
_CURRENTYEAR - _Previous

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @davidtanchon ,

 

Due to I don't know your data model, I build a sample to have a test.

1.png

Try this measure:

Price GAP Formula = 
VAR _CURRENTYEAR = SUM('Table'[Product cost])*SUM('Table'[QTY])
VAR _Previous = CALCULATE(SUM('Table'[Product cost])*SUM('Table'[QTY]),FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])&&'Table'[Year] = SUM('Table'[Year])-1))
RETURN
_CURRENTYEAR - _Previous

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

 

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @davidtanchon - I think you are looking for formula the works out the ( Product Cost difference ) * Quantity within a SUMX.  I am going to assume that you Quantity is available for individual items on fact table, and the corresponding Current Year and Prior Year Price are on related product table:

The formula would look something like this:

 

Change in Product Cost = SUMX( fact , fact[Qty] * ( RELATED(Product[Current Cost] ) - RELATED(Product[Prior Year Cost]) )

Many thanks

Daryl

amitchandak
Super User
Super User

@davidtanchon , with help from date table and time intelligence you can create measures for this year and last year

 

example

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.