Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

How to calculate rolling 12 months sales

hbuehanx
6 - Meteoroid

Hi All, I am new to Alteryx. Can someone show me how to calculate rolling 12 months sales based on the month by Product Category, Product, Territory? Here is the sample data. In real data, some months may be missing if there is no sales for the product

Product CategoryProductTerritoryMonthSales
ABC1XYZ1AB112/1/2022100
ABC1XYZ1AB111/1/2022120
ABC1XYZ1AB110/1/2022120
ABC1XYZ1AB19/1/2022110
ABC1XYZ1AB18/1/2022100
ABC1XYZ1AB17/1/202290
ABC1XYZ1AB16/1/202280
ABC1XYZ1AB15/1/2022100
ABC1XYZ1AB14/1/2022100
ABC1XYZ1AB13/1/202290
ABC1XYZ1AB12/1/2022120
ABC1XYZ1AB11/1/2022130
ABC1XYZ1AB112/1/2021120
ABC1XYZ1AB111/1/2021110
ABC1XYZ1AB110/1/2021115
ABC1XYZ1AB19/1/2021100
ABC2XYZ2AB212/1/2022380
ABC2XYZ2AB211/1/2022420
ABC2XYZ2AB210/1/2022400
ABC2XYZ2AB29/1/2022420
ABC2XYZ2AB28/1/2022320
ABC2XYZ2AB27/1/2022440
ABC2XYZ2AB26/1/2022450
ABC2XYZ2AB25/1/2022470
ABC2XYZ2AB24/1/2022550
ABC2XYZ2AB23/1/2022350
ABC2XYZ2AB22/1/2022430
ABC2XYZ2AB21/1/2022340
ABC2XYZ2AB212/1/2021440
ABC2XYZ2AB211/1/2021550
ABC2XYZ2AB210/1/2021440
ABC2XYZ2AB29/1/2021330

 

 

 

 

Desired Result:

 

Product CategoryProductTerritoryMonthSalesRolling 12 month total
ABC1XYZ1AB112/1/20221001260 (Total Sales from 1/1/2022 to 12/1/2022)
ABC1XYZ1AB111/1/20221201280 (Total Sales from 12/1/2021 to 11/1/2022)
ABC1XYZ1AB110/1/20221201270
ABC1XYZ1AB19/1/20221101265
ABC1XYZ1AB18/1/2022100 
ABC1XYZ1AB17/1/202290 
ABC1XYZ1AB16/1/202280 
ABC1XYZ1AB15/1/2022100 
ABC1XYZ1AB14/1/2022100 
ABC1XYZ1AB13/1/202290 
ABC1XYZ1AB12/1/2022120 
ABC1XYZ1AB11/1/2022130 
ABC1XYZ1AB112/1/2021120 
ABC1XYZ1AB111/1/2021110 
ABC1XYZ1AB110/1/2021115 
ABC1XYZ1AB19/1/2021100 
ABC2XYZ2AB212/1/20223804970
ABC2XYZ2AB211/1/20224205030
ABC2XYZ2AB210/1/20224005160
ABC2XYZ2AB29/1/20224205200
ABC2XYZ2AB28/1/2022320 
ABC2XYZ2AB27/1/2022440 
ABC2XYZ2AB26/1/2022450 
ABC2XYZ2AB25/1/2022470 
ABC2XYZ2AB24/1/2022550 
ABC2XYZ2AB23/1/2022350 
ABC2XYZ2AB22/1/2022430 
ABC2XYZ2AB21/1/2022340 
ABC2XYZ2AB212/1/2021440 
ABC2XYZ2AB211/1/2021550 
ABC2XYZ2AB210/1/2021440 
ABC2XYZ2AB29/1/2021330 

 

 

 

Thank you very much!

Tim

9 REPLIES 9
geraldo
13 - Pulsar

@hbuehanx 

 

Could you put the desired result to understand better

hbuehanx
6 - Meteoroid

Hi, I have modified the question. Please let me know if it is still confusing. Thank you!

Yoshiro_Fujimori
15 - Aurora

Hi @hbuehanx ,

 

Here is one way of doing this.

My result shows one more row than your expected result. I think it OK, but if I misss anything, please let me know.

 

Workflow

Yoshiro_Fujimori_0-1684364391024.png

 

Expression in Multi-Row Formula tool 

IF IsEmpty([Row+11:Product Category]) THEN Null()
ELSE [Sales] + [Row+1:Sales] + [Row+2:Sales] + [Row+3:Sales] + [Row+4:Sales] + [Row+5:Sales] + [Row+6:Sales] + [Row+7:Sales] + [Row+8:Sales] + [Row+9:Sales] + [Row+10:Sales] + [Row+11:Sales]
ENDIF

 

Output

Yoshiro_Fujimori_1-1684364484517.png

Yoshiro_Fujimori_2-1684364498301.png

 

I hope this helps.

hbuehanx
6 - Meteoroid

Hi Yoshiro, thank you for your help. In real data, some months may be missing if the product doesn't have sales in that month. Does it still work?

Yoshiro_Fujimori
15 - Aurora

Hi @hbuehanx ,

 

I can think of two approaches.

#1. In Multi-Row Formula tool, check if the row is within 12 months or nor.

#2. Add missing rows before calculationg the rolling totals.

 

#1 is straightforward, but the formula can be lengthy as below:

IF IsEmpty([Row+11:Product Category]) THEN Null()

ELSE [Sales]
+ IF DateTimeDiff([Date],[Row+1:Date],"month")<=12 THEN [Row+1:Sales] ELSE 0 ENDIF
+ IF DateTimeDiff([Date],[Row+2:Date],"month")<=12 THEN [Row+1:Sales] ELSE 0 ENDIF

...
+ IF DateTimeDiff([Date],[Row+11:Date],"month")<=12 THEN [Row+11:Sales] ELSE 0 ENDIF
ENDIF

 

#2 would be like below.

(1) Generate Rows tool to generate rows including all the months in the period

(2) Join tool to the output with the original tabl

(3) then apply the original workflow.

If you prefer this approach, you may try it by yourself. 😁

 

Good luck.

Qiu
20 - Arcturus
20 - Arcturus

@hbuehanx 
Maybe we can use a batch macro.

Inside the macro, we will calculate the Time Difference and filter only 12 months younger, no mater it is null or not.

0518-hbuehanx-A.PNG0518-hbuehanx-B.PNG

hbuehanx
6 - Meteoroid

Thank you for the guidance. I'll follow your instruction

hbuehanx
6 - Meteoroid

Thank you for the help. I'll do more research on macro

Niru9986
5 - Atom

Hi ACE Spotlight Series: Jifeng Qiu

 

   Could you please share me batch file for reference.

 

Thanks for advance...

Labels