n8n tutorial - Lesson 19: n8n Weekly Digest: Aggregate All Your Data in One Report

Hi everyone, in this session of the n8n Workflow Automation Tutorial series, we're building an n8n weekly digest workflow that pulls data from four Google Sheets, aggregates everything with a Code node, generates an AI summary using Claude, and delivers it to Telegram every Sunday at 7 PM. This is the capstone workflow for the YouTube Assistant project — and it's a great real-world example of parallel branching, cross-node aggregation, and LLM-powered reporting in a single automated pipeline.

How to do:

Step 1 — Create the Workflow and Set the Schedule Trigger

Create a new workflow named T5-B7-Weekly-Digest and configure a cron-based schedule to fire every Sunday at 19:00.
  1. In n8n, click + New Workflow and name it T5-B7-Weekly-Digest.
  2. Add a Schedule Trigger node and set the mode to Cron.
  3. Enter the cron expression 0 19 * * 0 — this means every Sunday at 19:00.
  4. Save the node. This single trigger will fan out into four parallel branches in the next step.

Tip — The cron expression 0 19 * * 0 breaks down as: minute=0, hour=19, any day-of-month, any month, weekday=0 (Sunday). Double-check your server timezone in n8n settings so the trigger fires at the correct local time.

Step 2 — Add Four Parallel Google Sheets Branches

Connect four separate Google Sheets nodes directly to the Schedule Trigger, one for each metrics sheet, so all four reads execute in parallel.
  1. Add a Google Sheets node, name it Get Comments Stats, and connect it to the Schedule Trigger.
  2. Configure it:
    • Credential: Google Sheets Personal (shared across all four nodes)
    • Spreadsheet: select T5-Comments-Queue
    • Operation: Get Rows
    • Always Output Data: ON
  3. Duplicate the node three times and rename them:
    • Get Title Stats → Sheet: T5-Title-Suggestions
    • Get Performance Stats → Sheet: T5-Performance-Snapshots
    • Get Metadata Stats → Sheet: T5-Video-Metadata
  4. Connect all four nodes directly from the Schedule Trigger output — they run in parallel, not in sequence.

Note — Always Output Data = ON is the correct setting here because these nodes act as reference lookups — you want the workflow to continue even if a sheet has no rows yet. This is different from trigger-style nodes where you want AOD = OFF to avoid empty runs.

Step 3 — Merge All Four Branches

Add a Merge node to collect all four streams into a single flow before aggregation.
  1. Add a Merge node and name it Merge All Sheets.
  2. Set Mode to Append — this stacks all rows from all four sheets into one item list.
  3. Connect all four Google Sheets nodes (Get Comments Stats, Get Title Stats, Get Performance Stats, Get Metadata Stats) as inputs to this Merge node.
  4. Verify in test mode that the merged output shows approximately 34 items (the combined row count from all four sheets).

Tip — The Append merge mode is the right choice when you don't need to join rows by a key — you just want all items stacked. The next Code node will use cross-node references to read each sheet's data individually, so the merged list here is mainly a trigger to pass execution forward.

Step 4 — Aggregate Stats with a Code Node Using Cross-Node References

Add a Code node that reads each sheet independently via cross-node references and builds a single structured summary object.
  1. Add a Code node named Aggregate Stats and connect it to Merge All Sheets.
  2. Set Mode to Run Once for All Items.
  3. In the code editor, reference each sheet's data using the cross-node pattern:
    • const comments = $('Get Comments Stats').all();
    • const titles = $('Get Title Stats').all();
    • const performance = $('Get Performance Stats').all();
    • const metadata = $('Get Metadata Stats').all();
  4. Build a nested summary object with these four sections:
    • comments: total, by_category, by_status
    • titles: total, by_status
    • performance: video_count, total_view, total_like, videos (list)
    • metadata: total, by_status
  5. For the performance section, sort rows to get the latest snapshot per video before summing totals — use a reduce or sort + dedup pattern in JavaScript.
  6. Add a week_label field formatted as DD/MM/YYYY using JavaScript's Date object to label the digest by week.
  7. Return return [{ json: summary }]; — a single item containing the full aggregated object.

Production tip — Always use $('Node Name').all() cross-node references inside a Code node running "once for all items" when you need to aggregate across multiple upstream branches. Never use .find() in expression fields for lookups — build an O(1) lookup map in Code instead.

Step 5 — Generate the AI Weekly Digest with Claude

Add a Basic LLM Chain node connected to the Anthropic API to turn the aggregated stats object into a formatted Telegram message.
  1. Add a Basic LLM Chain node named Weekly Digest and connect it to Aggregate Stats.
  2. Set the model to Claude Haiku 4.5 (consistent with the rest of the project).
  3. Set Temperature to 0.3 and Max Tokens to 2500.
  4. Write the system/user prompt using an XML 5-block structure:
    • Block 1 — Role: define the assistant as a YouTube analytics reporter
    • Block 2 — Data: inject the aggregated stats via {{ $json.summary }} or the relevant field
    • Block 3 — Format rules: specify telegram_markdown_legacy — single asterisk *bold*, no V2 syntax
    • Block 4 — Digest structure: list the 7 required sections (e.g., overview, comments, titles, performance, metadata, highlights, next week)
    • Block 5 — Constraints: language, tone, emoji use
  5. Test the node. If you get an authentication error, check your Anthropic API balance — a $0 balance silently stops all active workflows using Haiku.

Note — If the Claude API returns an error due to insufficient credit, top up your Anthropic account ($5–10 is enough to cover several weeks of digest runs) and re-run the workflow. This is an external dependency, not a design flaw — but it means you should monitor your Anthropic console balance regularly and consider enabling auto-recharge if available.

Step 6 — Send the Digest to Telegram

Add a Telegram node to deliver the AI-generated digest message every Sunday evening.
  1. Add a Telegram node named Send Weekly Digest and connect it to Weekly Digest.
  2. Select your existing Telegram Bot credential (reused from earlier workflows in this series).
  3. Set Chat ID to your target Telegram group or personal chat ID.
  4. Set Parse Mode to Markdown (legacy — single asterisk format, not MarkdownV2).
  5. In the Message field, reference the LLM output: {{ $json.text }} or the field your LLM Chain outputs.
  6. Set Append Attribution to OFF to keep the message clean.

Tip — Always use Telegram Markdown legacy (single * for bold, single _ for italic) when your LLM is prompted to produce Telegram-formatted text. MarkdownV2 requires escaping many special characters, which makes AI output unreliable without a post-processing step.

Step 7 — Activate the Workflow

With all 9 nodes connected and tested, activate the workflow so it runs automatically every Sunday at 19:00.
  1. Click the Inactive toggle in the top-right corner of the workflow editor to set it to Active.
  2. Verify the full node chain is connected:
    • Schedule Trigger → 4× Google Sheets nodes (parallel)
    • Google SheetsMerge All Sheets
    • Merge All SheetsAggregate Stats (Code)
    • Aggregate StatsWeekly Digest (LLM Chain)
    • Weekly DigestSend Weekly Digest (Telegram)
  3. Check Executions the following Monday morning to confirm the Sunday run completed without red errors.
  4. If the workflow ran during an Anthropic credit outage, top up the balance and manually trigger a test run to confirm recovery.

Production tip — After activating any workflow that depends on a paid external API (Anthropic, OpenAI, etc.), bookmark the provider's billing console and check it at least once a week. A $0 balance will silently stop all active workflows using that provider — there is no built-in n8n alert for third-party API credit exhaustion.

Key Lessons from This Session

  1. Parallel branching from a single trigger. Connect multiple nodes directly to one trigger node to read from several data sources simultaneously — this is faster and cleaner than chaining them sequentially.
  2. Use Merge (Append) to reunite parallel branches. Append mode stacks all items from all inputs without needing a join key — ideal when you plan to aggregate in the next Code node anyway.
  3. Cross-node references in Code nodes unlock multi-source aggregation. Use $('Node Name').all() inside a "Run Once" Code node to read each source independently and build a structured summary object.
  4. Always Output Data = ON for lookup/reference nodes. Set AOD=ON on any Google Sheets node acting as a data source so the workflow continues even when a sheet is temporarily empty.
  5. Sort and dedup snapshot data before summing. For lifetime stats stored as snapshots, always pick the latest snapshot per video before calculating totals — otherwise you double-count historical rows.
  6. Telegram Markdown legacy: single asterisk only. Prompt your LLM to use *bold* (one asterisk), not **bold** — Telegram legacy parse mode does not support double asterisks.
  7. Monitor third-party API credit balances regularly. A depleted Anthropic (or OpenAI) balance silently kills every active workflow using that credential — check balances on a set schedule and enable auto-recharge if available.
  8. Vietnamese (and other CJK-adjacent) tokens are ~3× heavier than English. If your AI output language is not English, set Max Tokens high enough to avoid truncated messages — 2500 is a safe floor for a 7-section digest.

Conclusion:

In this n8n tutorial, we built a complete n8n weekly digest workflow that uses parallel Google Sheets branches, a cross-node Code aggregator, a Claude LLM chain, and a Telegram sender to deliver a structured weekly report every Sunday — all fully automated. This pattern of branching + merging + Code aggregation is one of the most reusable patterns in n8n workflow automation, applicable any time you need to consolidate data from multiple sources into a single report. The next session opens Week 6: a multi-channel Content Factory that connects Blog, YouTube, Email, and Word output from a single idea using sub-workflows and error handling.

If you have any questions, feel free to leave a comment below. Thank you!

Tags: n8n weekly digest workflow, n8n tutorial, n8n workflow automation, n8n Google Sheets aggregate, n8n Telegram bot, n8n Code node cross-node reference, n8n LLM chain Claude, n8n parallel branches merge

Maybe you are interested!