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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
LotteLaugesen
Helper V
Helper V

How to calculate difference day by day

Hi 

 

I need to calculate difference in stock day by day, but sometime previous day doesn't exists.

How can I solve that?
I have tried with the formula below, but it doesn't work when previous day doesn't exists.:

 
Day Change Ton =
VAR TheDay = CALCULATE(SUM(FT_StockFiguresByWarehouse[Onhand balance Total Kg])) /1000
VAR LastDay = CALCULATE(SUM(FT_StockFiguresByWarehouse[Onhand balance Total Kg]),PREVIOUSDAY(Dim_Calendar[Date])) /1000
RETURN TheDay - LastDay

Result:
LotteLaugesen_0-1627042252175.png

 

Any suggestions?

 

1 ACCEPTED SOLUTION

@Greg_Deckler I found a way to make it work 😊

LotteLaugesen_0-1627369965217.png

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@LotteLaugesen Don't use PREVIOUSDAY but rather calculate the previous day using MAXX and filter by days less than the current row. That will give you the latest previous day that you have. Then you can use that to calculate that previous day's value. 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thank you for answering, but I can't make work.

 

I have made this measure:

LotteLaugesen_1-1627282199940.png

It seems that it gives the same date not the prior.

LotteLaugesen_2-1627282579519.png

And when I try to use in a filter I get an error

LotteLaugesen_3-1627282636731.png

So what am I doing wrong?

 

 

 

@Greg_Deckler I found a way to make it work 😊

LotteLaugesen_0-1627369965217.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.