get_gross_margin โ Gross Margin by Item
Revenue minus cost of goods per item, by month โ which products actually make money.
/SQLQueries) โ dynamic
aggregate SQL returning per-query rows, not a fixed Service Layer entity.Gross-margin report โ revenue minus cost of goods per item, by month. Returns one row
per item ร month with the revenue (from A/R invoice lines), the cogs (from delivery lines),
the gross_margin (revenue โ cogs), and the margin_pct, plus the item name and a
YYYY-MM period label, newest month first. An item invoiced but never delivered shows 100%
margin (no COGS).
Try these prompts
- “show me gross margin by product”
- “which items make money?”
- “profit per item by month”
- “margin for I002”
ื ืกื ืื ืืขืืจืืช
- “ืืฆื ืจืืื ืืืืื ืืคื ืืืฆืจ”
- “ืืืื ืคืจืืืื ืืจืืืืืื?”
- “ืื ืืจืืืืืืช ืฉื ืื ืคืจืื ืืืืืฉ?”
Arguments
| Arg | Required | Meaning |
|---|---|---|
item_code | optional | One product, e.g. I002. Omit for all items. |
Example result
I001 is your margin leader. I001 โ $4,200 revenue, $2,600 COGS, $1,600 margin (38%) for 2025-06. I002 โ $1,900 revenue, $1,700 COGS, $200 margin (11%).
Result columns
| Column | Type | Meaning |
|---|---|---|
item_code | text | The item’s SAP code. |
item_name | text | The item’s name. |
period | text | The invoice month the row covers, YYYY-MM. |
revenue | number | Invoiced revenue for that item in that month, from A/R invoice lines. |
cogs | number | Cost of goods for that item in that month, from delivery lines (0 when nothing shipped). |
gross_margin | number | revenue minus cogs. |
margin_pct | number | gross_margin as a percentage of revenue. |
Charts
None. This tool returns one row per item ร month, so no single column is unique per
row โ a chart keyed on item_name would draw one bar per item per month under a repeated
label. Aggregation belongs in the tool’s SQL, not the chart layer (decided 2026-07-29):
a chart is declarable only where the tool already returns the grain the chart wants. To
chart gross margin, add a tool (or a param) that groups to one row per item.
Related
get_revenue_monthlyโ revenue rollups without cost.report_inventory_valuationโ the money value of on-hand stock.