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...)
    • Settings Tab: Global defaults for safety stock, lead time, and growth acceleration.
    • Marketing Events Tab: Date ranges for planned promotions (used to apply lift multipliers).
    • MPN Settings Tab: SKU-specific overrides (e.g., if one SKU needs 120 days lead time instead of 90).
    • MPN Seasonality Control Tab: Month-by-month weighting per SKU.
  • Operational Inputs
    • Sales by Date & Product Family: Historical unit sales.
    • Current Inventory Levels: Live Total On Hand and Total Available counts.

Filters

  • SKU is not Shipping 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.

  1. 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.
  2. Operational Branch (Bottom):
    • Fetches Sales History and Live Inventory simultaneously.
    • Merge: Joins Inventory data onto the Sales data using SKU as the key.
  3. Calculation (The “Run Forecast Algorithm” Node):
    • The code iterates through every SKU and applies the forecasting logic described below.
  4. Loading:
    • The results are appended/updated in the Testing Live Algorithm spreadsheet.

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.

Data Destination

Destination: Google Sheets

Overview

The results are written to the Testing Live Algorithm spreadsheet.

Output Columns

  • Status: OK or REORDER (Triggered if Current 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.