Auto-Generate Monthly Financial Reports with n8n + Gemini AI
SQL data → AI analysis → HTML report → Outlook email, automatically delivered monthly per Cost Center
- Who
- Teams needing automated monthly financial reports for multiple departments or cost centers, using ERPNext or MySQL/PostgreSQL databases
- You get
- Automatically triggers monthly to generate HTML reports with P&L, WIP, and employee stats for each Cost Center, analyzed by Gemini AI and sent via email
Constraints
Prerequisites: n8n instance (self-hosted or Cloud), MySQL/PostgreSQL/ERPNext database, Microsoft Outlook or Gmail account, Google Gemini API Key. Understanding of your data schema is required to adapt SQL queries. Template defaults to ERPNext schema (tabBudget Group Detail, tabGL Entry, tabProject, tabEmployee). The Filter node hardcodes 'AI DEPARTMENT' for testing; update or remove for production.
What they did
Author Amjid Ali created an n8n template that automatically triggers monthly via Schedule Trigger, fetches financial data from SQL (ERPNext/MySQL) for each Cost Center, processes through Loop Over Items, analyzes with Google Gemini 2.5 Pro AI Agent, and sends structured HTML reports via Microsoft Outlook. The template includes complete SQL queries, Code nodes for HTML conversion, AI Agent prompt, and email configuration.
How it went
Author reports saving 2-3 days of manual work per month (author_report), with multi-division/multi-company scalability, providing budget vs actual, P&L, WIP, and per-employee KPIs. Published on n8n.io with video tutorial and guidebook.
Worth knowing
1. Database schema targets ERPNext (tabBudget Group Detail, tabGL Entry, tabProject, tabEmployee); other databases require SQL rewrites. 2. Filter node hardcodes 'AI DEPARTMENT' for testing—update for production. 3. Outlook recipient defaults to [email protected] and must be replaced. 4. AI Agent prompt references specific company name (Syncbricks LLC); replace with your own. 5. Template supports swapping to DeepSeek/GPT/Claude but is configured for Gemini 2.5 Pro. 6. SQL nodes can be AI-assisted or replaced with Excel/Google Sheets. 7. Not tested by this site; reproduction=not_tested.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- After import, connect your own credentials on auth-required nodes; author secrets are not included.
Configuration to replace
- Source template is n8n public workflow #3617 (~30 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-24
Steps
Set up scheduled trigger and time calculation
Configure the Schedule Trigger node in n8n to fire on the 5th of each month. Connect to the Date & Time node to capture the current date, then use the PreviousMonth Code node to calculate the previous month and year (outputs previousMonth and year for dynamic SQL filtering).
Fetch and loop over Cost Centers
Use the Get Cost Centers with Budgets SQL node to query all cost centers with budget and GL data for the period. Optionally use the Filter node to limit to a specific Cost Center (e.g., 'AI DEPARTMENT') for testing. Then Loop Over Items iterates through each cost center to generate individual reports.
Query four financial data streams in parallel
For each Cost Center, execute four SQL queries simultaneously: 1) YTD vs Previous Month1: budget vs actual revenue/expenses (YTD and prior month); 2) Departments: income, expenses, and profit by vertical (sub-division); 3) Projects: contract value, invoice %, cost %, WIP; 4) Employees: headcount, joined this year/month. All queries use dynamic month/year from PreviousMonth.
Merge data into HTML report
Each query result passes through CostCenter, verticalPL, WIP1, and Employees1 Code nodes to convert to HTML tables. The Merge node combines all four tables, and the Code node assembles them into a single responsive HTML page with styled sections: Financial Overview – YTD & PM Summary, Vertical Profit & Loss, WIP Summary, and Employees.
AI Agent analysis and report refinement
Feed the merged HTML into the Business Performance AI Agent node, which calls Google Gemini 2.5 Pro for structured financial analysis. The AI generates an executive summary, standard P&L analysis (with budget vs actual, gross margin, net margin), vertical performance summary, project progress, and per-employee revenue/profit metrics, outputting optimized HTML with CSS styling.
Execution prompt · Source text。Business Performance AI Agent (Analyst) node text parameter (promptType=define)
=You are a Business Performance Analyst Expert in Financial Management of Syncbricks LLC, you willbe given an input to Analyze the Financial Performance of syncbricks which is an AI and Automation Company. The sections Given to you will be below 1. Financial Overview – YTD & PM Summary (whis is income and expense of the Company, this data doesn't include the calculation of Gross Profit and Net Profit that you must do. This should be used together in one section only don't seperate them) 2. Financial Overview – Vertical Profit & Loss (This containers the Verticials within the Cost Center, these are in fact the Sub Business Unit, you don't need to calculate anything but the information is for analysis to see how the Verticals within the Business Unit Perfored ) 3. Financial Overview – WIP Summary (This is the Projects Summary about how many projects are currently open and work is the WIP - Work in Process of the Project, the WIP figure should be added for Profit and Loss Statement Under Proejct Reveneu as expected WIP) 4. Employees in the Business Unit (These will be the number of Employees who are directly working in this BU, which means these employees are only serving the Company, other staff which are in back office support are not included in this. ) *** Your Role *** Your Role is to Prepare a comprehensive Report : 1. Executive Summary : Tell how was the overall performance of the Business Unit. 2. Analayze the Financial Overview - YTD together with PM Summary (Which is Previous Month) which is previous month Income and Expenses you must use Proper Strcuture of Financial Statement with Budget Vs Actuals (follow same input already given). You must use the Section that will be shared with you in detail that says "Financial Overview – YTD & PM Summary " and from there you must ensure to create sections based on best Practices of Performance Analysis that should include; Section: Revenue -Projects - Revenue -Trading - Revenue -Service - Revenue Net Sales (Total) Section: Project Work in Process WIP (Revenue to Book) Total: Gross Sale Section: Cost of Sale Projects - COGS Trading - COGS Service - COGS Total Cost of Sales Gross Profit Other Income Gross Income Section: Indirect Cost (here you must all the detail of expenses from "Financial Overview – YTD & PM Summary" Then you must calculate Profit / (Loss) before tax NP % to Revenue Use the calculator tool to ensure precise calculations. - Don't add decimals give format in currency but don't add symbol. Use the standard P&L Format where you should first use Sale, then Cost of Sale and GP, then use Indirect Expenses and then Net Profile. Ensure to calculate the Perentages as well. 3. Provide the Summary of the Verticials Performance with their Profit and Loss and Percetage and Total of all Verticlals 4. Current Project Progress. 5. Employees Summary, Number of Employees, How many joined in this Year and what is per Eployee Revenue and Gross Profit Analyze Overall Performance of the Company and provide the Business Managers an Overview of what should be done next. Calculate per employee profit as well and suggest what is the performance overall **Tools** Use calculator tool to do all calculations for accurate calculations ** Formatting and Output ** Give output in html format fully responsive in with beauty added using CSS, ready to be shared with all possible tables, in hightly attracrtive format, headings, add colors green for good, red for bad, organge for acceptable and so on, also add remarks to show how the performance was, enusre to response as if you were as an Expert in Analyzing the Bususiness Performance. Don't add any other infomration or symbols which are not part of html. Don't give additional message saying ok, I will do and so on. Align Text in table on left and numbers on right Number formatting : ##,### Here is the data Month : {{ $('PreviousMonth').first().json.previousMonth }} Year : {{ $('PreviousMonth').first().json.year }} {{ $json.html }}Send email report
The Financial Performance Code node cleans markdown code block markers from the AI output. The Email Data node assembles subject, body, and month info. The Microsoft Outlook node sends the HTML email to the configured recipient (default placeholder [email protected] must be replaced).
Control loop interval
The Wait node pauses for a configured duration (default: minutes) to prevent email overload or API rate limiting when processing multiple Cost Centers, then returns to Loop Over Items for the next iteration.
Prompt you can copy
Setup guidance · Editorial suggestion。Give to setup assistant to confirm inputs and credentials first
This block is the prompt. Ads are never placed here.
You are setting up an n8n automation workflow to auto-generate and send monthly financial reports. Core flow: Schedule Trigger (5th of each month) → SQL queries (YTD/prior month finances, departments, projects, employees) → Loop Over Items per Cost Center → merge to HTML → Gemini AI Agent analysis → Outlook email delivery. Confirm you have: n8n instance, database connection (ERPNext/MySQL/PostgreSQL), Gemini API Key, Outlook/Gmail credentials. To swap data sources, replace SQL nodes with Excel/Google Sheets/Airtable/API while maintaining the same output structure.
This prompt is for understanding the overall architecture and prerequisites, not a node execution instruction. The actual AI Agent prompt is in step 5.
Source
Generate monthly financial reports with Gemini AI, SQL, and Outlook · amjid · n8n.io · 2025-04-19
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.