Subtract a quantity from a PRODUCTO with the same CODIGO in an SALIDA

Friends, I have a form that SALIDAS tools according to CODIGO, but these have a unique QR. In the ARTICULOS table, only the quantity is recorded per CODIGO and the QR is only for reference of the tool. When registering the SALIDA, the quantity must subtract the amount of the ARTICULO by CODIGO, but the Bot and the action that I have implemented, gives me wrong results. For example, if I make the SALIDA of CODIGO=BODCAL001 QR=123 CANTIDAD=01 in one line, in the other line CODIGO=BODCAL001 QR=456 CANTIDAD=01 in another line CODIGO=BODCAL001 QR=789 CANTIDAD=01 the result is (- 2) being that the quantity of ARTICULO BODCAL001 was 4.
These are the expressions:

BOT RESTA, Data change, Table SALIDAS, Data change type Adds and Updates, Condition = “”

PASO RESTA, Run action on rows, References Table ARTICULOS, Referenced rows=FILTER(“ARTICULOS”,([CODIGO]=[_THISROW].[CODIGO])), Referenced Action RESTA.

Action RESTA, For a record of this table ARTICULOS, Do this Data: set the values of some in this row, Set these columns CANTIDAD TOTAL= ([CANTIDAD TOTAL] - SUM(SELECT(SALIDAS[CANTIDAD], [CODIGO] = [_THISROW].[CODIGO])))

Please help me to know what mistake I am making. My job depends on this application. Thank you.

Hola @malfaro_2000 .

Primero que nada, espero que aún conserves tu trabajo ya que este post ya tiene tiempo. :sweat_smile:

Tu problema es algo confuso, pero me parece que el detalle se encuentra en la esctructura de los datos. Para administración de inventarios recomiendo al menos las siguientes tablas:

  • Productos
  • Almacen/Ubicaciones
  • Movimientos (Entradas-Salidas)
  • Ordenes (Una órden esta relacionada a “n” movimientos)

Generalmente no es necesario ningun bot para el descuento de inventario, en tu tabla PRODUCTOS, crea una columna virtual [Inventario] que realice la suma de todos los movimientos (+entradas -salidas) de la tabla Movimientos para cada producto. Lo cual se ve algo así:

Sum(Select(Movimientos[Cantidad],[Producto]=[_ThisRow].[Producto]))

Si requieres mayor soporte puedes contactarme directamente.

Saludos!