# knime inventory coverage in days

Hello everyone!

I’m trying to calculate the stock coverage, considering that I have the initial stock and another 200 columns with daily requirements, these columns with daily requirements have some that are zero.

the calculation is if the stock >= requirement 1, then the variable receives 1, if the stock is less than the requirement, then it remains (stock / requirement 1), and so the calculation must be carried out by decreasing the stock of all requirements until the zero stock, and the variable receives one for each time the stock becomes positive, another factor if the requirement is zero, then 1 must be considered in the variable.

I understand that there must be a loop to do this calculation, but I can’t do it.

For me it’s quite hard to understand your requirement.

You have an initial stock, let’s call it stock(0). You have daily requirements (req(x=day)) and you have stock on day x = stock(x)
You write:

`If stock(0) >= req(1) the variable receives 1`

What is “the variable”?
What does “1” stand for?
Let’s put figures on it: I have stock(0) = 10 and req(1) = 5
Now I calculate “the variable” = 1. But what about the stock (1)?

Then you say
`If stock(0) < req(1) it remains (stock / requirement)`
Also here with figures: stock(0) = 5 and req(1) = 10.
Now I calculate 5 / 10 = 0.5 (is this again “the variable”?)

So it would be great if you can share some examples with the input data and the desired output (you may of course reduce the days/columns).

1 Like

stock coverage.xlsx (10.5 KB)

Hello my friend,
Thank your feedback, I uploaded the excel file.
Maybe I expressed myself wrong, sorry

I need to know how many days my stock has coverage, considering daily requirements.

In my xlx file, in the last table I tried to give an example of what result knime needs to do, in this case and know how many days my stock has, considering the daily requirement.

You can use unpivot node to unpivot all but the first 2 columns
Then start a group loop based on COD use moving aggregation (cumulative sum) to sum up the column values from the unpivot add a counter generation node and then use rule engine to check if the cumsum is above the inventory
output is sth like

You might want to adjust this further but this might give you some idea to start hopefully.
br

2 Likes

Hello my friend,
In this case, when we have, for example, 9.5 or 9.7 days… Do you know the solution?
And when the stock is more cumsum?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.