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

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