Last Updated: Jan 22, 2026
Open workflow in n8n
Executive Summary
This is the core demand planning engine. It executes a parallel fetch operation to gather global configuration settings (Seasonality, Marketing Events) and operational data (Sales History, Live Inventory). It merges these datasets to run a custom forecasting algorithm (Holt’s Linear Trend) that projects inventory depletion and generates specific “Reorder” recommendations per SKU.
INFO
Config + Sales + Inventory→n8n→Google Sheets
Trigger:Every 1 day at 00:20
Data Source
Source: Google Sheets (Multiple Files)
Overview
This workflow relies on a distributed configuration model. Instead of hardcoding values in n8n, it pulls parameters from specific Google Sheets to allow business users to tune the algorithm without touching code.
Data Sources
- Configuration Inputs (Source:
Projection Algorithm Output Example...)SettingsTab: Global defaults for safety stock, lead time, and growth acceleration.Marketing EventsTab: Date ranges for planned promotions (used to apply lift multipliers).MPN SettingsTab: SKU-specific overrides (e.g., if one SKU needs 120 days lead time instead of 90).MPN Seasonality ControlTab: Month-by-month weighting per SKU.
- Operational Inputs
Sales by Date & Product Family: Historical unit sales.Current Inventory Levels: LiveTotal On HandandTotal Availablecounts.
Filters
SKUis notShipping Revenue Shopify- Purpose: Exclude non-physical service items from the forecast.
Data Manipulation (n8n Workflow)
Logic Flow
The workflow executes in two parallel branches to optimize performance before merging for the final calculation.
- Configuration Branch (Top):
- Fetches the “Defaults” first.
- Iteratively fetches and maps Marketing Events, SKU Settings, and Seasonality profiles.
- Result: A master configuration object passed to the code node.
- Operational Branch (Bottom):
- Fetches Sales History and Live Inventory simultaneously.
- Merge: Joins Inventory data onto the Sales data using
SKUas the key.
- Calculation (The “Run Forecast Algorithm” Node):
- The code iterates through every SKU and applies the forecasting logic described below.
- Loading:
- The results are appended/updated in the
Testing Live Algorithmspreadsheet.
- The results are appended/updated in the
The Forecast Algorithm
The logic inside the code node applies a sophisticated “Gap Analysis” using the following mathematical models:
- Holt’s Linear Smoothing:
- Used to “de-seasonalize” historical data and find the true trend.
- Alpha (Level): 0.2 | Beta (Trend): 0.05 | Phi (Damping): 0.9
- Safety Clamps:
- Prevents the algorithm from hallucinating wild growth.
- Max Weekly Growth: Capped at 5%.
- Min Weekly Growth: Floor at -10%.
- Gap Analysis Loop:
- It projects daily inventory levels for the next
Lead Time + Coverage Days. - It subtracts daily demand (adjusted for Seasonality and Marketing Events).
- If projected inventory hits 0, it calculates the “Gap” needed to fulfill the remaining days.
- It projects daily inventory levels for the next
Data Destination
Destination: Google Sheets
Overview
The results are written to the Testing Live Algorithm spreadsheet.
Output Columns
- Status:
OKorREORDER(Triggered ifCurrent Weeks of Supply<Lead Time). - Stock Level Target: The calculated quantity needed to meet the coverage target.
- Weekly RoS Acceleration: The detected trend direction (positive = growing demand).
- Telemetry: Internal metrics (RoS, Monthly Velocity) used for debugging.