Monthly sales matrix

select distinct TRANS_counselid,
Decode(upper(months),'APR', total_qty, 0) As April,
Decode(upper(months),'MAY', total_qty, 0) As May,
Decode(upper(months),'JUN', total_qty, 0) As June,
Decode(upper(months),'JUL', total_qty, 0) As July,
Decode(upper(months),'AUG', total_qty, 0) As August,
Decode(upper(months),'SEP', total_qty, 0) As Sept,
Decode(upper(months),'OCT', total_qty, 0) As October,
Decode(upper(months),'NOV', total_qty, 0) As November,
Decode(upper(months),'DEC', total_qty, 0) As December,
Decode(upper(months),'JAN', total_qty, 0) As January,
Decode(upper(months),'FEB', total_qty, 0) As February,
Decode(upper(months),'MAR', total_qty, 0) As March,total_qty
from (select TRANS_counselid,
to_char(TRANS_DATE,'MON') months,
sum(TRANS_AMOUNT) total_qty
from LEGAL_TRANS
group by TRANS_counselid, to_char(TRANS_DATE,'MON'))
This gives me a monthly report in a matrix format but though it gives a monlthy figure in each month for trans_counselid it creates a new row for each month. Is there any way to make it show trans_counselid on only 1 row ?
Thanks in advance

not quite understand what you mean,
some sample data might help.
anyway, this is my guessing
WITH legal_trans as (
  select 1 trans_counselid, to_date('01-01-06','DD-MM-YY') trans_date, 10 trans_amount from dual union all
  select 1 trans_counselid, to_date('01-02-06','DD-MM-YY') trans_date, 20 trans_amount from dual union all
  select 2 trans_counselid, to_date('01-02-06','DD-MM-YY') trans_date, 20 trans_amount from dual union all
  select 3 trans_counselid, to_date('01-03-06','DD-MM-YY') trans_date, 30 trans_amount from dual union all
  select 4 trans_counselid, to_date('01-04-06','DD-MM-YY') trans_date, 40 trans_amount from dual union all
  select 5 trans_counselid, to_date('01-05-06','DD-MM-YY') trans_date, 50 trans_amount from dual union all
  select 6 trans_counselid, to_date('01-06-06','DD-MM-YY') trans_date, 60 trans_amount from dual union all
  select 7 trans_counselid, to_date('01-07-06','DD-MM-YY') trans_date, 70 trans_amount from dual union all
  select 8 trans_counselid, to_date('01-08-06','DD-MM-YY') trans_date, 80 trans_amount from dual union all
  select 9 trans_counselid, to_date('01-09-06','DD-MM-YY') trans_date, 90 trans_amount from dual union all
  select 9 trans_counselid, to_date('01-10-06','DD-MM-YY') trans_date, 90 trans_amount from dual
SELECT DISTINCT trans_counselid,
  SUM(decode(UPPER(MONTHS), '04', total_qty, 0)) AS april,
  SUM(decode(UPPER(MONTHS), '05', total_qty, 0)) AS may,
  SUM(decode(UPPER(MONTHS), '06', total_qty, 0)) AS june,
  SUM(decode(UPPER(MONTHS), '07', total_qty, 0)) AS july,
  SUM(decode(UPPER(MONTHS), '08', total_qty, 0)) AS august,
  SUM(decode(UPPER(MONTHS), '09', total_qty, 0)) AS sept,
  SUM(decode(UPPER(MONTHS), '10', total_qty, 0)) AS october,
  SUM(decode(UPPER(MONTHS), '11', total_qty, 0)) AS november,
  SUM(decode(UPPER(MONTHS), '12', total_qty, 0)) AS december,
  SUM(decode(UPPER(MONTHS), '01', total_qty, 0)) AS january,
  SUM(decode(UPPER(MONTHS), '02', total_qty, 0)) AS february,
  SUM(decode(UPPER(MONTHS), '03', total_qty, 0)) AS march,
  SUM(total_qty) total_qty
FROM
  ( SELECT trans_counselid,
      to_char(trans_date, 'MM') MONTHS,
      SUM(trans_amount) total_qty
    FROM legal_trans
    GROUP BY trans_counselid,
             to_char(trans_date, 'MM') )
GROUP BY trans_counselid
ORDER BY trans_counselid
TRANS_COUNSELID        APRIL                  MAY                    JUNE                   JULY                   AUGUST                 SEPT                   OCTOBER                NOVEMBER               DECEMBER               JANUARY                FEBRUARY               MARCH                  TOTAL_QTY             
1                      0                      0                      0                      0                      0                      0                      0                      0                      0                      10                     20                     0                      30                    
2                      0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      20                     0                      20                    
3                      0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      30                     30                    
4                      40                     0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      40                    
5                      0                      50                     0                      0                      0                      0                      0                      0                      0                      0                      0                      0                      50                    
6                      0                      0                      60                     0                      0                      0                      0                      0                      0                      0                      0                      0                      60                    
7                      0                      0                      0                      70                     0                      0                      0                      0                      0                      0                      0                      0                      70                    
8                      0                      0                      0                      0                      80                     0                      0                      0                      0                      0                      0                      0                      80                    
9                      0                      0                      0                      0                      0                      90                     90                     0                      0                      0                      0                      0                      180                   
9 rows selected

Similar Messages

  • Report for monthly sales(sales office wise,sales group wise,plant wise)

    Please send the Report for monthly sales(sales office wise,sales group wise,plant wise)  with T.CODE.,

    Hi
    As per my knowledge there is no Standard Report in SAP based on sales office, sales group. and plant.
    You may create your own report using MC18,MC21 and MC24.... Otherwise ask your ABAPer's help...
    Muthu

  • Time Series Line Chart - Monthly Sales - Make $0 or "No Sales" show up - not skipped

    Post Author: kevinday17
    CA Forum: Charts and Graphs
    I have been messing with my chart for a while and I guess I'll just ask for help since I can't figure it out.  All I am trying to do is chart out monthly sales dollars by customer.  Simple enough...I have it working except I want to be able to see a $0 plotted on my graph when there were no sales in a month.  Currently it just skips over that month and goes to the next where there is data (month after i.e next group summary field)).  I've tried all sorts of ways of grouping.  If I use the "group by date, monthly," on the "Order Date" field, I can't chose it as the "On Change of" under Advanced chart (single arrow is greyed out).   So I ended up making a huge formula to make my own groups of months.  My GH2 is the customer (and my chart), GH3 is my Grouping for month and year, and the detail is every single sales order.  My graph points are based on summary data; sum of all the sales orders for that customer for that month. 
    How do I tell Crystal Reports that if there were no sales in December, then tell me 0.  Don't just ignore it.
    Maybe there is an option to make the X Axis Fixed with points (month-year, in order).  It would be nice to have it uniform for every customer.  I would love to see every graph that prints out have 36 x-axis coordinates; one for every month of the last 36 months (jan-05, feb-05, mar-05......dec-07) regardless of whether or not the customer had sales or not.
    Thanks so much in advance. 
    Kevin

    Post Author: V361
    CA Forum: Charts and Graphs
    I have CR XI, I created a formula and used it to create the chart section
    if (isnull ()) then 0 else
    So if your AMNT is a null value it should put 0, else the AMNT

  • Help With Monthly Sales Query

    Hello All -
    We use the below Query to find monthly sales for each of our stock units.  However, it only provides the current year -- so for 2010, all our 2009 data is gone and the query just shows Jan 2010.
    Is there any way to adjust this Query so that we can select the year we want to see?
    Thanks!
    Mike
    SELECT T0.ITEMCODE,
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'DEC Amt'
    FROM dbo.OITM T0
    LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode
    WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = YEAR(GETDATE())
    ORDER BY T0. ITEMCODE

    /*Hello there!!
    you should try this code*/
    SELECT T0.ITEMCODE, (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'DEC Amt'
    FROM dbo.OITM T0 LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1) ORDER BY T0. ITEMCODE
    thou i suggest that its more practical for you to use a variable to enter the year, for example like this.
    declare @year as char(4)
    set @year = '2009'
    SELECT T0.ITEMCODE, (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'DEC Amt'
    FROM dbo.OITM T0 LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = @year ORDER BY T0. ITEMCODE

  • Monthly Sales report of a given Year

    Hi Experts,
    I have a requirement that User enters Fiscal year in Selection Prompt, based on the year, user wants monthly sales  like
    Jan-2010 | Feb-2010 | March 2010 | ..........| Dec-2010
    How can i get this?
    My report layout is like
    Vendor nbr     Vendor name  201001  201002   201003  201004     201005     201006     201007     201008     201009
         201010     201011     201012     Grand Total of sales revenue                                                                                                                             
    Thanks
    David

    Hi David,
    Can you add a column for Year?
    If Yes, then you Section the Year column in the report. This will make the months appear below this specific year.
    Then put the prompt for the Year. So when the user selects the year (eg: 2010), he will get all the months under the year 2010.
    Thanks
    Niranjan

  • Monthly Sales Report

    Hi All!
    Is there any kind of report in SAP B1 that shows comparison of monthly sales year over year by state.  So, for example, CA sales Jan-Dec 07 vs. Jan-Dec 08? 
    Thanks,
    Mike

    Hi Mike,
    Only 3 types of reports built-in for sales analysis.  Namely: By Customers, By Items or By Sales Employee.
    You need either a XL Report or a query to define this report.
    Thanks,
    Gordon

  • Monthly Sales By Geography

    Hello All -
    We would like to have a query that shows us monthly sales by geography (US State).
    However, using the Bill To Address or the Ship To Address is a problem for us -- I won't get into the details but it doesn't serve our purposes very well.
    Instead, we would like the location to be referenced from our account number.  The first two characters of a BP's account number represents their state. 
    So, first step would be to consolidate sales for all BP's that share the same first two letters in their account number.  This should, in theory, give us total sales for a particular state.  Then, we would want to see a listing of that state's sales by month.  So, result would be something like this:
               Jan      Feb     Mar     etc.
    AK
    AL
    CA 
    Can anyone help with this? 
    Thanks!
    Mike

    I just randomly selected a year.  You may change it to any year you want.
    Freight is included.  However, for adding Credit Memos I have to try more.
    Try this:
    SELECT P.[SalesSTATE],
    [1] as [Jan],
    [2] as [Feb],
    [3] as [Mar],
    [4] as [Apr],
    [5] as [May],
    [6] as [Jun],
    [7] as [Jul],
    [8] as [Aug],
    [9] as [Sep],
    [10] as [Oct],
    [11] as [Nov],
    [12] as [Dec]
    FROM (SELECT Left(T0.CardCode,2) as [SalesState] ,
    Case WHEN ISNULL(T1.DocTotal,0) !=0
    THEN T1.DocTotal ELSE -T2.DocTotal END as [DocTotal],
    CASE WHEN ISNULL(T1.DocTotal,0) !=0 THEN MONTH(T1.docdate)
    ELSE MONTH(T2.docdate) END as [month]
    FROM dbo.ocrd T0
    LEFT JOIN dbo.oinv T1 ON T1.CardCode = T0.CardCode AND Year(T1.docdate)=2010
    LEFT JOIN dbo.ORIN T2 ON  T2.CardCode = T0.CardCode AND Year(T2.docdate)=2010
    WHERE (T0.CardCode in (SELECT CardCode FROM OINV)) OR
    (T0.CardCode in (SELECT CardCode FROM ORIN)))  S
      PIVOT  (SUM(DocTotal) FOR [month] IN
    ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    ORDER BY P.[SalesState]

  • Monthly Sales By Sales Employee

    Hello All!
    Is there any report that shows Monthly sales by Sales Rep.  So basically, consolidating all invoices for a rep by month. The headers would look like this:
    Sales Rep...Jan...Feb...March...April...etc. Total
    Thanks!
    Mike

    Hello Mike,
    Please check the Sales Module > Sales reports > Sales Analysis > by Sales Employee tab.
    You can select the Annual, Monthly, Qterly Report from the various options in the Selection creteria window.
    Hope it solves the issue you are looking for.
    Regards,
    Jitin Chawla

  • Monthly Sales Order query Doc Status problem

    Hi Experts,
    I am having an problem while making a total monthly sales order query in which I am not getting the document status which are Open - Printed. Also note that these document which are open printed are not having any target document.
    SELECT T0.[DocStatus],T1.[TargetType],T0.[CANCELED],T0.[CardCode], T0.[CardName], T0.[NumAtCard], T5.[SeriesName], T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[DocTotal],T0.[Max1099]'Total Before Discount',T0.[TotalExpns],T4.[descript]'Territory',T2.[SlpName]'Employee Name'
    ,T0.[discsum]  FROM ORDR T0  ,RDR1 T1,OSLP T2,OCRD T3,OTER T4,NNM1 T5  where  T0.DocEntry = T1.DocEntry AND T0.SlpCode = T2.SlpCode AND T0.CardCode = T3.CardCode
    AND T3.Territory = T4.territryID AND T0.Series = T5.Series and T0.[CANCELED]='N' and T1.[TargetType] is not null
    My mission for the above query is to have Total Monthly Sales Orders with value exluding the cancelled and closed sales sales ( close here means - which are manually done by right click on sales order screen and selecting Close )
    Please guied how to solve this issue because in the back end for Sales Order which have turned to deleivery are showing doc status as closed and the sales order which are manually closed are also showing doc status as closed. How to diffrentiate between them.
    Waiting for a positve feedback.
    Regards,
    Rahul

    Try this one:
    SELECT DISTINCT T0.[DocStatus],T0.[CardCode], T0.[CardName], T0.[NumAtCard], T5.[SeriesName],
    T0.[DocNum], T0.[DocDate], T0.[DocDueDate], T0.[DocTotal],T0.[Max1099]'Total Before Discount',
    T0.[TotalExpns],T4.[descript]'Territory',T2.[SlpName]'Employee Name',T0.[discsum]
    FROM DBO.ORDR T0
    INNER JOIN DBO.RDR1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN DBO.OSLP T2 ON T0.SlpCode = T2.SlpCode
    INNER JOIN DBO.OCRD T3 ON T0.CardCode = T3.CardCode
    INNER JOIN DBO.OTER T4 ON T3.Territory = T4.territryID
    INNER JOIN DBO.NNM1 T5 ON T0.Series = T5.Series
    where  T0.[CANCELED]='N' and T1.[TargetType] != -1
    Thanks,
    Gordon

  • Monthly Sale By Item

    Hello,
    We are looking for a Query that will show all of our items and monthly sale by Qty and Amt.  This includes items that do not have sales for that month - those fields would just be left blank.
    So, header would be...
    Item #...Jan Qty...Feb Qty...Mar Qty...etc...Jan Amt...Feb Amt...etc...
    Does anyone know a Query that can do this?
    Sales analysis will just show only items that have sold. 
    This is similar to Queries we have asked for in the past that shows all items. 
    Thanks!
    Mike

    creo que nececitan algo como esto:
    DECLARE @FECHAINI DATE = '2015-01-01';
    DECLARE @FECHAFIN DATE = '2015-02-28';
    DECLARE @sql nvarchar(MAX) = '';
    DECLARE @columns_1 nvarchar(MAX) = '';
    DECLARE @columns_2 nvarchar(MAX) = '';
    SET @columns_1 = STUFF(
    SELECT DISTINCT
        ',Piezas_Mes' + cast( MONTH(DocDate) as varchar) + '_año_' + cast( YEAR(DocDate) as varchar)
    FROM
        (SELECT DocDate FROM OINV where DocDate BETWEEN @FECHAINI AND @FECHAFIN) AS P
    FOR XML PATH('')
    ), 1, 1, '');
    SET @columns_2 = STUFF(
    SELECT DISTINCT
        ',Monto_Mes' + cast( MONTH(DocDate) as varchar)  + '_año_' + cast( YEAR(DocDate) as varchar)
    FROM
        (SELECT DocDate FROM OINV where DocDate BETWEEN @FECHAINI AND @FECHAFIN) AS P
    FOR XML PATH('')
    ), 1, 1, '');
    SET @sql = N'
    select
        Z.PRODUCTO,
        Z.DESCRIPCION,
        ' + @columns_1 + ',' + @columns_2 + N'
    from
            select
            FROM
                    SELECT
                        a.ItemCode AS PRODUCTO,
                        a.Dscription AS DESCRIPCION,
                        ''Piezas_Mes'' + cast( MONTH(b.DocDate) as varchar) + ''_año_'' + cast( YEAR(b.DocDate) as varchar) AS MES,
                        a.Quantity AS CANTIDAD
                    FROM INV1 AS a
                        INNER JOIN OINV AS b
                        ON a.DocEntry=b.DocEntry
                        INNER JOIN OCRD AS c ON b.CardCode = c.CardCode
                    WHERE b.DocType = ''I'' AND b.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
                UNION ALL
                    SELECT
                        d.ItemCode AS PRODUCTO,
                        d.Dscription AS DESCRIPCION,
                        ''Piezas_Mes'' + cast( MONTH(e.DocDate) as varchar) + ''_año_'' + cast( YEAR(e.DocDate) as varchar) AS MES,
                        (d.Quantity * -1) AS CANTIDAD
                    FROM RIN1 AS d
                        INNER JOIN ORIN AS e
                        ON d.DocEntry = e.DocEntry
                        INNER JOIN OCRD AS f ON e.CardCode = f.CardCode
                    WHERE e.DocType = ''I'' AND e.DocDate BETWEEN ''' + CAST (@FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
            ) as TABLADATOS
            pivot
            SUM(TABLADATOS.CANTIDAD) for TABLADATOS.MES IN(' + @columns_1 + N')
            ) as P
    ) as Z
    inner join
            select
            from
                    SELECT
                         a.ItemCode AS PRODUCTO,
                         a.Dscription AS DESCRIPCION,
                         ''Monto_Mes'' + cast( MONTH(b.DocDate) as varchar) + ''_año_'' + cast( YEAR(b.DocDate) as varchar) AS MES,
                         a.LineTotal AS TOTAL
                    FROM INV1 AS a
                        INNER JOIN OINV AS b
                        ON a.DocEntry=b.DocEntry
                        INNER JOIN OCRD AS c ON b.CardCode = c.CardCode
                    WHERE b.DocType = ''I'' AND b.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
                UNION ALL
                    SELECT
                         d.ItemCode AS PRODUCTO,
                         d.Dscription AS DESCRIPCION,
                         ''Monto_Mes'' + cast( MONTH(e.DocDate) as varchar) + ''_año_'' + cast( YEAR(e.DocDate) as varchar) AS MES,
                         (d.LineTotal * -1) AS TOTAL
                    FROM RIN1 AS d
                        INNER JOIN ORIN AS e
                        ON d.DocEntry = e.DocEntry
                        INNER JOIN OCRD AS f ON e.CardCode = f.CardCode
                    WHERE e.DocType = ''I'' AND e.DocDate BETWEEN ''' + CAST( @FECHAINI AS VARCHAR) + ''' AND ''' + CAST( @FECHAFIN AS VARCHAR) + '''
            ) as TABLADATOS
                pivot
            SUM(TABLADATOS.TOTAL) for TABLADATOS.MES IN (' + @columns_2 + N')
            ) as P
    ) as Y
    on Z.PRODUCTO = Y.PRODUCTO and Z.DESCRIPCION = Y.DESCRIPCION
    order by
    PRODUCTO,
    DESCRIPCION;';
    EXEC sp_executesql @sql;
    SALUDOS ...

  • Calculate gross profit, yearly sales,monthly sales,weekly sales?

    hi all
    i try to create procedures according to these conditions 
    What are my yearly sales?
    What are my monthly sales?
    What are my weekly sales?
    What are my daily sales?
    What is my Gross Profit?
    What is my Gross Sales?
    this is star schema
    now how i calculate yearly sales, monthly sales, and also gross profit.
    create procedure spgrossprofit
    as
    select as grossprofit from dimfact
    now which aggregate function i use for calculate above conditions?
    any help?

    Sorry(ETC) is a Spanish expression = the same for the next option
    The correct query:
    Year/Month
    create procedure spyearlysales
    as
    select sum(totalsales),Year(Dimtime.date) from Dimtime
    inner join Dimfact on Dimtime.Time_Key=dimfact.Time_Key
    group by Year(Dimtime.date)create procedure spmonthsales
    as
    select sum(totalsales),year(Dimtime.date),Dimtime.Month from Dimtime
    inner join Dimfact on Dimtime.Time_Key=dimfact.Time_Key
    group by Year(Dimtime.date),Dimtime.Month
    JM Claudio Dba/Consultor SQL/BI Pasiona - Spain

  • CURRENT YEAR PREVIOUS TWO MONTHS SALES+MDX

    QUERY TO GET CURRENT YEAR LAST TWO MONTH SALES DYNAMICALLY IN MDX

    assuming you are looking for data with the latest two months and taking adventure works DW 2008  as sample DB
    try this
    select [Measures].[Internet Sales Amount]
    on 0,
     {Tail(nonempty(descendants([Date].[Calendar].[Calendar
    Year],[Date].[Month of Year]))).item(0),
     Tail(nonempty(descendants([Date].[Calendar].[Calendar
    Year],[Date].[Month of Year]))).item(0).prevmember} 
    on 1
     from [Adventure Works]

  • Previous month sales against each date

    Hi all,
    I am working on Bo XI 3.0.
    I have a requirement where i need to display in table  -"Date" then "sales" and against that in the same table "previous month's sales"
    For e.x
    date              sales            previous month's sales
    01/04/08        45637            63536
    02/04/08          73565           78556
    and so on..
    Any one having any clue please reply .
    Thanks in advance,
    Gaurav
    Edited by: Gaurav Gayawar on May 22, 2009 7:23 PM
    Edited by: Gaurav Gayawar on May 22, 2009 7:43 PM

    Hi,
    Can you go through the forum which has been answered:
    How to calculate "Last Month Sales revnue"
    Let me know if this works.
    -Madhu.

  • Calculate Last 12 months Sales

    Hi Experts,
    I need to have MAT value in Reporting.
    MAT Value = Last 12 Months Sales Value/12.
    How can i achieve this.
    Please suggest the best way to have MAT value.
    Thanks in advance,
    Rafi

    Hi,
    Create one restricted key fig by offsetting month for last 12 months and drag sales value key fig into that.
    Now create a formula variable by dividing the newly created restricted key fig with 12.
    hope it helps...
    regards,
    Raju

  • Monthly sales ordr in alv

    hi,       i am facing a problem in creation of sales order for a particular sales organization where in i need the sales orders raised by customers of the sales organization in a report which shows the sales order number,material data in it,quantity,cost,but my requirement to display the sales month wise for all customers .for example what r the sales orders raised in january by all customers of  sales org should come under jan month,like what r the orders raised by customers in febraury in january month like this i need for a particular financial year ,my problem is i am unable to split the sales based on months,i am able to get all months sales order with out classification under one set.....if

    HI RAJ,
    this is sample code it may help u,
    u do like this pass ktab to alv u got list by monthly.
    but first field 'erdat' b/c we use this field i at end of.
    types : begin of ty_vbak ,
           erdat type erdat,
          vbeln type vbeln_va,
          end of ty_vbak.
    data : itab    type table of ty_vbak,
           ktab    type table of ty_vbak,
           wa_itab type ty_vbak,
           ty_wa_itaB TYPE TY_VBAK,
           TEMP(2) TYPE C.
    select vbeln erdat from vbak into CORRESPONDING FIELDS OF table itab
    where vbeln > 100.
    sort itab by erdat.
    LOOP AT ITAB INTO WA_ITAB.
    APPEND WA_ITAB TO KTAB.
    AT END OF ERDAT+4(2).
    CLEAR WA_ITAB.
    APPEND WA_ITAB TO KTAB.
    ENDAT.
    ENDLOOP.
    regards,
    chandu.

Maybe you are looking for