Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Rolling sum of future forecast quantity over n number of rows

ritikat
6 - Meteoroid

Hello Team,

 

I have a situation where I need to do a sum of forecast quantity over "n" number of rows. 

 

n = coverage days

 

The N will vary based on article and store combination. 

 

Requirement column is the output column where the sum has to be stored.

 

Looking forward for your responses. 

 

ArticleStoreN (Coverage days)DateForecast qtyRequirement
A1S122020-09-021010+20=30
A1S122020-09-032020+5 = 25
A1S122020-09-04515+5 = 20
A1S122020-09-051515
A2S142020-09-0233+2+1 + 5=11
A2S142020-09-0322+1+5+6=14
A2S142020-09-0411+5+6=12
A2S142020-09-055 
A2S142020-09-066 
8 REPLIES 8
ggruccio
ACE Emeritus
ACE Emeritus

Hi @ritikat,

 

Based on the data you provided, you could build out a simple if-then statement within a multi-row formula tool.  However if it gets too complex then you may want to choose another route...this would depend on the number of "N Coverage Days"  you have. 

ggruccio_0-1599058597245.png

Not sure if I have the logic exactly correct , as shown below, in item A2, I believe your formula pulls values from A3, where I've grouped on the field [Article] and won't allow it to pull from A3.  

 

ggruccio_1-1599058706266.png

You may also want to "Group-by" [Store] and [Article] and check my formula...where I've only added 2 rows below the current row for the N-Coverage days =4 to match your requirement you may want to go 3 rows below (the current row + 3 more =4).

 

Hopefully this is enough to get you started!

 

 

ritikat
6 - Meteoroid

Hi @ggrucio,

 

Thanks so much for the reply. 

 

1 issue that I am facing is - The expression needs to be dynamic based on the coverage days value. This is going to be a huge data set and every article store combination will have a different coverage days, so we can't  possibly right all IF statements and expression to sum the Row+N rows. 

 

Hoping to find a way where the expression changes dynamically. 

 

Regards,

Ritika

RolandSchubert
16 - Nebula
16 - Nebula

Hi @ritikat ,

 

maybe this approach solves your problem:

- generate a list of "days to add" using the Generate Rows  tool (number of rows to generate is determined by the number of days to include)

- join this list to the input data

- summarize

 

2020-09-03_07-37-44.png

I've separated the number of days from the forecast data, the "number of days" table needs your input for each combination Article/Store.

 

I've attached a sample workflow. Let me know if it works for you.

 

Best,

 

Roland

ritikat
6 - Meteoroid

Thank you So much @

 

 

 

 

MarqueeCrew
20 - Arcturus
20 - Arcturus

@ritikat ,

 

I was reviewing this post and saw a fixed-solution that works by @ggruccio and wanted you to be aware of a CReW macro (http://www.chaosreignswithin.com/p/macros.html) that is a "Moving Summarize" tool.  It allows you to generate not only the sum, but also moving averages and virtually all summarize numeric functions.

 

Macros Download Link 

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
akshaydalvicia
7 - Meteor

The Moving summarize tool only go back 100 rows. It is not looking back > 100 rows

Mahadeva
8 - Asteroid

@MarqueeCrew It doesn't have group by option to perform moving calculations. Any way we can achieve this along with the features available in this macro. ?

Mahadeva
8 - Asteroid

@RolandSchubert Thanks for the awesome solution.

Labels