Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Subtracting Quantity until 0 left for item and date

jdallen
5 - Atom

Hi

 

What I am trying to do is for an item and date which are both ascending - I need the earliest date first to apply stock to a row until it hits 0 or whatever is  remaining

 

I need to subtract sum_qty (which is my available stock) from order quantity (which is the order quantity) which gives me the stock for that item and if remaining greater than sum_qty just apply whatever  is remaining in the order quantity  meaning I have none left to apply to the next line if the item is the same as previous row

 

I have several items the same so the total only applies to the same item, if the next row is a different item start the subtraction again

 

I have some data here as follows:

SKUSum_QTYOrder QuantityExpected OutcomeDate
B6967Q8C8585E033 1/5/2022
B7403Q7C8114W01014 11/16/2021
B7403Q7C8114W01014 11/23/2021
B7671Q8C8LB5E061 11/30/2021
B7671Q8C8LB5E062 12/10/2021
B7671Q8C8LB5E0610 12/15/2021
B7671Q8C8LB5E064 1/5/2022
B7671Q8C8LB5E065 1/11/2022
B7671Q8C8LB5E065 1/28/2022
B7672Q8C8WL5E042 12/14/2021
B7672Q8C8WL5E042 1/21/2022
     


What I am trying to achieve is the following:

 

SKUSum_QTYOrd QtyRemainingStock for OrderDate
B6967Q8C8585E033031/5/2022
B7403Q7C8114W0101401011/16/2021
B7403Q7C8114W010140011/23/2021
B7671Q8C8LB5E0615111/30/2021
B7671Q8C8LB5E0623212/10/2021
B7671Q8C8LB5E06100312/15/2021
B7671Q8C8LB5E064001/5/2022
B7671Q8C8LB5E065001/11/2022
B7671Q8C8LB5E065001/28/2022
B7672Q8C8WL5E0422212/14/2021
B7672Q8C8WL5E042021/21/2022

 

Hope that makes sense - and thanks in advance for any help!!

3 REPLIES 3
Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @jdallen,

 

This can be achieved with a series of formula tools and multi-row formulas:

 

JonathanSherman_0-1638963237783.png

 

 

I've attached my workflow for you to download if needed!

 

Kind regards,

Jonathan

jdallen
5 - Atom

THank you very much, works a charm!!

Jonathan-Sherman
15 - Aurora
15 - Aurora

No problem, it was a cool challenge! Had my head tangled for a little while as I was overcomplicating it to begin with!

Labels
Top Solution Authors