Someone asked me for code to get monthly SOP sales and I could have sworn I already had that. But I searched and didn’t come up with anything, so here is a new view to show SOP sales (the total of SOP invoices less returns) by month. As usual, I am making a few assumptions (listed in the view comments), and am hard coding one year at a time (2013 in this example). You can easily change the year as needed on line 59.
create view view_Sales_by_Customer_by_Month as -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -- view_Sales_by_Customer_by_Month -- Created June 7, 2013 -- by Victoria Yudin - Flexible Solutions, Inc. -- For updates see http://victoriayudin.com/gp-reports/ -- Returns total sales (invoices - returns) for each customer -- by month (for the specified year) -- Amount used is the invoice total (including freight, -- taxes, discounts, etc.) -- Only posted invoices and returns are included -- Shows functional currency -- Voided transactions are excluded -- Document Date is used (not GL Posting Date) -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ select d.CUSTNMBR Customer_ID, d.CUSTNAME Customer_Name, sum(case when month(d.DOCDATE) = 1 then d.SALES else 0 end) Jan_Sales, sum(case when month(d.DOCDATE) = 2 then d.SALES else 0 end) Feb_Sales, sum(case when month(d.DOCDATE) = 3 then d.SALES else 0 end) Mar_Sales, sum(case when month(d.DOCDATE) = 4 then d.SALES else 0 end) Apr_Sales, sum(case when month(d.DOCDATE) = 5 then d.SALES else 0 end) May_Sales, sum(case when month(d.DOCDATE) = 6 then d.SALES else 0 end) Jun_Sales, sum(case when month(d.DOCDATE) = 7 then d.SALES else 0 end) Jul_Sales, sum(case when month(d.DOCDATE) = 8 then d.SALES else 0 end) Aug_Sales, sum(case when month(d.DOCDATE) = 9 then d.SALES else 0 end) Sep_Sales, sum(case when month(d.DOCDATE) = 10 then d.SALES else 0 end) Oct_Sales, sum(case when month(d.DOCDATE) = 11 then d.SALES else 0 end) Nov_Sales, sum(case when month(d.DOCDATE) = 12 then d.SALES else 0 end) Dec_Sales, sum(d.SALES) Yearly_Total from (select s.DOCDATE, s.CUSTNMBR, c.CUSTNAME, case s.SOPTYPE when 3 then s.DOCAMNT when 4 then s.DOCAMNT*-1 end SALES from SOP30200 s left outer join RM00101 c on s.CUSTNMBR = c.CUSTNMBR where s.VOIDSTTS = 0 and s.SOPTYPE in (3,4) and year(s.DOCDATE) = 2013 --change year as needed ) d group by d.CUSTNMBR, d.CUSTNAME -- add permissions for DYNGRP go grant select on view_Sales_by_Customer_by_Month to DYNGRP
Disclaimer: I tested this on limited data, if you find an issue or have a suggestion for improvement, please let me know and I will post the update here for everyone.
Filed under: Dynamics GP, GP Reports code, GP SQL scripts, SOP SQL code Tagged: featured, GP Reports code, GP SQL view, Sales Order Processing
