Free Trial

Alteryx Designer Desktop Discussions

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

Running Total For Last "N" Days Fixed on Specific Fields

Trent_Montgomery
5 - Atom

I am trying to calculate a moving sum that is "N" days from the date specified on the row. I also need this calculation to fix itself to both distinct store and sku combination (as shown below). In the scenario below I am creating a fourth column that calculates a moving running total for the last 5 days (including the current date). In other tools such as Tableau I would calculate this as a window sum and fix the calculation at store and sku.

StoreSKUDateSales5 Day Running Sum
111111/1/202155
211111/1/202155
111111/2/2021611
211111/2/2021611
111111/3/2021718
211111/3/2021819
111111/4/2021321
211111/4/2021322
111111/5/2021425
211111/5/2021527
111111/6/2021121
211111/6/2021123
111111/7/2021520
211111/7/2021522
111111/8/2021215
211111/8/2021216
111111/9/2021416
211111/9/2021417
111111/10/2021618
211111/10/2021618
111111/11/2021825
211111/11/2021825
111111/12/2021929
211111/12/2021525
111111/13/2021229
211111/13/2021225
111111/14/2021631
211111/14/2021627

 

8 REPLIES 8
Luke_C
17 - Castor
17 - Castor

Hi @Trent_Montgomery 

 

I took a pass at this using the multi-row formula tool. See attached. I grouped by the Store and SKU and was able to get the same results as your sample data 

 

Luke_C_0-1624473235669.png

 

Trent_Montgomery
5 - Atom

@Luke_C thanks for the solution, however, I still have one concern: 

 

This solution works if every store has every calendar date present in the data, but if a date is missing (ie. the store did not sell any units on a particular date) it could include sales that happened more than 5 days ago? Is their a way to complete this calc with a date calc included.

Luke_C
17 - Castor
17 - Castor

Hi @Trent_Montgomery 

 

Yes, definitely possible. Here's an example of how you could do it:

 

  1. Convert dates to actual valid alteryx dates
  2. Identify the max/min date for each store/SKU combo
  3. Generate a row for every date in that range
  4. Join that up with the original data and union the dropouts from the R anchor (this would represent dates dates not found in the source). I deleted a record from your data to test this
  5. Sort the data and run the multi-row formula tool

 

Luke_C_0-1624475124312.png

 

apathetichell
19 - Altair

Here's a fairly different way from @Luke_C  - it uses the running total tool. and a macro.

2021-06-23 (2).png

2021-06-23 (3).png

  Since it uses actual dates (and does so as the control) missing dates won't matter.

apathetichell
19 - Altair

And before you ask - let's say you want a numeric up/down to choose how many days you want your running total? can it be done? why sure...

Trent_Montgomery
5 - Atom

Alright, I think I am almost there... One more questions question...

In my actual data set I am doing this for the last 91 days. Do I really have to add all 91 rows in the expression (multi row) or is their a simpler way to write that expression (ie. Row +0 through Row -90). Thanks again for all the help

Luke_C
17 - Castor
17 - Castor

@Trent_Montgomery , so instead of doing a rolling 5 days you want to do a running total for a rolling 91 days? In that case amending the filter in @apathetichell is probably the easier option.

 

Alternatively if you want a straight running total for the data the running total tool grouped by the store/sku would work too

apathetichell
19 - Altair

Hi @Trent_Montgomery I used a slightly different approach and I avoid the quagmire of the extended multi-row formula. Take a look and see if it works for your needs. First version needs a hardcoded number of days to filter on (in the macro) - second uses a drop down interface in the batch macro to filter on a day # of your choosing (I think I limited it to 100 but you can change that) and even changes the column name to reflect your date selection.

Labels
Top Solution Authors