Monthly sales trend
Net invoiced sales per month for the last 12 months.
Tool
SELECT YEAR(T0.DocDate) AS SalesYear, MONTH(T0.DocDate) AS SalesMonth, COUNT(T0.DocEntry) AS Invoices, SUM(T0.DocTotal - T0.VatSum) AS NetSales FROM OINV T0 WHERE T0.CANCELED = 'N' AND T0.DocDate >= DATEADD(month, -12, GETDATE()) GROUP BY YEAR(T0.DocDate), MONTH(T0.DocDate) ORDER BY SalesYear, SalesMonth
SELECT YEAR(T0."DocDate") AS "SalesYear", MONTH(T0."DocDate") AS "SalesMonth", COUNT(T0."DocEntry") AS "Invoices", SUM(T0."DocTotal" - T0."VatSum") AS "NetSales" FROM OINV T0 WHERE T0."CANCELED" = 'N' AND T0."DocDate" >= ADD_MONTHS(CURRENT_TIMESTAMP, -12) GROUP BY YEAR(T0."DocDate"), MONTH(T0."DocDate") ORDER BY "SalesYear", "SalesMonth"
What this query answers
The owner wants a simple 12-month view of invoiced sales for the board pack or a dashboard tile: is revenue growing, flat or seasonal? One row per month is enough to drop straight into an Excel line chart.
Sample output
Illustrative demo values. Your columns are the same; the numbers come from your company.
| SalesYear | SalesMonth | Invoices | NetSales |
|---|---|---|---|
| 2026 | 7 | 212 | 184300 |
| 2026 | 8 | 198 | 171950 |
| 2026 | 9 | 236 | 205480 |
| 2026 | 10 | 171 | 149200 |
SQL Server vs SAP HANA
DATEADD(month, -12, GETDATE()) becomes ADD_MONTHS(CURRENT_TIMESTAMP, -12). YEAR() and MONTH() exist in HANA with the same meaning, so the GROUP BY is unchanged apart from quoting.
Common errors and fixes
- The first month looks too low: The window starts on today's day number 12 months ago, so the oldest month is only partly included. Start from the first day of that month (for example DATEFROMPARTS on SQL Server) if you need 12 full months.
- Months with no sales are missing: GROUP BY only returns months that have invoices. Join to a calendar or month list if your chart needs a zero for empty months.
- Figures do not match the Sales Analysis report: This query reads A/R invoices only. Subtract credit notes from ORIN by month to get net sales after returns.
- Totals don't match the Sales Analysis report (header discount): This query reads DocTotal - VatSum from the document header, which already includes the header discount (OINV.DiscPrcnt), plus freight. If you change it to sum INV1.LineTotal, for example for item revenue, the header discount is not inside LineTotal and the line sum overstates sales. Use SUM(T1.LineTotal * (1 - T0.DiscPrcnt / 100.0)) (HANA: SUM(T1."LineTotal" * (1 - T0."DiscPrcnt" / 100.0))), and subtract credit memos (ORIN/RIN1) with the same factor. See SAP B1 sales total mismatch: header discount fix.
Need this report built into SAP Business One?
A saved query answers the question once. We build SAP Business One reports and dashboards on SQL Server and HANA, and you own the files. Or hire a remote SAP Business One developer for the whole job, fixed price per phase.
Related queries
Table reference: OINV table (A/R Invoice (header))
Three steps, no signup
Copy the right version
Use the SQL Server tab for MS SQL databases and the HANA tab for SAP B1 on HANA.
Open Query Generator
In SAP Business One go to Tools → Queries → Query Generator, paste and click Execute.
Save and share
Click Save, pick a category and give the query a name. Your team can run it from Query Manager.
Questions about this tool
How do I run the monthly sales trend query in SAP Business One?
Copy the version that matches your database, open Tools → Queries → Query Generator, paste it in the SQL box and click Execute. Save it to reuse it later.
Which tables does this query use?
It reads OINV from the standard SAP Business One schema. No user-defined fields are needed.
Can this be turned into a dashboard or alert?
Yes. We turn queries into Crystal reports, Excel reports that refresh themselves, SAP B1 alerts or WhatsApp messages for managers.
Built for SAP Business One teams
Need this inside SAP Business One?
We build add-ons, reports and integrations for SAP B1 on SQL Server and HANA. Tell us what you need and get a fixed price, usually within 24 hours.
