How to Analyze Gross Margin Using AI
Review gross margin by period and product group with an AI agent connected to Cube. Start with the approved metric definition, then inspect the numerator and denominator behind each change.
- Confirm the approved gross profit and net revenue metrics
- Compare historical margin by month and product group
- Trace changes to modeled revenue and cost of goods sold
What is gross margin analysis with AI?
Gross margin analysis compares gross profit with net revenue across a defined period. Finance, product, and data teams use it to review how reported margin changes by month, product, or customer segment. The formula and adjustments depend on the approved business definition in the data model.
An AI agent can query those modeled metrics, compare trends, and summarize gaps. Cube's semantic layer for AI gives the agent approved metrics and dimensions to work from, while deployment access rules govern what it can query. This workflow reviews historical results; it does not forecast future margin or establish why a change occurred. If a definition or input is missing, the agent should report the gap rather than invent a result.
Define gross margin before comparing periods
Confirm the approved metric, currency, grain, and treatment of discounts, refunds, freight, and cost allocations before reviewing changes.
| Metric | Illustrative example |
|---|---|
| Reporting period | April, May, and June 2026: three complete calendar months in the model reporting timezone. |
| Net revenue | June total: $1,200,000 — Core $800,000 and Premium $400,000. |
| Cost of goods sold (COGS) | June total: $720,000 — Core $520,000 and Premium $200,000. |
| Gross profit and margin | Gross profit totals $480,000. If the approved formula is gross profit ÷ net revenue, $480,000 ÷ $1,200,000 = 40%. |
Copy. Paste. Run your gross margin review.
Connect to Cube through MCP or the CLI, then run the prompt below in your preferred agent.
Start with a Cube deployment connected to your data and a model containing the metrics you want to analyze.
Connect over MCP
Connect your agent to your existing Cube deployment and sign in through OAuth.
https://cubecloud.dev/mcp
Complete OAuth in your agent to connect your Cube account.
Use your default deployment or select another one available to your account.
Connect with CLI
Install the Cube CLI and sign in from a terminal-capable agent.
curl -fsSL https://raw.githubusercontent.com/cube-js/cube/master/install-cli.sh | sh
cube login --url https://TENANT.cubecloud.dev
cube spec --json
02Run this prompt in your agent
Choose your agent and copy the prompt below.
Use the Cube MCP server connected in Codex and select the intended deployment. Run read-only analytics queries. Run a historical gross margin review using my connected Cube deployment.Use read-only analytics requests. Keep credentials and row-level identifiers private. DEFINITIONSBefore querying, inspect the model for approved gross margin, gross profit,net revenue, and cost of goods sold (COGS) metrics. Report their formulas,currency, grain, dimensions, filters, time zone, and any defined adjustmentssuch as discounts, refunds, freight, returns, or allocations. Use the modeledgross margin metric as the source of truth. Calculate gross profit dividedby net revenue only when that is the approved formula; derive gross profitfrom net revenue and COGS only when that relationship is approved. Do notinfer missing inputs or silently substitute a proxy. ANALYSIS1. Review the last three complete calendar months, ending with the latest fully closed month. Use the model's reporting time zone and state the inclusive start and end dates for every month. If a month is incomplete or has partial data, disclose that and exclude it from comparisons.2. For each month, report net revenue, gross profit and COGS when available, gross margin, and the numerator and denominator used. Compare monthly margin changes in percentage points. Compute an overall rate from the approved aggregate numerator and denominator; do not average segment rates or sum ratios.3. Break results out by product group and, when available, customer segment. Use the same definitions, currency, and filters as the overall result. Report segment numerators and denominators, flag small samples, and state whether historical membership uses point-in-time or current assignments.4. Reconcile segment amounts to totals when the model grain permits. Identify missing periods, currencies, dimensions, filters, and data-quality gaps. Describe mix and metric changes as observations, not proven causes. OUTPUTReturn the metric definitions and time zone, exact date filters, a monthlysummary, a segment table, and a concise interpretation. Show the numeratorand denominator behind every reported rate. Separate observed changes fromhypotheses, and list follow-up checks that could test those hypotheses.Do not forecast future margin or claim causal drivers without supporting data.
How it works
Confirm the metric and reporting window
Check the model's approved gross margin, gross profit, and net revenue definitions, then set three complete months in the model's reporting timezone.
Compare monthly and segment results
Review each month's numerator, denominator, and margin. Compare product groups on the same basis and calculate the overall rate from aggregated values rather than averaging segment percentages.
Investigate the observed change
Check modeled cost, revenue, discount, refund, allocation, and product mix details before suggesting an explanation. Treat causes as hypotheses until the source data supports them.
Compare the trend with product groups
The monthly trend and June product group table use fictional values. They illustrate a historical review; the approved metric definition determines real results.
| Period / product group | Net revenue | COGS | Gross profit | Gross margin |
|---|---|---|---|---|
| April · total | $1,000,000 | $620,000 | $380,000 | 38.0% |
| May · total | $1,100,000 | $715,000 | $385,000 | 35.0% |
| May · Core | $700,000 | $455,000 | $245,000 | 35.0% |
| May · Premium | $400,000 | $260,000 | $140,000 | 35.0% |
| June · Core | $800,000 | $520,000 | $280,000 | 35.0% |
| June · Premium | $400,000 | $200,000 | $200,000 | 50.0% |
| June · total | $1,200,000 | $720,000 | $480,000 | 40.0% |
- In this fictional example, June margin is $480,000 ÷ $1,200,000 = 40.0%, compared with $385,000 ÷ $1,100,000 = 35.0% in May, a 5.0 percentage-point increase. The overall rate comes from aggregate values, not the arithmetic mean of the product group rates.
- Premium is 50.0% in June ($200,000 ÷ $400,000), up from 35.0% in May ($140,000 ÷ $400,000). Core remains 35.0% ($245,000 ÷ $700,000 in May; $280,000 ÷ $800,000 in June). These figures show where the rate changed, but they do not identify why.
- June gross profit totals $480,000 ($280,000 Core plus $200,000 Premium), COGS totals $720,000, and net revenue totals $1,200,000. Review the approved cost allocation, discount and refund treatment, and product mix before explaining the change.
All figures in the table and images are fictional illustrations, not executed queries, customer results, benchmarks, or predictions. Real results depend on the approved metric definitions, available data, and access permissions in your Cube deployment.