get_gross_margin โ€” Gross Margin by Item

Revenue minus cost of goods per item, by month โ€” which products actually make money.

This is a Named SQL Query (SAP /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

ArgRequiredMeaning
item_codeoptionalOne 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

ColumnTypeMeaning
item_codetextThe item’s SAP code.
item_nametextThe item’s name.
periodtextThe invoice month the row covers, YYYY-MM.
revenuenumberInvoiced revenue for that item in that month, from A/R invoice lines.
cogsnumberCost of goods for that item in that month, from delivery lines (0 when nothing shipped).
gross_marginnumberrevenue minus cogs.
margin_pctnumbergross_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.

  • get_revenue_monthly โ€” revenue rollups without cost.
  • report_inventory_valuation โ€” the money value of on-hand stock.