AI Data Analyst Chatbot for Google Sheets - n8n Workflow

Deploy a powerful n8n workflow that connects an AI agent (GPT-4o) to Google Sheets, enabling complex data analysis and filtering via natural language. Leverage this advanced n8n templates solution.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Business analysts needing immediate data insights from their sheets without manual manipulation.

  • Users looking for advanced n8n templates integrating AI and core data sources.

  • Developers seeking to build custom AI assistants using the power of n8n, LangChain, and sub-workflows.

  • Teams who store transaction data in Google Sheets and require complex filtering, especially by date range and status.

Overview

This solution transforms static Google Sheets data into an interactive, natural language data analyst. Instead of relying on standard formulas or complex manual lookups, users can chat with the AI using plain English questions (ee.g., "How many successful sales did we have in January 2025?"). The core innovation of this n8n workflow lies in its sophisticated structure, utilizing a dedicated sub-workflow activated by a specialized n8n node tool to handle date range queries—a complex task when using standard Google Sheets n8n nodes. The AI Agent dynamically selects the appropriate tool (Google Sheet lookup, Calculator, or the complex date-range tool) to fulfill the request, providing accurate, synthesized data analysis. This showcases the power and flexibility available when building custom n8n templates for data processing.

How it Works

The entire process begins when the When chat message received n8n trigger captures a user's query.

Main Flow (AI Agent):


  1. Input & Context: The user message is passed to the AI Agent n8n node, which maintains conversation context using Buffer Memory and uses the OpenAI Chat Model (GPT-4o) for decision-making.

  2. Tool Orchestration: The AI Agent determines the necessary action. Simple calculations utilize the Calculator n8n node tool. Simple data lookups (by status or product name) use standard Google Sheets n8n node tools.

  3. Complex Query Handling: If the query requires advanced filtering, particularly by date range, the Agent calls the specialized Records by date Workflow Tool. This tool uses the powerful $fromAI function to intelligently extract startdate, enddate, and status parameters from the user's natural language request.

Sub-workflow (Data Extraction Pipeline):


  1. Sub-workflow Activation: The call from the Agent activates the When Executed by Another Workflow n8n trigger, initiating the data pipeline below.

  2. Data Retrieval: A Google Sheets request (HTTP Request) n8n node performs a complex Google Visualization Query (TQL) that specifically handles filtering by date range, bypassing the limitations of simple lookups.

  3. Transformation: The raw JSONP output is cleaned and structured into usable JSON objects by the Code n8n node, ensuring data integrity and correct date formatting.

  4. Refinement: If the query included a status filter, the Filter by status n8n node refines the results.

  5. Consolidation: The Aggregate n8n node combines all processed items into a single payload, which is essential to ensure the comprehensive dataset is returned to the AI Agent for final analysis and summary generation. This completes the n8n workflow execution, providing the final result back to the chat interface.

Installation Guide


  1. Import: Import this n8n workflow JSON into your n8n instance.

  2. Google Sheets Setup: You must first copy the linked Google Sheets file to your own Google Drive. Once copied, ensure you update the Document ID and URL paths in the following n8n node configurations: Records by date, Get transactions by product name, Get all transactions, Get transactions by status, and the Google Sheets request HTTP node.

  3. Credentials: Set up the required credentials.

OpenAI: Provide your API key for the OpenAI Chat Model n8n node (using GPT-4o).
Google Sheets: Configure Google OAuth credentials to grant n8n access to your Google Drive and Sheets data. Ensure these credentials are applied to all Google Sheets-related n8n node elements.

  1. Activation: The main flow uses a When chat message received n8n trigger, which provides a unique webhook URL or chat interface to interact with the deployed AI Agent.

Node Details

When chat message received (n8n trigger): The entry point for the chat, providing the user prompt to the Agent.
AI Agent: The central control mechanism. It uses 15 maximum iterations to solve complex problems and relies on the tools provided below.
OpenAI Chat Model: Configured to use gpt-4o as the core language model for reasoning and output generation.
Records by date (Workflow Tool): A crucial custom n8n node tool that triggers the sub-workflow to retrieve date-filtered data. It dynamically extracts parameters (startdate, enddate, status) using the $fromAI function.
When Executed by Another Workflow (n8n trigger): The entry n8n trigger for the sub-workflow, designed to receive input parameters exclusively from the Records by date tool.
Google Sheets request (HTTP Request): This advanced n8n node uses the Google Visualization Query Language (tq) to execute precise date range filtering directly against the sheet data, which is necessary because native n8n node operations sometimes struggle with this complexity.
Code: An essential custom n8n node used to parse the messy JSONP format returned by the Google Visualization query, transforming it into clean, structured JSON items for analysis.
Aggregate: This final n8n node in the sub-workflow combines all processed results into a single item, ensuring the AI Agent receives a complete dataset instead of a fragmented item list for synthesis and response.

Related n8n Workflows

Free

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

Freelance consultant from Brazil, specializing in automations and data analysis. I work with select clients, addressing their toughest projects. For business inquiries, email me at [email protected] or message me on Telegram for a faster response.

Featured*