Natural Language Google Sheets Data Analysis with Gemini AI

Go to Workflow
0 views
Built by Robert Breen Robert Breen
Created on June 05, 2026

Description


This n8n workflow template creates an efficient data analysis system that uses Google Gemini AI to interpret user questions about spreadsheet data and processes them through a specialized sub-workflow for optimized token usage and faster responses.

What This Workflow Does

Smart Query Parsing**: Uses Gemini AI to understand natural language questions about your data
Efficient Processing**: Routes calculations through a dedicated sub-workflow to minimize token consumption
Structured Output**: Automatically identifies the column, aggregation type, and grouping levels from user queries
Multiple Aggregation Types**: Supports sum, average, count, count distinct, min, and max operations
Flexible Grouping**: Can aggregate data by single or multiple dimensions
Token Optimization**: Processes large datasets without overwhelming AI context limits

Tools Used

Google Gemini Chat Model** - Natural language query understanding and response formatting
Google Sheets Tool** - Data access and column metadata extraction
Execute Workflow** - Sub-workflow processing for data calculations
Structured Output Parser** - Converts AI responses to actionable parameters
Memory Buffer Window** - Basic conversation context management
Switch Node** - Routes to appropriate aggregation method
Summarize Nodes** - Performs various data aggregations

📋 MAIN WORKFLOW - Query Parser

What This Workflow Does
The main workflow receives natural language questions from users and converts them into structured parameters that the sub-workflow can process. It uses Google Gemini AI to understand the intent and extract the necessary information.

Prerequisites for Main Workflow
Google Cloud Platform account with Gemini API access
Google account with access to Google Sheets
n8n instance (cloud or self-hosted)

Main Workflow Setup Instructions

1. Import the Main Workflow
Copy the main workflow JSON provided
In your n8n instance, go to Workflows → Import from JSON
Paste the JSON and click Import
Save with name: "Gemini Data Query Parser"

2. Set Up Google Gemini Connection
Go to Google AI Studio
Sign in with your Google account
Go to Get API Key section
Create a new API key or use an existing one
Copy the API key

Configure in n8n:
Click on Google Gemini Chat Model node
Click Create New Credential
Select Google PaLM API
Paste your API key
Save the credential

3. Set Up Google Sheets Connection for Main Workflow
Go to Google Cloud Console
Create a new project or select existing one
Enable the Google Sheets API
Create OAuth 2.0 Client ID credentials
In n8n, click on Get Column Info node
Create Google Sheets OAuth2 API credential
Complete OAuth flow

4. Configure Your Data Source
Option A: Use Sample Data
The workflow is pre-configured for: Sample Marketing Data
Make a copy to your Google Drive

Option B: Use Your Own Sheet
Update Get Column Info node with your Sheet ID
Ensure you have a "Columns" sheet for metadata
Update sheet references as needed

5. Set Up Workflow Trigger
Configure how you want to trigger this workflow (webhook, manual, etc.)
The workflow will output structured JSON for the sub-workflow

⚙️ SUB-WORKFLOW - Data Processor

What This Workflow Does
The sub-workflow receives structured parameters from the main workflow and performs the actual data calculations. It handles fetching data, routing to appropriate aggregation methods, and formatting results.

Sub-Workflow Setup Instructions

1. Import the Sub-Workflow
Create a new workflow in n8n
Copy the sub-workflow JSON (embedded in the Execute Workflow node)
Import as a separate workflow
Save with name: "Data Processing Sub-Workflow"

2. Configure Google Sheets Connection for Sub-Workflow
Apply the same Google Sheets OAuth2 credential you created for the main workflow
Update the Get Data node with your Sheet ID
Ensure it points to your data sheet (e.g., "Data" sheet)

3. Configure Google Gemini for Output Formatting
Apply the same Gemini API credential to the Google Gemini Chat Model1 node
This handles final result formatting

4. Link Workflows Together
In the main workflow, find the Execute Workflow - Summarize Data node
Update the workflow reference to point to your sub-workflow
Ensure the sub-workflow is set to accept execution from other workflows

Sub-Workflow Components
When Executed by Another Workflow**: Trigger that receives parameters
Get Data**: Fetches all data from Google Sheets
Type of Aggregation**: Switch node that routes based on aggregation type
Multiple Summarize Nodes**: Handle different aggregation types (sum, avg, count, etc.)
Bring All Data Together**: Combines results from different aggregation paths
Write into Table Output**: Formats final results using Gemini AI

Example Usage

Once both workflows are set up, you can ask questions like:

Overall Metrics:
"Show total Spend ($)"
"Show total Clicks"
"Show average Conversions"

Single Dimension:
"Show total Spend ($) by Channel"
"Show total Clicks by Campaign"

Two Dimensions:
"Show total Spend ($) by Channel and Campaign"
"Show average Clicks by Channel and Campaign"

Data Flow Between Workflows
Main Workflow: User question → Gemini AI → Structured JSON output
Sub-Workflow: Receives JSON → Fetches data → Performs calculations → Returns formatted table

Contact Information


For support, customization, or questions about this template:

Email**: [email protected]
LinkedIn**: Robert Breen

Need help implementing these workflows, want to remove limitations, or require custom modifications? Reach out for professional n8n automation services and AI integration support.

Nodes Used (5)

AI Agent
@n8n/n8n-nodes-langchain.agent
Google Gemini Chat Model
@n8n/n8n-nodes-langchain.lmChatGoogleGemini
Google Sheets
n8n-nodes-base.googleSheets
Simple Memory
@n8n/n8n-nodes-langchain.memoryBufferWindow
Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured