Natural Language Data Analysis for Google Sheets via Gemini AI - n8n Workflow

Use this powerful n8n workflow to turn natural language questions into structured Google Sheets data queries. Featuring Gemini AI for query parsing and report generation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Data Analysts & Marketers: Who need quick summaries of metrics in Google Sheets without writing complex formulas.

  • Business Users: Seeking instant answers to data questions via a conversational interface built on n8n.

  • Automation Developers: Looking for advanced n8n templates integrating Langchain concepts (Agents, Tools, Parsers) with core n8n node functionalities.

Overview

Analyzing large datasets in Google Sheets often requires manual effort or complex pivot tables. This advanced n8n workflow solves this problem by creating a conversation layer powered by Google's Gemini AI. The core value of this n8n automation is its ability to interpret ambiguous human language (e.g., "Show total Spend by Channel") and translate it into a precise, executable instruction set (column, aggregation, level). This ensures accurate data retrieval and aggregation using standard n8n node logic, followed by a final formatting step using Gemini AI to present the results cleanly. It’s an ideal example of how to leverage n8n to build sophisticated, AI-driven data tools, reducing friction for end-users and showcasing the power of n8n templates.

How it Works

This n8n workflow operates in two main phases: Query Parsing (Main Workflow) and Data Processing (Sub-Workflow).

Phase 1: Query Parsing (Main Workflow)


  1. Input: The user provides a natural language query (e.g., "What is the average Spend by Channel?").

  2. AI Agent Processing: The request enters the Talk to Data with Gemini n8n node (an AI Agent). This Agent uses the Google Gemini Chat Model and a Simple Memory n8n node for context retention.

  3. Schema Understanding: The Agent utilizes the Get Column Info Google Sheets tool to dynamically inspect the data structure, ensuring it only generates queries based on actual column names in the sheet.

  4. Structured Output: A Structured Output Parser n8n node forces the Gemini Agent to convert the natural language query into a strict JSON object specifying the target column, the required aggregation (sum, avg, countd, etc.), and the level of detail (level).

  5. Execution Transfer: The main n8n workflow passes this structured JSON query to a dedicated sub-workflow via the Execute Workflow - Summarize Data n8n node.

Phase 2: Data Processing (Sub-Workflow)


  1. Trigger and Data Fetch: The sub-workflow starts using the When Executed by Another Workflow n8n trigger, receiving the structured JSON query. It uses a Google Sheets n8n node (Get Data) to pull the necessary source data.

  2. Conditional Routing: The Type of Aggregation Switch n8n node routes the data flow based on the aggregation type specified by the AI (e.g., if the aggregation is 'sum', it routes to the Sum node; if 'countd', to Count Unique).

  3. Data Summarization: One of the dedicated Summarize n8n node runs the aggregation logic (Sum, Average, Count Unique, Min, Max, Count), grouped by the specified level.

  4. Collection: The Bring All Data together Aggregate n8n node collects the results from the successful aggregation branch.

  5. Final Presentation: The final raw data is sent to the Write into Table Output AI Agent n8n node, which uses the Google Gemini Chat Model1 to re-format the data into a clean, human-readable table or summary before returning the final result.

Installation Guide

To deploy this comprehensive n8n workflow template, you must configure both Google Sheets and Google Gemini credentials.

1. Import the n8n Workflow


  1. Copy the entire provided n8n workflow JSON.

  2. In your n8n instance, click 'New' -> 'Import from JSON'.

  3. Paste the code and save the new n8n workflow.

2. Configure Google Gemini Credentials

This n8n template uses Gemini AI for parsing and output formatting.

  1. Obtain an API Key from Google AI Studio.

  2. In the Talk to Data with Gemini and Google Gemini Chat Model1 n8n node, click 'Create New Credential'.

  3. Select 'Google PaLM API' and paste your API key.

3. Configure Google Sheets Credentials and Data Source

This n8n workflow requires OAuth 2.0 access to your Google Drive.

  1. Enable the Google Sheets API in your Google Cloud Console project and create an OAuth 2.0 Client ID.

  2. In the Get Column Info and Get Data n8n node, create a new 'Google Sheets OAuth2 API' credential and complete the authentication flow.

  3. Update Sheet IDs: Ensure the Google Sheets n8n nodes (Get Column Info and Get Data) point to your actual spreadsheet document ID and sheet names. The example uses a sheet named 'Data' and fetches column metadata from 'Columns'.

Node Details

When Executed by Another Workflow (n8n trigger): This node acts as the entry point for the sub-workflow, receiving the structured query parameters (column, aggregation, level) from the main n8n workflow.
Google Sheets Tool (Get Column Info): A crucial tool within the main n8n workflow's AI Agent. Its function is to provide the Gemini model with the exact schema (column names and types) of the Google Sheet data, ensuring the generated query is valid.
Google Gemini Chat Model / Agent (n8n node): Used as the backbone for the AI functionality. In the main workflow, it powers the Agent to interpret natural language and produce structured JSON. In the sub-workflow (Google Gemini Chat Model1), it is used for final result formatting.
Structured Output Parser (n8n node): Enforces a specific JSON format output from the AI Agent, standardizing the query for subsequent data processing n8n nodes.
Execute Workflow (n8n node): Passes the structured query parameters from the parsing phase to the dedicated data aggregation sub-workflow, enabling modular design for this complex n8n automation.
Google Sheets (Get Data) (n8n node): Fetches the necessary rows from the data sheet once the query is defined.
Switch (Type of Aggregation) (n8n node): A core logic n8n node that dynamically routes the data to the correct aggregation method (Sum, Average, Count Unique, etc.) based on the parameter determined by the AI Agent.
Summarize (n8n node): Multiple instances (Sum, Average, Min, Max, Count Unique, Count) execute the actual data aggregation and grouping based on the column and level passed from the initial query. These are essential processing steps in the n8n workflow.


  • Aggregate (Bring All Data together) (n8n node): Collects the output from the successful aggregation path, ensuring a unified result set before final output formatting.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by

Professional services consultant with over 10 years of experience solving complex business problems across industries. I specialize in n8n and process automation—designing custom workflows that integrate tools like Google Calendar, Airtable, GPT, and internal systems. Whether you need to automate scheduling, sync data, or streamline operations, I build solutions that save time and drive results.

Featured*