# SQL Revenue Analytics

> Clean messy sales logs, warehouse them in SQL, and generate MoM/YTD growth analytics and HTML dashboards.

SQL Revenue Analytics is a paid AI agent skill on Agensi by nwafor lawrence, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $8 (one-time purchase)
- Creator: [nwafor lawrence](https://www.agensi.io/creators/nwafor-lawrence)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0
- Last updated: 2026-11-27
- Security: scan passed (2026-11-27); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/sql-revenue-analytics
- Tags: api, ecommerce, automation, python, sqlalchemy, sql, postgresql, sqlite

## About this skill

Messy transaction logs and missing pricing data break revenue reporting pipelines. This skill automates the ETL process to clean sales files, algebraically repair missing values, and warehouse them in SQL for advanced window-function analytics.

### What it does
- **Data cleaning** Standardizes inconsistent date formats and camelCase headers into a structured schema.
- **Value repair** Algebraically reconstructs missing `unit_price` or `revenue` values using available transaction metadata.
- **SQL warehousing** Upserts cleaned records into SQLite or PostgreSQL using SQLAlchemy to ensure primary key integrity.
- **Window analytics** Executes complex `LAG()` and `SUM() OVER` queries to calculate MoM growth and YTD cumulative revenue.
- **Dashboard generation** Produces a standalone HTML dashboard with Plotly visualizations for monthly trajectories and geographical breakdowns.

### How it works
1. **Validation** Run `run_sql_pipeline.py` with the `--validate-only` flag to check CSV or Excel headers against the required schema.
2. **ETL Execution** Execute the pipeline with `--input` and `--db-url` to process files and upsert data into the warehouse.
3. **Reporting** Review the generated `mom_ytd_analytics.csv` and `sql_revenue_dashboard.html` in your specified output directory.

### Frameworks & tools
Built with Python, Pandas, SQLAlchemy, and Plotly. Supports SQLite and PostgreSQL backends.

### Why this beats prompting it yourself
Writing reliable SQL window functions and algebraic data repair logic in a single prompt often leads to calculation errors or schema mismatches. This skill provides a tested CLI framework that handles edge cases like `#N/A` values, mixed date formats, and transaction deduplication out of the box.

### Use cases
- Migrating messy Shopify or Amazon export files into a structured SQL database.
- Calculating monthly revenue growth percentages for board reporting.
- Recovering total revenue figures when unit prices are missing from manual logs.
- Generating interactive sales dashboards without hosting a BI server.

### Known limitations
Requires specific columns like `transaction_id` and `quantity`. Unparseable timestamps or rows with both missing price and revenue are quarantined.

## Requires

- Python 3.10+
- pandas
- numpy
- SQLAlchemy
- openpyxl
- Optional: PostgreSQL (or built-in SQLite)

Runs locally out of the box with SQLite and zero external API keys after `pip install -r requirements.txt`. Only install `psycopg2-binary` if writing directly to PostgreSQL via `--db-url` or `DATABASE_URL`; pass `--sheet` when targeting a non-default Excel tab.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the SQL Revenue Analytics skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific data fields do I need in my files for the repair logic to work?

The skill requires basic transaction headers such as `transaction_id`, `quantity`, and `date`. It is designed to handle messy inputs, but rows missing both the price and total revenue simultaneously will be quarantined to ensure data integrity.

### What exactly is included in the purchase of this skill?

You will receive the complete Python source code for the ETL pipeline, the SQL schema definitions, a CLI utility for execution, and a README documentation file for quick setup.

### Which database systems and AI agents are compatible with this pipeline?

The skill is built using Python and SQLAlchemy, making it compatible with any AI agent capable of executing Python scripts. It natively supports SQLite for local use and PostgreSQL for production-grade environments.

### How does this perform better than just asking an AI to write a SQL query for me?

Unlike a simple prompt, this skill includes pre-built algebraic logic and SQL window functions that prevent common calculation errors. It handles complex edge cases like mixed date formats and deduplication that basic LLMs often hallucinate or overlook.

### Can I test my sales logs for errors before importing them into the SQL warehouse?

Yes, the skill includes a `--validate-only` flag that allows you to check your data against the required schema and identify formatting issues before any records are actually written to your database.

### Does it support both SQLite and PostgreSQL without code edits?

Yes. By default it writes a local SQLite database (revenue_warehouse.db), and passing --db-url postgresql+psycopg2://... or setting DATABASE_URL automatically uses PostgreSQL syntax (TRUNCATE + DATE_TRUNC + ON CONFLICT DO UPDATE).

### How does the pipeline repair missing unit_price or revenue cells?

When quantity > 0 and either unit_price or revenue is missing (#N/A, ?, FREE), it solves revenue = unit_price * quantity - discount_amount + tax_amount + shipping_amount (or its inverse for unit_price). Rows missing both or lacking a valid timestamp/transaction_id are quarantined to rejected_rows.csv.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
