# Inventory - Last suported Invoices

**URL:** <https://forum.knime.com/t/inventory-last-suported-invoices/91929>\
**Category:** KNIME Analytics Platform\
**Created:** [May 15, 2026, 12:55am UTC](https://forum.knime.com/t/inventory-last-suported-invoices/91929 "2026-05-15T00:55:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipereis50](https://forum-cdn.knime.com/user_avatar/forum.knime.com/felipereis50/32/78928_2.png) [@Felipereis50](https://forum.knime.com/u/Felipereis50)\
**Post date:** [May 15, 2026, 12:55am UTC](https://forum.knime.com/t/inventory-last-suported-invoices/91929/1 "2026-05-15T00:55:55Z")

</div>

**Hello friends,**

**Objective:** I would like some help implementing a rule to identify the most recent invoices that account for the final inventory balance.

In the example below, I join the Invoice table with the Inventory table. Since the Inventory table shows 4 units of SKU ABC for company “01”, I need to retrieve only the most recent documents that cover the quantity of 4.

In the example, the correct result would be to consider only these invoices:  
000005 = 2  
000004 = 1  
000003 = 5

In summary, if I have 4 units in inventory, invoice “000005” only covers 2, so I need to find the next most recent invoice. Invoice “000004” is also not enough because, so far, 2 + 1 = 3, and I need 4. Invoice “000003” then becomes sufficient.

Note: The invoice quantities do not need to match the 4 units exactly. The important thing is for the system to “stop” as soon as it finds the last invoice that supports the total.

Invoices “000002” and “000001” would be discarded.

**How could I implement this rule? The best simple aproach using Knime nodes (No Python)**

_It is important to consider that I have hundreds of SKUs and companies. I would use this rule within a Group Loop._  
_I know there are several ways to do this. Maybe using a recursive loop would be interesting until it finds the total. However, I haven’t been able to do it in a simple way using a group loop._

I am attaching a workflow to make it easier.

# Invoice Table

| Company | INVOICE NUMBER | INVOICE DATE | SKU | QTY SKU |
| --- | --- | --- | --- | --- |
| 01 | 000005 | 2026-05-14 | ABC | 2 |
| 01 | 000004 | 2026-04-02 | ABC | 1 |
| 01 | 000003 | 2026-04-01 | ABC | 5 |
| 01 | 000002 | 2026-02-05 | ABC | 1 |
| 01 | 000001 | 2025-12-31 | ABC | 1 |

# Inventory Table

| Company | SKU | QTY SKU |
| --- | --- | --- |
| 01 | ABC | 4 |

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/3/434b795c023a0902f3c863b77899712887fbe6bb.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/b/f/bfb706043f378c900686a95d9bb5e14034a69a0d.png)  
[Inventory\_Last\_suported Invoices.knwf](https://forum.knime.com/uploads/short-url/vYVwpRxPKWsUKSI66cKTTOwV0M0.knwf) (52.0 KB)

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [May 15, 2026, 7:29am UTC](https://forum.knime.com/t/inventory-last-suported-invoices/91929/2 "2026-05-15T07:29:48Z")

</div>

@Felipereis50 my very quick take on this. Will maybe expand and explain more later

> **[Inventory\_Last\_suported Invoices - KNIME Forum (91929) – mlauber71](https://hub.knime.com/mlauber71/spaces/Forum/2026/Inventory_Last_suported%20Invoices%20-%20KNIME%20Forum%20(91929)~-Pwo7Y7NUKSWO6Kk/current-state)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

---

<div class="post-metadata">

**Author:** ![Felipereis50](https://forum-cdn.knime.com/user_avatar/forum.knime.com/felipereis50/32/78928_2.png) [@Felipereis50](https://forum.knime.com/u/Felipereis50)\
**Post date:** [May 15, 2026, 11:42am UTC](https://forum.knime.com/t/inventory-last-suported-invoices/91929/3 "2026-05-15T11:42:27Z")

</div>

@mlauber71

This “Cumulative Sum for Grouping” node solved my problem.  
PS: I adapted your code.

1. I created a column to calculate the difference between Inventory and Cumulative (positive and negative values.) Then Grouping
2. I used your Row Splitter idea. Port 1 contains only the negatives, and Port 2 contains only the positives.
3. I used the Top k Row Filter to consider only the first line that becomes positive, which means I only need to find the first invoice that turned positive to fulfill the stock balance.
4. After that, I concatenate the negative invoices with the single positive one and end the loop.

**Your idea was excellent.** 😍

PS: I ended up not using the “Collecting” column.

**Thank you very much. It solved my problem.**

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/0/10a6322f623f972d60be2a84c7f2a89d80f4e010.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/e/4e84c18065820560a13974d01a311e50ee3e4344.png)

* * *

In the last update I ended up changing the Group Loop Star location.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/9/c92a683d6908af46e830e59162e70f08780c6e59.png)  
[Inventory\_Last\_suported Invoices - KNIME Forum (91929)\_updated.knwf](https://forum.knime.com/uploads/short-url/f67W6JTNmEECD6ceEPlrY3qq5vb.knwf) (86.5 KB)

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 22, 2026, 11:43am UTC](https://forum.knime.com/t/inventory-last-suported-invoices/91929/4 "2026-05-22T11:43:05Z")

</div>

Closed on May 22, 2026, 11:43am UTC

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