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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
robbinkees1
Frequent Visitor

Stock simulation over time

Hi all, 

 

I'am working on a report which tells me in which week I'm running out of stock. 

 

Stock incoming column: Purchase order quantity's that will be delivered in that week. 

Sales column: Sales order quantity's that will be send to the customer in that week. 

In / out column: Stock incoming column - sales column

 

robbinkees1_2-1652358670196.png

 

Now I want in the stock over time column a simulation over the weeks when I run out of stock. (current stock - sales + incoming)

It doesn't need to fall back to the current stock every time, so for example: 

Week 20: 83 -9 = 74.

Week 21 74 - 6 = 68. 

Week 23 68 - 28 = 40.

week 24 40 + 18 =58. 

etc 

 

Is there a way how i can fix this with a measure. 

I currently try to calculate it like this, but it takes the current stock every week again and it doesn't calculate further based on the previous weeks.

 

Stock over time = SUM('crm stock'[current_stock]) + CALCULATE([In / out],FILTER(ALL('Date master2'[WeekNumber]),'Date master2'[WeekNumber]<=MAX('Date master2'[WeekNumber])))

 

Can anyone help? 

 

1 ACCEPTED SOLUTION

Hi, @robbinkees1 

 

You can try the following methods.

Measure:

Stock over time = 
SUM ( 'Table'[Current_Stock] )
    + CALCULATE (
        SUM ( 'Table'[in/out] ),
        FILTER ( ALL ( 'Table' ), [Date] <= SELECTEDVALUE ( 'Table'[Date] ) )
    )

vzhangti_0-1652953919486.png

 

Column = 
[Current_Stock]
    + CALCULATE (
        SUM ( 'Table'[in/out] ),
        FILTER ('Table' , [Date] <= EARLIER( 'Table'[Date] ) )
    )

vzhangti_1-1652953964497.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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
amitchandak
Super User
Super User

@robbinkees1 , We use these kinds of formulas (Measures) to build inventory. Very similar to what you have done

 

Inventory / OnHand
[Intial Inventory] + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

Inventory / OnHand
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

if you have date , prefer to use date not week no

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

Hi @amitchandak 

 

Thanks for your reply! 

But unfortunately it keeps calculating with the current stock of 83 on every day, I want to simulate it further over the time based on the incoming and outgoing stock. it doesn't need to fall back to the current. 

Tried both measures.

robbinkees1_1-1652361374902.png

 

 

I want that it continues over time and simulating my stock levels. 

So for example after 5/16/2022 it should calculate with 74 instead of 83. 

The calculation on 5/23/2022 should be 74 - 6 instead of 83 - 6.

Hi, @robbinkees1 

 

You can try the following methods.

Measure:

Stock over time = 
SUM ( 'Table'[Current_Stock] )
    + CALCULATE (
        SUM ( 'Table'[in/out] ),
        FILTER ( ALL ( 'Table' ), [Date] <= SELECTEDVALUE ( 'Table'[Date] ) )
    )

vzhangti_0-1652953919486.png

 

Column = 
[Current_Stock]
    + CALCULATE (
        SUM ( 'Table'[in/out] ),
        FILTER ('Table' , [Date] <= EARLIER( 'Table'[Date] ) )
    )

vzhangti_1-1652953964497.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors