Advanced JavaScript Data Filtering and Statistical Analysis - n8n Workflow

Learn advanced JavaScript data manipulation techniques inside an n8n workflow using the Code n8n node for filtering, aggregation, and export formatting. Ideal n8n templates for developers.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation Developers needing to perform complex data filtering or calculations within an n8n workflow.
Users who want to master the n8n Code node and integrate custom JavaScript logic.
Engineers preparing data for dashboards, reporting, or external APIs using specialized n8n templates.
Anyone looking for practical n8n workflow examples focusing on data transformation.

Overview

This essential n8n workflow serves as a comprehensive tutorial for leveraging the power of custom JavaScript code directly within the automation environment. It addresses the common need to perform intricate data manipulation tasks that are often too complex for standard n8n nodes alone. By running this n8n template, users can observe practical examples of filtering datasets (Example 1), calculating aggregated statistics like averages and distributions (Example 2), and formatting structured data into multiple output types suitable for export, such as CSV or custom API payloads (Example 3). Mastering the Code n8n node is crucial for extending the capabilities of any sophisticated n8n automation project. This n8n workflow showcases parallel data processing streams, making it a robust learning tool.

How it Works

This learning n8n workflow begins with the manual n8n trigger, designed for easy testing and execution, focusing solely on the internal data logic.


  1. Trigger & Setup: The 'When clicking ‘Execute workflow’' manual n8n trigger starts the automation. It immediately flows into the Set Sample Data n8n node, which injects a structured array of user data (name, age, salary, etc.) into the pipeline via a fixed JSON string.

  2. Parallel Execution: The sample data is distributed into three parallel Code n8n nodes, each demonstrating a distinct and valuable data processing technique utilizing JavaScript.

  3. Data Filtering and Transformation: The 'Code: Filter & Transform' n8n node executes custom JavaScript to filter the original dataset, retaining only users over 18. It then calculates a 10% bonus field and creates a specially formatted email string. This process demonstrates how the Code n8n node can enrich data while ensuring each resulting item is returned as a separate n8n item using the .map() function.

  4. Statistical Aggregation: The 'Code: Calculate Stats' n8n node performs statistical analysis on the full dataset. It calculates the total number of employees, average age, total salary, and detailed role distribution using advanced JavaScript reduction methods. This illustrates using the Code n8n node to efficiently reduce many input items into a single summary output, a key task in report generation workflows.

  5. Export Formatting: The 'Code: Format for Export' n8n node takes the data and prepares it for different consumption methods. It generates a plain comma-separated email list, a raw CSV format string, and a tailored JSON structure (jsonForApi) suitable for posting to an external API endpoint. This ensures the output from the n8n workflow is perfectly structured for its destination system, maximizing the utility of this n8n node.

Installation Guide

To start using this powerful n8n workflow demonstration:


  1. Import: Copy the entire n8n workflow JSON provided. In your n8n instance, navigate to 'Workflows' and click 'New'. Select 'Import from JSON' and paste the copied data.

  2. Setup: This specific n8n template requires no external credentials, as it focuses entirely on internal data manipulation within the Code n8n node. It is ready to run immediately.

  3. Execution: Click the 'Execute workflow' button or use the 'Test workflow' function. Review the output of the three separate Code n8n node branches to see the different data transformation results.

  4. Customization: To experiment, modify the JavaScript within any of the Code n8n nodes. Remember that the Code n8n node must always return data in the expected n8n format: an array of objects, typically using the structure return [{ json: data }].

Node Details

When clicking ‘Execute workflow’ (Manual n8n Trigger): Function: Starts the n8n workflow manually for testing and learning purposes. Key Configuration: None, serves as the activation n8n trigger.
Set Sample Data (Set n8n Node): Function: Creates and injects the sample user dataset into the n8n workflow, providing consistent input for the subsequent processing n8n nodes. Key Configuration: Contains a predefined usersJson string of structured user details.
Code: Filter & Transform (Code n8n Node): Function: Demonstrates filtering JavaScript arrays (age > 18) and augmenting data by calculating a 10% bonus field. Key Configuration: Uses JavaScript's .filter() and .map() methods to process and return multiple filtered items in the correct n8n node format.
Code: Calculate Stats (Code n8n Node): Function: Demonstrates efficient data aggregation using JavaScript array methods like .reduce() to calculate comprehensive statistical summaries (averages, totals, distributions). This powerful n8n node reduces the dataset to a single, valuable report item.


  • Code: Format for Export (Code n8n Node): Function: Shows advanced data formatting, generating text-based output (CSV strings, email lists) and custom, restructured JSON payloads, ensuring the n8n workflow output is perfectly prepared for integration with any external system or API.

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all
Created by
David Olusola
David Olusola

I help ambitious businesses eliminate operational bottlenecks and scale faster with AI automation. My clients typically see 40-60% efficiency gains within 90 days. Currently accepting 3 new projects this quarter - [email protected]

Featured*