AnyChart Category Sum

Hi everybody,
I've been searching around for quite some time, but didn't find a simple solution to my problem.
I've a stacked bar chart with multiple categories. There I need to place the sum of all categories above the bar.
An example can be found here: http://anychart.com/products/anychart/gallery/samples/Multi-Series-2D-Column-Stacked-Chart.html
As in the example stated out, I need to attach the following within the last series.
<extra_labels>
     <label enabled="true">
          <format><![CDATA[{%CategoryYSum}{numDecimals:0}]]></format>
          <font size="10" color="Black" />
     </label>
</extra_labels>The Custom XML option to generate the XML is not an option, because I'm retrieving the SQL dynamically by "Function Returning SQL Query".
Is there any way to approach this?
Thanks & Regards
Michael
P.S.: APEX 4.0.2.00.06, AnyChart 5.1.3

I assume that you have not found a solution yet. I have the same problem and the only solution is to overwrite the data in # DATA #. My workaround is to add the axis labels sums so in your example P1 -> P1 (198).
Any other solution ?
Cheers.
UPDATE: Realized that {%CategoryYSum} is created for data so my workaround is bad...
UPDATE2: What about creating xml data on your own look at this http://apex.oracle.com/pls/apex/f?p=36648:60:2007207572745902:::::&tz=1:00 this is gant of course but you can successfully replace #DATA# with xmltype substitution ?
Edited by: jareeq on 2011-12-06 03:49
Edited by: jareeq on 2011-12-06 04:41

Similar Messages

  • Displaying different sums in the same row based on date ranges

    Say I had a table like this
    DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME )
    Now I want to get a result that is grouped first by BusinessType, then SalesPerson and include derived columns that are sums based  on different date ranges.
    Month-to-date = from the start of the current month to today
    Month-to-date previous year = from the start of the current month to today 1 year ago
    DECLARE @today DATETIME
    DECLARE @today_prev_year DATETIME
    DECLARE @year_start DATETIME
    DECLARE @year_prev_start DATETIME
    DECLARE @month_start DATETIME
    DECLARE @month_prev_start DATETIME
    SET @today = GETDATE();
    SET @today_prev_year = DATEADD(YEAR,-1,@today)
    SET @year_start = CAST('01/01/' + CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(10)) AS DATETIME);
    SET @year_prev_start = DATEADD(YEAR,-1,@year_start)
    SET @month_start = DATEADD(month, DATEDIFF(month, 0, @today), 0); --gets the first of the current month
    SET @month_prev_start = DATEADD(YEAR,-1,@month_start); --gets the first of the current month
    SELECT t.BusinessType,t.SalesPerson,t.Category
    SUM(CASE WHEN o.OrderDate > @month_start AND ac.DocumentDate < @today THEN o.OrderAmount ELSE 0 END) AS MTDActualAmount
    SUM(CASE WHEN o.OrderDate > @month_prev_start AND ac.DocumentDate < @today_prev_year THEN o.OrderAmount ELSE 0 END) AS MTDPrevActualAmount
    FROM @t1 t
    Hope this is clear as to what Im trying to do.  Im ultimately going to pull this into an SSRS report, so im wondering if I can do this different SUM values in the report and handle the grouping there.
    Thoughts?

    Based on your example (with a group by added) it should work.
    However, if you incorperated a calendar table (http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx)
    you could lose all those manually set parameters:
    DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME, DocumentDate DATETIME)
    INSERT INTO @t1 (BusinessType, SalesPerson, Category, OrderAmount, OrderDate, DocumentDate) VALUES
    ('A','Joe','CatA',10,'2015-01-01','2015-01-01'),('A','Joe','CatB',10,'2015-01-02','2015-01-01'),('A','Joe','CatA',30,'2015-01-03','2015-01-04'),('A','Joe','CatB',40,'2015-01-04','2015-01-01'),('A','Joe','CatA',100,'2015-02-01','2015-02-01'),
    ('A','Joe','CatB',100,'2015-02-02','2015-02-01'),('A','Joe','CatA',300,'2015-02-03','2015-02-04'),('A','Joe','CatB',400,'2015-02-04','2015-02-01'),('A','Bob','CatA',1,'2015-01-01','2015-01-01'),('A','Bob','CatB',1,'2015-01-02','2015-01-01'),
    ('A','Bob','CatA',3,'2015-01-03','2015-01-04'),('A','Bob','CatB',4,'2015-01-04','2015-01-01'),('A','Bob','CatA',10,'2015-02-01','2015-02-01'),('A','Bob','CatB',10,'2015-02-02','2015-02-01'),('A','Bob','CatA',30,'2015-02-03','2015-02-04'),
    ('A','Bob','CatB',40,'2015-02-04','2015-02-01'),('B','Joe','CatA',10,'2015-01-01','2015-01-01'),('B','Joe','CatB',10,'2015-01-02','2015-01-01'),('B','Joe','CatB',40,'2015-01-04','2015-01-01'),
    ('B','Joe','CatA',100,'2015-02-01','2015-02-01'),('B','Joe','CatB',100,'2015-02-02','2015-02-01'),('B','Joe','CatA',300,'2015-02-03','2015-02-04')
    SELECT t.BusinessType,t.SalesPerson,t.Category,
    SUM(CASE WHEN OrderDate >= monthStart AND DocumentDate < today THEN OrderAmount ELSE 0 END) AS MTDActualAmount,
    SUM(CASE WHEN OrderDate BETWEEN prevMonthStart AND prevMonthENd AND DocumentDate >= yearStart THEN OrderAmount ELSE 0 END) AS MTDPrevActualAmount
    FROM @t1 t
    INNER JOIN calendar c
    ON today = CAST(CURRENT_TIMESTAMP AS DATE)
    Group by t.BusinessType,t.SalesPerson,t.Category

  • How can i copy and referencing the value of a sub-total of a category into another cell?

    How can i copy and referencing the value of a sub-total of a category into another cell?

    Cells in Category  rows 'exist' only when those categories are inserted using the Reorganize table. Those cells cannot be referenced from other cells.
    If you want a category summed, you will need to do that in a cell that is still visible when the table is not sorted into categorie using the Reorganize pane. The function to use is SUMIF. You can find information regarding SUMIF (and SUMIFS) in the iWork Formulas and Functions User Gude. The guide may be downloaded using the link in the Help menu in Numbers '09.
    Regards,
    Barry

  • SUM Parenthesis - Difference???

    Hi;
    i just want to ask if there is any differences between calculating summuation inside the pharenthesis or not???
    Example Query;
    select     a12.CATEGORY,
         (sum(a11.COL1) / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END)) SUM1,
         sum((a11.COL1 / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END))) SUM2
    from     table1     a11,
         table2a12
    where     a11.ID = a12.ID
    group by     a12.CATEGORY
    Which one is faster? SUM1 or SUM2 or no difference???
    Note that DB is Oracle 10g.
    Thanks...

    It makes no difference because the query won't work anyway. COL1 is aggregated but COL2 isn't...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 4 as col1, 2 as col2 from dual union all
      2             select 5, 3 from dual union all
      3             select 6, 0 from dual union all
      4             select 7, 3 from dual)
      5  --
      6  select sum(col1) / (case when col2=0 then null else col2 end) as sum1
      7        ,sum(col1 / case when col2=0 then null else col2 end) as sum2
      8* from t
    SQL> /
    select sum(col1) / (case when col2=0 then null else col2 end) as sum1
    ERROR at line 6:
    ORA-00937: not a single-group group function

  • Need template with daily entries, & monthly sums & year-to-date sums

    I'm trying to find a budget template for Numbers -- adapted from the checkbook template, maybe? --
    where one can enter daily transactions (with category) in 12 different monthly tables, show each month's category sums in tables next to the daily ones,
    and also have a table for Year-to-Date category sums, probably at the top of the whole thing.
    In other words, each individual transaction would have to be added to its monthly category table, AND to the Year-to-Date category table.
    Has anyone done this?  Can it be done in Numbers?
    Thanks.

    Hi Jackie,
    That makes more sense than my original reading. The function you are looking for is "SUMIFS."
    Here's an example, with the transactions recorded in the "Data" table, and the January sums reported in the "Summary" table.
    "Data" contains no formulas.
    On "Summary":
    A1 contains the start date, Jan 1, 2012.
    The rest of column A contains the category names, which must exactly match the names used in the Data table.
    B2 contains the formula, which is filled down the rest of column B:
    Summary::B2: =SUMIFS(Data::$C,Data::$B,"="&A,Data::A,">="&$A$1,Data::$A,"<="&EOMONTH($A$1,0) )
    For an amount to be included in the SUM, three conditions must be met:
    -- The transaction category must match the category in that row of Summary.
    -- The transaction date must be on or after the date in A1 of Summary
    -- The transaction date must be on or before the last day of the month in A1 of Summary.
    Regards,
    Barry

  • Calculated measures

         Hi everyone
    Hoping that there is an easy workaround to the below
    I am calculating GM at a SKU level, however would like to be able to present the data at a product category and/or customer channel level
    However when I drag in my calculated field of GM per SKU it recalculates GM at a average product category level and uses that new calc to determine GM achieved, rather than summing the GM per product catergory.
    I basically want the GM to calculate at a SKU level but be able to present the data at an aggregate level,
    In excel the formulas would look like this:
    GM per SKU = ytd sales/ ytd sales quantity
    GM achieved for day per SKU = GM per SKU*qty delivered for the day
    GM achieved per category = sum(GM achieved for all SKUs in category)
    It looks like BO recalculates GM per SKU depending on what product field I drag in ie if my table to calculate GM had product catergory rather than SKU I am getting GM per category, which then impacts my final calculation
    I basically want the calcs to keep running at a SKU level but be able to present totals at an aggregate level, rather than aggregating data then calculating GM
    Hope this makes sense. Can attched screenshots if required.

    Hi,
    What you describe sounds very similar to the user guide's definition of the calculation contexts. Read the chapter "Understanding calculation contexts" and make sure that you get to know the input and output calculation contexts:
    http://help.sap.com/businessobject/product_guides/sbo41/en/sbo41sp3_ffc_user_guide_en.pdf#page=16

  • How to calculate totals based on year (date) and comparing othe columns in the same table please

    Hello Good Evening,
    Could you please help me here
    how to write condition for self table year records, such 2012 name and acctno match with 2013 name and acctno then total, provided below,
    create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
    --drop table #tab1
    insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
    insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
    insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
    insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
    insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
    insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
    insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
    insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
    insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
    insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
    insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
    insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
    insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
    create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1) )
    --drop table #tab2
    insert into #tab1 values (1000, 500, 'V')
    insert into #tab1 values (1001, 150, 'U')
    insert into #tab1 values (1002, 100, 'N')
    insert into #tab1 values (1003, 170, 'U')
    insert into #tab1 values (1010, 100, 'U')
    insert into #tab1 values (1011, 200, 'K')
    insert into #tab1 values (1012, 340, 'U')
    insert into #tab1 values (1013, 560, 'N')
    insert into #tab1 values (1014, 280, 'V')
    insert into #tab1 values (1015, 150, 'V')
    insert into #tab1 values (1016, 840, 'V')
    insert into #tab1 values (1017, 530, 'N')
    i would like to get 4 columns output
    how to get sumofshares (#tab1) and TotalOutStanding(#tab2) summ up with these values please.,
    MasterKey (#tab1) and IssueKey (#tab2) are like primary key and foreign key
    so the request is
    need to calculate, sumofshares (#tab1) and TotalOutStanding(#tab2) as below
    1)ShareBenefist = U and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
    then '2012 and 2013 accts UN Veriverted'
    2)ShareBenefist = V and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
    then '2012 and 2013 accts Veriverted'
    3)ShareBenefist = N and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
    then '2012 and 2013 accts NONVERT'
    4)year( request_dat) =2102 and Name and Acctno not match with 2013 account name and acctno (#tab1)
    then '2012 last year accounts'
    5)year( request_dat) = 2013 and Name and Acctno not match with 2013 account name and acctno (#tab1)
    then '2012 This year accounts'
    for ex 1) the below accounts in #tab1 has both 2012 and 2013 and acctno same in both years and name is same in both years so it is condired as
    insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
    for ex 2)
    insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
    for ex 4) 2012 records there is not match acctno and name in 2013 recods
    insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
    for ex 5) 2013 records there is no match of name and acct no with 2012 records
    insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
    insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
    insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
    insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
    Expected Results (just for format)
    AcctTypeDescription, SumofShares, OtotalutStand
    '2012 and 2013 accts UN Veriverted',2700,234
    '2012 and 2013 accts Veriverted' ,2890,234
    '2012 and 2013 accts NONVERT' ,4533,325
    '2012 last year accounts' ,2334,567
    '2012 This year accounts' ,2222,877
    Please
    Thank youy in advance
    asita

    As I understand it, your sample output was only to show the format, and did not pretend to be give the exact result given the sample data. This is pity, because means that I was not able to verify that my query below gives the desired result.
    The exact relation between #tab1 and #tab2 is not clear to me. I'm making the assumption that a row in #tab1 may have zero or one row in #tab2, but not many.
    My solution has two CTEs. The first simply joins the tables together and extracts the year. In the second CTE, I perform a self-join over the first CTE which I have divided in two by year. This is a full join, since an account may appear for only one of
    the year. Note that it is instrumental to extract the year data in inner queries first.
    The final query is just an aggregation over the categories.
    create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
    --drop table #tab1
    insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
    insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
    insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
    insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
    insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
    insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
    insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
    insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
    insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
    insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
    insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
    insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
    insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
    create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1)  )
    --drop table #tab2
    insert into #tab2 values (1000,  500,  'V')
    insert into #tab2 values (1001,  150,  'U')
    insert into #tab2 values (1002,  100,  'N')
    insert into #tab2 values (1003,  170,  'U')
    insert into #tab2 values (1010,  100,  'U')
    insert into #tab2 values (1011,  200,  'K')
    insert into #tab2 values (1012,  340,  'U')
    insert into #tab2 values (1013,  560,  'N')
    insert into #tab2 values (1014,  280,  'V')
    insert into #tab2 values (1015,  150,  'V')
    insert into #tab2 values (1016,  840,  'V')
    insert into #tab2 values (1017,  530,  'N')
    go
    WITH joined AS (
      SELECT a.MasterKey, a.AcctNo, a.name, a.SumaofShares,
             year(a.request_dat) AS year, b.totalOutstanding, b.sharedBenefits
      FROM   #tab1 a
      LEFT   JOIN #tab2 b ON a.MasterKey = b.IssueKey
    ), categories (category, sumofshares, totaloutstanding) AS (
       SELECT CASE WHEN A.MasterKey IS NOT NULL AND
                        B.MasterKey IS NOT NULL
                        THEN '2012 and 2013 accts ' +
                             CASE B.sharedBenefits
                                WHEN 'U' THEN 'UN Veriverted'
                                WHEN 'V' THEN 'Veriverted'
                                WHEN 'N' THEN 'NONVERTED'
                                ELSE ''
                             END
                   WHEN A.MasterKey IS NOT NULL THEN '2012 last year accounts'
                   WHEN B.MasterKey IS NOT NULL THEN '2013 this year accounts'
              END,
              coalesce(A.SumaofShares, 0) + coalesce(B.SumaofShares, 0),
              coalesce(A.totalOutstanding, 0) + coalesce(B.totalOutstanding, 0)
       FROM   (SELECT * FROM joined WHERE year = 2012) AS A
       FULL   JOIN (SELECT * FROM joined WHERE year = 2013) AS B
             ON A.AcctNo = B.AcctNo
            AND A.name   = B.name
    SELECT category, SUM(sumofshares) AS sumofshares,
           SUM(totaloutstanding) AS totaloutstanding
    FROM   categories
    GROUP  BY category
    go
    drop table #tab1, #tab2
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Pivot not working; Analytics question

    I got a lot done this past weekend on tough query for me but now have more questions. You must run the top query to understand the understand the second.
    Background:
    This is a period to date report which includes amounts from beginning of the year as well as last year.
    My example Report is for Period 9 which begins on Aug 24, 2009
    Period has 5 weeks (Most periods have 4) ;
    Also if period is requested in Week 3 then only weeks 1 and 2 will be reflected on report
    The report looks like this: (Data provided should produce these numbers except for maybe the YTD column.
                 WEEK1       WEEK2           WEEK3         WEEK4             WEEK5       Period-to-date          Year-to-date
    Net - Landau     11,485.79   11,416.60      11,609.01     11,049.76      12,867.10      58,428.00             454,231.37      
    Net - AW     0.00               0.00          0.00        0.00                   0.00          0.00              0.00
    Net - LJS     0.00                   0.00           0.00         0.00           0.00          0.00            0.00
    Net - TB     7,118.17     7,228.13    7,657.94      7,699.53           7,958.53      37,662.00            306,115.59      
    Total Net     18,603.96    18,644.73      19,266.95     18,749.29         20,825.63      96,091.00            760,346.96      
    Last Year Sales     23,515.95    24,244.37       23,962.74    23,134.79      24,440.87      119,299.00           856,363.36      
    Increase     (4,911.99)  (5,599.64)      (4,695.79)  (4,385.50)           (3,615.24)     (23,208.00)           (96,016.40)     
    Last year
      Next Week     24,244.37    23,962.74       23,134.79    24,440.87      23,055.87      118,839.00           879,419.23      --===== Current Year Dates
    Beginning of period: (BOP) Mon Aug 24
    Week 1: Mon Aug 24 - Aug 30
    Week 2: Mon Aug 11 - Sept 6
    Week 3: Mon Sep 7 - Sept 13
    Week 4: Mon Sept 14 - Sept 20
    Week 5: Mon Sept 21 - Sept 27
    Beginning of fiscal year( BOY) = '28-Dec-08'
    --===== Last Year Dates
    Beginning of period: (BOP_LY) Mon Aug 25
    Week 1: Mon Aug 25 - Aug 31
    Week 2: Mon Aug 1 - Sept 7
    Week 3: Mon Sep 8 - Sept 14
    Week 4: Mon Sept 15 - Sept 21
    Week 5: Mon Sept 22 - Sept 28
    Beginning of fiscal year( BOY) = '31-Dec-07'
    My challenge over weekend was to get entire year of data vs. just the period data.
    There are 7 columns on this report. 5 weeks of period, PeriodToDate (total of the weeks) and YearToDate (PeriodToDate + Sum of all data from beginning of year to the end of the previous period.
    I'm not really concerned with the PTD, the program can handle that. I got the BOY date with the following code:
    All data is summed for the week and grouped by storeid and TRUNC(date, 'IW') which is the Monday of each week.
    of each week. (The resultset contains data for 2 stores instead of 1. This is there only to make sure my query was filtering correctly)
    drop table my_csh_main;
    CREATE TABLE MY_CSH_MAIN
       (     "FK_STR_MAIN_ID" NUMBER,
         "BUSI_DATE" DATE,
         "CONF_NUMB2" NUMBER,
         "CONF_NUMB49" NUMBER,
         "CONF_NUMB44" NUMBER,
         "CONF_NUMB3" NUMBER,
         "CONF_NUMB4" NUMBER,
         "CONF_NUMB38" NUMBER,
         "CONF_NUMB56" NUMBER
    REM INSERTING into MY_CSH_MAIN
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('28-AUG-08','DD-MON-RR'),22103.69,0,0,119,0,4605.21,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('27-AUG-09','DD-MON-RR'),18081.37,0,0,0,0,3533.45,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('17-SEP-09','DD-MON-RR'),18211.29,0,0,0,0,3806.32,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('04-SEP-08','DD-MON-RR'),24244.37,0,0,284.94,0,0,9395.63);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('03-SEP-09','DD-MON-RR'),18644.73,0,0,85.48,0,0,7228.13);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('24-SEP-09','DD-MON-RR'),16809.21,0,0,64.99,0,3014.61,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('25-SEP-08','DD-MON-RR'),24440.87,0,0,0,0,0,9469.64);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('28-AUG-08','DD-MON-RR'),23515.95,0,0,0,80.38,0,9379.9);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('24-SEP-09','DD-MON-RR'),20825.63,0,0,73.97,0,0,7958.53);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('17-SEP-09','DD-MON-RR'),18749.29,0,0,0,0,0,7699.53);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('11-SEP-08','DD-MON-RR'),22839.3,0,0,206.39,116.74,4493.28,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('04-SEP-08','DD-MON-RR'),22627.74,0,0,279.98,0,4423.83,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('27-AUG-09','DD-MON-RR'),18603.96,0,0,81.25,0,0,7118.17);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('11-SEP-08','DD-MON-RR'),23962.74,0,0,153.1,0,0,9335.35);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('18-SEP-08','DD-MON-RR'),23134.79,0,0,44.12,0,0,8978.87);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('25-SEP-08','DD-MON-RR'),24950.45,0,0,129.98,0,5330.22,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('10-SEP-09','DD-MON-RR'),19266.95,0,0,0,0,0,7657.94);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('03-SEP-09','DD-MON-RR'),17183.25,0,0,0,0,3487.12,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('18-SEP-08','DD-MON-RR'),21372.82,0,0,0,0,4546.15,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('10-SEP-09','DD-MON-RR'),17688.41,0,0,113.12,0,3424.17,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('31-DEC-08','DD-MON-RR'),611016.24,0,0,1276.62,724.96,122236.02,0);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('31-DEC-08','DD-MON-RR'),667612.63,0,0,1018.81,0,0,269777.87);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (141,to_date('02-JAN-08','DD-MON-RR'),1676737.13,0,0,5652.47,3850.68,345971.1,500.5);
    Insert into MY_CSH_MAIN (FK_STR_MAIN_ID,BUSI_DATE,CONF_NUMB2,CONF_NUMB49,CONF_NUMB44,CONF_NUMB3,CONF_NUMB4,CONF_NUMB38,CONF_NUMB56) values (221,to_date('02-JAN-08','DD-MON-RR'),1786451.11,0,0,3167.61,175.38,0,788438.73);
      CREATE TABLE  LANDAU_REPORT_STORES
       (     "COMPANYNAME" CHAR(40 BYTE),
         "DISTRICTNAME" VARCHAR2(50 BYTE),
         "STOREID" NUMBER(4,0) NOT NULL ENABLE,
         "STORENAME" VARCHAR2(70 BYTE),
         "STORENBR" CHAR(4 BYTE) NOT NULL ENABLE
    REM INSERTING into LANDAU_REPORT_STORES
    Insert into LANDAU_REPORT_STORES (COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',64,'N_Main','0004');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',65,'Belvidere','0005');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',104,'Mulford','0032');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 50',141,'Charleston','0043');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',61,'Kilburn','0002');
    Insert into LANDAU_REPORT_STORES(COMPANYNAME,DISTRICTNAME,STOREID,STORENAME,STORENBR) values ('Landau                                  ','DIST 10',62,'11th_St','0003');
       with WeeklyTotals as
       ( select                           StoreId
                                         , week_date
                                         , net_sales
                                         , ljs_food_sales
                                         , total_drink_sales
                                         , net_food
                                         , CASE
                                              WHEN net_food is null  then 0
                                              WHEN net_food  = 0  then 0
                                              ELSE Ljs_food_sales / net_food
                                           END as LJS_Percent
                                         , CASE
                                              WHEN net_food is null  then 0
                                              WHEN net_food = 0  then 0
                                              else total_drink_sales * (ljs_food_sales / net_food)
                                           END as LJS_Drinks
                                         , aw_sales
                                         , tb_sales
              FROM                            (Select fk_str_main_id as StoreId,
                                                                               trunc(csh.busi_date, 'IW') as week_date,
                                                                         sum(csh.conf_numb2) As net_sales,
                                                                         sum(conf_numb49) as ljs_food_sales,
                                                                         sum(conf_numb44)  As total_drink_sales,
                                                                         sum(csh.conf_numb2) - sum(CONF_NUMB44) - sum(conf_numb3) - sum(conf_numb4) AS net_food,
                                                                         sum(conf_numb38) As aw_sales,
                                                                         sum(conf_numb56)  as tb_sales
                                                     from my_csh_main csh
                                                     WHERE BUSI_DATE BETWEEN  TO_DATE( '28-Dec-08' ,'DD-MON-YY') AND  TO_DATE( '27-SEP-09' ,'DD-MON-YY')
                                                    and fk_str_main_id in (141, 221)
                                                    GROUP BY CSH.FK_STR_MAIN_ID,    trunc(csh.busi_date, 'IW')
       ,  WeeklyFoodSalesLY as
        SELECT    fk_str_main_id AS storeid
               ,  TRUNC(busi_date, 'iw') week_date
               ,  SUM(csh.conf_numb2) AS net_sales
        FROM   my_csh_main csh
        WHERE busi_date BETWEEN   to_date('31-DEc-07', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy')
        GROUP BY fk_str_main_id, TRUNC(busi_date, 'iw')
      , StoreDetails  AS
             select * from LANDAU_REPORT_STORES where STORENAME NOT like  '%CLOSED%'  order by DistrictNAme, StoreNbr
       Select 
                 foods.storeid
              ,   CASE
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy')  then 1
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 7 then 2
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 14 then 3
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09','dd-Mon-yy') + 21 then 4
                   WHEN   to_date(Foods.week_date, 'dd-Mon-yy')  =  to_date('24-AUG-09', 'dd-Mon-yy') + 28 then 5
                   ELSE  0
             end as WeekNBr
        ,   foods.week_date  as CurrWeekDate
        ,   foodsLY.week_date as LastYearWEekDate   
        ,   ROUND(NVL(foods.net_sales - (aw_sales + tb_sales + ljs_drinks + ljs_food_sales ), 0), 2) as Landau_Net_Sales
        ,   ROUND(NVL(aw_sales, 0), 2) as aw_sales
        ,   ROUND(NVL(tb_sales, 0), 2) as tb_sales
        ,   ROUND(NVL(ljs_drinks + ljs_food_sales, 0),2)    as ljs_net_sales
        ,   ROUND(NVL(foods.Net_Sales, 0), 2) as net_sales
        --==
        -- Last Year Sales and Last Year Next Year Sales
       --==
    ,    ROUND(NVL(foodsLY.Net_Sales, 0),2)    as    WTDLYNetSales
    ,    ROUND(NVL(Foods.Net_Sales -  FoodsLY.Net_Sales, 0),2)  as    WTDSalesIncrease
    -- ,    ROUND(NVL(FoodsLY_NextWeek.Net_Sales, 0), 2)          as    WTDFoodsSalesLY 
    ,   stores.*
    from WEeklyTotals Foods 
    LEFT OUTER JOIN Weeklyfoodsalesly foodsly ON foodsly.storeid = foods.storeid
                                              AND foodsly.week_date = DECODE(foods.week_date,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy') ,       to_date('25-AUG-08', 'dd-Mon-yy') ,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 7,   to_date('25-AUG-08', 'dd-Mon-yy') + 7,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 14,  to_date('25-AUG-08', 'dd-Mon-yy') + 14,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 21,  to_date('25-AUG-08', 'dd-Mon-yy') + 21,
                                                                             to_date('24-AUG-09', 'dd-Mon-yy')  + 28,  to_date('25-AUG-08', 'dd-Mon-yy') + 28)
    LEFT OUTER  JOIN  StoreDetails             stores  ON     stores.storeid   = Foods.storeid;one exception. In a With statement, I get a recordset containing all of last years data. I could not figure out the Pivot
    to get the Last Year Next Week . That means next week, one year ago. I pulled out a snippet to work with but couldn't get it
    to work:
    The problem came when I tried to pivot the Last year sales. I pulled this snippet out to test with but couldn't make it work.
    with   WeeklyFoodSalesLY  as
    (         SELECT  fk_str_main_id AS storeid
                 ,   TRUNC(busi_date, 'iw') week_date
                 ,   sum(conf_numb2)   conf_numb2
               FROM  my_csh_main csh    
               WHERE busi_date BETWEEN   to_date('31-dec-07', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy') + 7
               and fk_str_main_id = 141  
               GROUP BY  fk_str_main_id , TRUNC(busi_date, 'iw')      
    ,  sales_ly as
    (    SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date BETWEEN   to_date('25-Aug-08', 'dd-Mon-yy')  and  to_date('28-Sep-08', 'dd-Mon-yy') 
          GROUP BY  storeid , week_date    
          UNION ALL
          SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date BETWEEN   to_date('25-Aug-08', 'dd-Mon-yy') + 7   and  to_date('28-Sep-08', 'dd-Mon-yy') + 7
          GROUP BY  storeid , week_date
          UNION ALL
          SELECT      storeid
                    , week_date
                    , sum(conf_numb2) as net_sales
          from WeeklyFoodSalesLY
          WHERE week_date < to_date('25-Aug-08', 'dd-Mon-yy') 
          GROUP BY  storeid , week_date
    ,  pivoted_sales_ly as
    (    SELECT          storeid
                         week_date
                    ,    MAX(DECODE(week_date, to_date('25-Aug-08', 'dd-Mon-yy'),          net_sales))        as lastyear
                    ,    MAX(DECODE(week_date, to_date('25-Aug-08', 'dd-Mon-yy') + 7,      net_sales))        as lastyearnextweek
                    ,    MAX(DECODE(week_date, to_date('31-dec-07', 'dd-Mon-yy'),          net_sales))        as lastyeartotal
          from sales_ly
          GROUP BY  storeid, week_date
    Select *
    from pivoted_sales_ly;  What am i dont wrong here? Once I get this I can work back into the original query.
    Analytics:
    Boneist gave me some code to try last week:
    Combining refCursors  and Summing
    that created the PTD column.
    I could never get it to work because I was tweaking so much with the Query but is there a way to get the PTD without
    having to add an extra PTD column for each week.
    One other thing:
    I would like to know how to use analytics to roll up report by division into a different cursor.
    Edited by: TheHTMLDJ on Oct 26, 2009 4:50 AM
    Edited by: TheHTMLDJ on Oct 26, 2009 4:59 AM

    TheHTMLDJ wrote:
    The report looks like this: (Data provided should produce these numbers except for maybe the YTD column.With the data you provided, I managed to produce the expected output for storeid 221, barring the YTD column, which had the wrong values. I had to make up the "next week" row for the previous year for storeid 221, btw:
    WITH weekly_values AS (SELECT fk_str_main_id as storeid,
                                  TRUNC(csh.busi_date, 'IW') AS week_date,
                                  NVL(SUM(csh.conf_numb2), 0) AS net_sales,
                                  NVL(SUM(conf_numb49), 0) AS ljs_food_sales,
                                  NVL(SUM(conf_numb44), 0) AS total_drink_sales,
                                  NVL(SUM(csh.conf_numb2) - SUM(conf_numb44)
                                                          - SUM(conf_numb3)
                                                          - SUM(conf_numb4), 0) AS net_food,
                                  NVL(SUM(conf_numb38), 0) AS aw_sales,
                                  NVL(SUM(conf_numb56), 0) AS tb_sales
                           FROM   my_csh_main csh
                           WHERE  (busi_date BETWEEN TRUNC(:v_bop, 'iy') AND TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks - 1) + 6
                                   OR
                                   busi_date BETWEEN TRUNC(:v_bop_ly, 'iy') AND TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks  + 6)
                           AND    fk_str_main_id IN (141, 221)
                           GROUP BY csh.fk_str_main_id,
                                    TRUNC(csh.busi_date, 'IW')),
         weekly_totals AS (SELECT storeid,
                                  week_date,
                                  net_sales,
                                  ljs_food_sales,
                                  total_drink_sales,
                                  net_food,
                                  CASE WHEN nvl(net_food, 0) = 0 then 0
                                       ELSE ljs_food_sales / net_food
                                  END AS ljs_percent,
                                  CASE WHEN nvl(net_food, 0) = 0 then 0
                                       ELSE total_drink_sales * (ljs_food_sales / net_food)
                                  END AS ljs_drinks,
                                  aw_sales,
                                  tb_sales,
                                  net_sales - aw_sales
                                            - tb_sales
                                            - ljs_food_sales
                                            - CASE WHEN nvl(net_food, 0) = 0 then 0
                                                   ELSE total_drink_sales * (ljs_food_sales / net_food)
                                              END AS landau_net_sales
                           FROM   weekly_values),
         week_tots_ytd AS (SELECT storeid,
                                  week_date,
                                  net_sales,
                                  ljs_food_sales,
                                  total_drink_sales,
                                  net_food,
                                  ljs_drinks,
                                  aw_sales,
                                  tb_sales,
                                  landau_net_sales,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, landau_net_sales)) OVER (PARTITION BY storeid,
                                                                                                                                             trunc(week_date, 'iy')) lns_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, aw_sales)) OVER (PARTITION BY storeid,
                                                                                                                                     trunc(week_date, 'iy')) aws_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, ljs_food_sales)) OVER (PARTITION BY storeid,
                                                                                                                                           trunc(week_date, 'iy')) ljsf_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, tb_sales)) OVER (PARTITION BY storeid,
                                                                                                                                     trunc(week_date, 'iy')) tbs_ytd,
                                  SUM(decode(week_date, TRUNC(:v_bop_ly, 'iw') + 7*:v_num_weeks, NULL, net_sales)) OVER (PARTITION BY storeid,
                                                                                                                                      trunc(week_date, 'iy')) net_ytd,
                                  SUM(net_sales) OVER (PARTITION BY storeid,
                                                                    trunc(week_date, 'iy')) full_net_ytd,
                                  SUM(landau_net_sales) OVER (PARTITION BY storeid,
                                                                           CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                                WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                           END) lns_ptd,
                                  SUM(aw_sales) OVER (PARTITION BY storeid,
                                                                   CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                        WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                   END) aws_ptd,
                                  SUM(ljs_food_sales) OVER (PARTITION BY storeid,
                                                                         CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                              WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                         END) ljsf_ptd,
                                  SUM(tb_sales) OVER (PARTITION BY storeid,
                                                                   CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                        WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks -1) THEN 2
                                                                   END) tbs_ptd,
                                  SUM(net_sales) OVER (PARTITION BY storeid,
                                                                    CASE WHEN week_date between TRUNC(:v_bop, 'iw') and TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks -1) THEN 1
                                                                         WHEN week_date between TRUNC(:v_bop_ly, 'iw') and TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks-1) THEN 2
                                                                    END) net_ptd,
                                  LEAD(net_sales) OVER (PARTITION BY storeid,
                                                                     trunc(week_date, 'iy')
                                                        ORDER BY week_date) next_week_net_sales
                           FROM   weekly_totals),
                 foods AS (Select storeid,
                                  CASE WHEN week_date in (:v_bop, :v_bop_ly) then 1
                                       WHEN week_date in (:v_bop + 7, :v_bop_ly + 7) then 2
                                       WHEN week_date in (:v_bop + 14, :v_bop_ly + 14) then 3
                                       WHEN week_date in (:v_bop + 21, :v_bop_ly + 21) then 4
                                       WHEN week_date in (:v_bop + 28, :v_bop_ly + 28) then 5
                                  END AS week_number,
                                  week_date,
                                  ROUND(net_sales - (aw_sales + tb_sales + ljs_drinks + ljs_food_sales), 2) AS landau_net_sales,
                                  ROUND(aw_sales, 2) AS aw_sales,
                                  ROUND(tb_sales, 2) AS tb_sales,
                                  ROUND(ljs_drinks + ljs_food_sales, 2) AS ljs_net_sales,
                                  ROUND(net_sales, 2) AS net_sales,
                                  ROUND(lns_ytd, 2) AS lns_ytd,
                                  ROUND(aws_ytd, 2) AS aws_ytd,
                                  ROUND(ljsf_ytd, 2) AS ljsf_ytd,
                                  ROUND(tbs_ytd, 2) AS tbs_ytd,
                                  ROUND(net_ytd, 2) AS net_ytd,
                                  ROUND(full_net_ytd, 2) AS full_net_ytd,
                                  ROUND(lns_ptd, 2) AS lns_ptd,
                                  ROUND(aws_ptd, 2) AS aws_ptd,
                                  ROUND(ljsf_ptd, 2) AS ljsf_ptd,
                                  ROUND(tbs_ptd, 2) AS tbs_ptd,
                                  ROUND(net_ptd, 2) AS net_ptd,
                                  ROUND(next_week_net_sales, 2) AS next_week_net_sales,
                                  SUM(ROUND(next_week_net_sales, 2)) OVER (PARTITION BY storeid,
                                                                                       TRUNC(week_date, 'iy')) nwns_ptd
                           FROM   week_tots_ytd
                           WHERE  (week_date BETWEEN TRUNC(:v_bop, 'iw') AND TRUNC(:v_bop, 'iw') + 7*(:v_num_weeks - 1)
                                   OR
                                   week_date BETWEEN TRUNC(:v_bop_ly, 'iw') AND TRUNC(:v_bop_ly, 'iw') + 7*(:v_num_weeks - 1))),
         pivoted_foods AS (SELECT storeid,
                                  week_number,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), landau_net_sales)) landau_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aw_sales)) aw_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tb_sales)) tb_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljs_net_sales)) ljs_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_sales)) net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), lns_ytd)) lns_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aws_ytd)) aws_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljsf_ytd)) ljsf_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tbs_ytd)) tbs_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_ytd)) net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), full_net_ytd)) full_net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), lns_ptd)) lns_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), aws_ptd)) aws_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), ljsf_ptd)) ljsf_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), tbs_ptd)) tbs_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop, 'iy'), net_ptd)) net_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_sales)) ly_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_ytd)) ly_net_ytd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), net_ptd)) ly_net_ptd,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), next_week_net_sales)) ly_next_week_net_sales,
                                  MAX(DECODE(TRUNC(week_date, 'iy'), TRUNC(:v_bop_ly, 'iy'), nwns_ptd)) ly_nwns_ptd
                           FROM   foods
                           GROUP BY storeid,
                                    week_number),
          storedetails AS (SELECT companyname,
                                  districtname,
                                  storeid,
                                  storename,
                                  storenbr
                           FROM   landau_report_stores
                           WHERE  UPPER(storename) NOT LIKE  '%CLOSED%' 
                           ORDER BY districtname, storenbr),
                 dummy AS (SELECT level col1
                           FROM   dual
                           CONNECT BY level <= 8)
    SELECT pf.storeid,
           DECODE(dummy.col1, 1, 'Net - Landau',
                              2, 'Net - AW',
                              3, 'Net - LJS',
                              4, 'Net - TB',
                              5, 'Total Net',
                              6, 'Last Year Sales',
                              7, 'Increase',
                              8, 'Last Year Next Week') category,
           SUM(CASE WHEN pf.week_number = 1 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 1 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week1,
           SUM(CASE WHEN pf.week_number = 2 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 2 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week2,
           SUM(CASE WHEN pf.week_number = 3 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 3 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week3,
           SUM(CASE WHEN pf.week_number = 4 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 4 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week4,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.landau_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aw_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljs_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tb_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_sales - pf.ly_net_sales
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.ly_next_week_net_sales
           END) week5,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.lns_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aws_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljsf_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tbs_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_ptd - pf.ly_net_ptd
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.ly_nwns_ptd
           END) period_to_date,
           SUM(CASE WHEN pf.week_number = 5 AND dummy.col1 = 1 THEN pf.lns_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 2 THEN pf.aws_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 3 THEN pf.ljsf_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 4 THEN pf.tbs_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 5 THEN pf.net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 6 THEN pf.ly_net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 7 THEN pf.net_ytd - pf.ly_net_ytd
                    WHEN pf.week_number = 5 AND dummy.col1 = 8 THEN pf.full_net_ytd
           END) year_to_date,
           stores.companyname,
           stores.districtname,
           stores.storename,
           stores.storenbr 
    FROM   pivoted_foods pf
           LEFT OUTER JOIN storedetails stores ON stores.storeid = pf.storeid,
           dummy
    group by dummy.col1,
             DECODE(dummy.col1, 1, 'Net - Landau',
                              2, 'Net - AW',
                              3, 'Net - LJS',
                              4, 'Net - TB',
                              5, 'Total Net',
                              6, 'Last Year Sales',
                              7, 'Increase',
                              8, 'Last Year Next Week'),
             rollup((pf.storeid,
             stores.companyname,
             stores.districtname,
             stores.storename,
             stores.storenbr))
    order by pf.storeid, dummy.col1;(replace all :v_num_weeks, :v_bop and :v_bop_ly references with your variables)

  • Accessing the field values in different fields for calculation

    Hi,
    I am creating a report in which I have used breaks for grouping the  customers by their category. I have used summary on the amount field to calculate the sum in the individual category and also for total amount.
    Now, I also want to add an column which could display the percentages of individual contributions.
    So, its like I have to write a query accessing the total percentage, categorized percentage and individual amount.
    My question: How can I access the various fields values in the query of some other field specifically sum and total sum( because it shows the sum([Amount]) for category sum and total sum both)
    -BOBJuser

    Hmmm, I assume you are talking about WebIntelligence here...
    Ok, so let's go: you can access every "object" in the report simply by it's name. Every cell contains either a constant value (e.g. some text) or a formula, the simplest one can be just the value of an "object" from the query.
    There is a formula bar on top which you can activate, where you can easily see the content of a specific cell and also copy/paste the formula from the cell, as well as access all the built-in functions.
    WebI has a built-in calculator which works very similar to a "micro" olap engine, so you can access every sort of aggregate (of a measure) via a correspondig formula, irrelevant in which cell you are using it.
    Nevertheless, there is a "computation context" which depends on the place where you put the formula, e.g. summary row, detail row, etc.
    for more info: see the manual )
    hth, Walter

  • Materialized views Error

    Hi,
    I have installed oracle 11g expression edition. I am trying to create materialized view like this
    create materialized view test_mv
    build immediate
    refresh fast on commit
    enable query rewrite
    as
    select product.category, sum(sales.netsales) from product, sales where product.productid=sales.productid group by
    product.category order by product.category;
    I am getting the following error:
    SQL Error: ORA-00439: feature not enabled: Materialized view rewrite
    I have updated the init file in the following path:
    # Materialized views for query rewrite
    QUERY_REWRITE_ENABLED=TRUE
    Path: C:\oraclexe\app\oracle\product\11.2.0\server\config\scripts (where exactly it is installed.). Pls let me know what is the problem? I am unable to trace it.
    regards
    chandra kanth.

    The Oracle Error Message brings it to the point nicely :-)
    $ oerr ORA 00439
    00439, 00000, "feature not enabled: %s"
    // *Cause:  The specified feature is not enabled.
    // *Action: Do not attempt to use this feature.The feature is only available with Enterprise Edition - not with your free-of-charge XE.
    See here for the Feature Availability by Edition
    http://docs.oracle.com/cd/E11882_01/license.112/e10594/editions.htm#CJACGHEB
    Kind regards
    Uwe Hesse
    "Don't believe it, test it!"
    http://uhesse.com

  • Catagorizing Data in Numbers.

    I need to catagorize a year's worth of credit card data but cannot group data in Numbers 3.0.1 so switched to Numbers '09 but found there was catagorizing limited of 500 cells! Any work around or do I have to buy Excel? Other ideas? Being able obtain group totals is very useful. Why does Apple ignore this essential feature?
    Paul Fishman

    I may need to get a database. Used Provue Panorama in distant past and had no trouble digesting this kind of data.
    Hi Paul,
    If you want a no-formula approach, where you can quickly see totals together with the data underlying them, then Excel pivot tables or Panorama may be the easiest for you.
    However, Numbers 3.0 or 2.3 can easily handle the extraction of category sums for 1000 or so rows if you don't mind entering a few formulas and it's acceptable for your purposes to display the sums separately from the underlying data.
    To do that you would proceed as shown in my post upthread, for which Jerry describes a subset.  You can find a good example of this formula-based technique in the Personal Budget template (File > New) in Numbers 3.0, which takes entries in a transactions table and summarizes them by category (column C of the Summary by Category table), very similar to what you describe as what you are trying to do.
    SG

  • Various AppleScript Questions

    Hi all,
    I am a newbie to AppleScript, so please be patient.
    I am trying to write a script that automatically performs the following actions which I have to do regularly to a spreadsheet I get:
    Delete the first two rows
    alter the top row to be a title row
    do three certain "search and replace" actions (replace "I1" by "1", case sensitive, full words only)
    categorize and sort by two columns
    set one certain column to "number" format
    apply category sums to a certain column
    Optionally: move some columns to a different position
    I am now as far as this (by reading some posts in this forum):
    tell application "Numbers"
    activate
    set myDocName to name of document 1
    tell document 1
    tell sheet 1
    tell table 1
    remove row 1
    remove row 1
    -- How to change the top row to be a title row??
    end tell
    end tell
    end tell
    end tell
    I suspect that the next things I need have something to do with changing the properties of rows and columns, but I did not find an example of the necessary syntax. Can anybody provide a hint? A link to some documentation would be really nice!
    Thanks a lot
    Wolfii

    Wolfii wrote:
    Hi all,
    I am a newbie to AppleScript, so please be patient.
    I am trying to write a script that automatically performs the following actions which I have to do regularly to a spreadsheet I get:
    Delete the first two rows
    alter the top row to be a title row
    do three certain "search and replace" actions (replace "I1" by "1", case sensitive, full words only)
    categorize and sort by two columns
    set one certain column to "number" format
    apply category sums to a certain column
    Optionally: move some columns to a different position
    I am now as far as this (by reading some posts in this forum):
    I suspect that the next things I need have something to do with changing the properties of rows and columns, but I did not find an example of the necessary syntax.
    You suspect wrongly
    If you insert in your code the instruction
    get properties of row 1
    you will discover that there is no property linked to the row status.
    Can anybody provide a hint? A link to some documentation would be really nice!
    THE source of information is the application's AppleScript's dictionary which you may access thru
    Script Editor > File > Open a dictionary…
    What you asked can't be done with vanilla AppleScript.
    It would require the use of GUI Scripting.
    http://www.apple.com/applescript/uiscripting/
    Defining headers is simple:
    Setting cells format is simple too.
    The dictionary states:
    format (automatic/checkbox/currency/date and time/fraction/number/percent/pop up menu/scientific/slider/stepper/text) : The cell format of the range's cells.
    Your Search/Replace request may be done thru vanilla AppleScript but it would be long and awful.
    AppleScript is unable to get the formulas. It get only the values so, to fit your request you need to:
    +scan every cell+
    +get and save the cell's format+
    +set the cell's format to text+
    +get the cell's value.+
    +if it contains the word l1, replace it by 1+
    +if you replaced something, set the cell's value to the new string+
    +reset the cell's format to it's original one+
    +continue the scan.+
    I didn't tested but, according to the dictionary, sorting thru vanilla AppleScript can only be done with a single key column:
    sort v : Sort the rows of the table.
    sort table
    by column : The column to sort by.
    [direction ascending/descending]
    [in rows range] : Limit the sort to the specified rows.
    Other tasks would be more difficult because you must find a way to GUIscript dialogs available thru Inspectors
    As far as I know, some request can't be responded because there is no tool to do that (we can't drag column label as requested to move a column)
    Have fun.
    on run
    set nbRowsToRemove to 2
    set nbHeaderRow to 1
    my activateGUIscripting()
    tell application "Numbers"
    set theApp to name
    set myDocName to name of document 1
    tell document myDocName to tell sheet 1 to tell table 1
    repeat with i from 1 to nbRowsToRemove
    remove row 1
    end repeat
    my selectSubMenu(theApp, 6, 10, (1 + nbHeaderRow)) (* define header row(s) *)
    set rowMax to row count
    set column6 to (name of cell 1 of column 6) & ":" & (name of cell rowMax of column 6)
    set format of range column6 to percent
    end tell
    end tell
    end run
    --=====
    on activateGUIscripting()
    tell application "System Events"
    if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
    end tell
    end activateGUIscripting
    --=====
    on selectSubMenu(theApp, mt, mi, ms)
    (* Call a 2nd level menu (submenu) *)
    tell application theApp
    activate
    tell application "System Events" to tell process theApp to tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
    end tell -- application theApp
    end selectSubMenu
    --=====
    Yvan KOENIG (from FRANCE mardi 5 mai 2009 16:55:46)

  • Productwise Monthly Sales by a Customer

    Dear Experts,
    Can anybody help me how to get the monthly sales qty like April, May ....etc according to Customer wise for a perticular Item.
    Any help to modify the existing query
    SELECT T1.[ItemName] 'Item Name', T0.[CardName] 'Customer Name', T2.[City], T3.[GroupName] 'Category', SUM(T0.[OutQty]) as 'Sale Qty',  SUM(T0.[InQty]) as 'Return Qty', SUM(T0.[OutQty])-SUM(T0.[InQty]) as 'Total Sale.Qty' FROM OINM T0  INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN OCRG T3 ON T2.GroupCode = T3.GroupCode WHERE T0.[DocDate] >= [%0] and  T0.[DocDate] <= [%1] and T0.[ItemCode] = [%2] and T0.[TransType] in ('15', '16', '14') GROUP BY   T0.[CardName], T2.[City], T1.[ItemName], T3.[GroupName] order by T1.[ItemName], T3.[GroupName] desc
    Regrds,
    Srini

    Hi,
    you may test the Istvan query in your SQL server query --> demo datbase :
    SELECT T1.ItemName 'Item Name', T0.CardName 'Customer Name',
    T2.City, T3.GroupName 'Category', T0.DocDate,
    datepart(m,T0.DocDate) Month,
    SUM(T0.OutQty) as 'Sale Qty', SUM(T0.InQty) as 'Return Qty',
    SUM(T0.OutQty)-SUM(T0.InQty) as 'Total Sale.Qty'
    FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
    INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode
    INNER JOIN OCRG T3 ON T2.GroupCode = T3.GroupCode
    WHERE
    T0.DocDate >= '01/01/2009' and T0.DocDate <= '12/30/2009'
    and
    T0.ItemCode = 'A00001'
    and T0.TransType in ('15', '16', '14')
    GROUP BY T0.CardName, T2.City, T1.ItemName, T3.GroupName,datepart(m,T0.DocDate), T0.DocDate
    order by T1.ItemName, T3.GroupName desc
    JImM

  • Need to concat multiple elements into one element

    Hello, here is my challenge:
    Query:
    SELECT  XMLROOT (
            XMLELEMENT ("Inv",
                             XMLAGG (
                                        XMLELEMENT ("Invline",
                                                     XMLELEMENT ( "Category", i.category ),
                                                    XMLELEMENT ( "Amount", i.amount ),
                                         ), VERSION '1.0', STANDALONE YES).EXTRACT ('/*')
      FROM (
            SELECT 1 AS inv_no, 'Labor' AS category, 5 AS amount FROM DUAL
                UNION ALL
            SELECT 1, 'Out-of-Pocket', 10 FROM DUAL
                UNION ALL
            SELECT 1, 'Travel', 20 FROM DUAL
                UNION ALL
            SELECT 1, 'Travel', 2.5 FROM DUAL) i;
    Returns:
    <?xml version="1.0" standalone="yes"?>
    <Inv>
      <Invline>
        <Category>Labor</Category>
        <Amount>5</Amount>
      </Invline>
      <Invline>
        <Category>Out-of-Pocket</Category>
        <Amount>10</Amount>
      </Invline>
      <Invline>
        <Category>Travel</Category>
        <Amount>20</Amount>
      </Invline>
      <Invline>
        <Category>Travel</Category>
        <Amount>2.5</Amount>
      </Invline>
    </Inv>
    Required:
    <?xml version="1.0" standalone="yes"?>
    <Inv>
      <Inv_No>1
        <Details>Labor 5
      Out-of-Pocket 10
      Travel 22.5
      </Details>
      </Inv_no>
    </Inv>
    So I would like help combining the details into one field for transmission to the Mexican Tax Authorities( their spec calls for all  invoice lines to be concated together).
    Note that there are two travel details that need to be summed as well.
    I would prefer to cannot change the query if possible, just using the XML functions.
    Thanks!

    And your db version is?
    From 11.2 and onwards, you can use LISTAGG aggregate function to concatenate character data across rows :
    SELECT XMLElement("Inv"
           , XMLAgg(
               XMLElement("Inv_No"
               , v.inv_no
               , XMLElement("Details"
                 , listagg(v.category || ' ' || to_char(v.amount), chr(10))
                     within group (order by v.category)
    FROM(
        SELECT t.inv_no
             , t.category
             , sum(t.amount) as amount
        FROM (
          SELECT 1 AS inv_no, 'Labor' AS category, 5 AS amount FROM DUAL UNION ALL
          SELECT 1, 'Out-of-Pocket', 10 FROM DUAL           UNION ALL
          SELECT 1, 'Travel', 20 FROM DUAL            UNION ALL
          SELECT 1, 'Travel', 2.5 FROM DUAL
        ) t
        GROUP BY t.inv_no, t.category
    ) v
    GROUP BY v.inv_no ;

  • Count of Data of column

    Hi
    one questions
    from DB i did RSUM,% etc etc and got data in the below format
    Category | Customer| Sales
    1 | ABC| 93
    2 | DEF| 83
    3 | GHI | 73
    4 | JKL | 64
    4 | MNO| 63
    5 | QRS | 55
    5 | TUV | 54
    Now I need to show report in below format
    Category |No of Customers| Sales| Avg Sales
    1 | 1| 93| 93
    2 | 1| 83 | 83
    3 | 1| 73 | 73
    4 | 2| 127| 63.5
    5 | 2| 109| 54.5
    Can anybody help get this No of Customers and Sales total for a category pls
    Thanks in Advance
    Cheers
    Edited by: user511637 on Jul 22, 2009 10:11 AM
    Edited by: user511637 on Jul 22, 2009 10:15 AM

    Hi,
    Try this way
    category|count( customer by category)|sum(sales by category)|sum(sales by category)/count(customer by category)
    Hope it helps you

Maybe you are looking for

  • Variable list of parameters in PL/SQL functions

    As I know, PL/SQL decode function can be called with variable number of parameters: decode (a, b, c); decode (a, b, c, d, e); decode (a, b, c, d, e, f, g); How is is possible to implement a PL/SQL procedure or function like decode, which is usable wi

  • Movie Clips in sequence

    Hello everyone, Question, If you want to play serval movie clips in a row how do you set that up on the time line? Do you use one frame for each movie clip or do you need the same number of frams in the main timeline as there is in the movie clip. Wh

  • PLZ PLZ help me, how do i add keywords to my website, so google search finds them...

    Hi everyone my website is www.oakleytrainingcentre.com how do add keywords to it, so for example if you type training my website comes up on google search, a guy at my work said you can do it using html codes? plz anyone help thanks

  • VMware Fusion 3 or Parallels Desktop Question

    I have a quick question about VMware Fusion 3 or Parallels Desktop 5.0 for Mac. Will a windows vista reinstall dvd run on either of these programs? Thanks in advance.

  • SSM Usage stat Method

    Hi All, Does anybody have any idea about how to get usage stat in SSM. I have refered to the post Usage Report for SSM 7.0 and found that Bob had suggested about Wed analytics Tool. Can some one help how to use web analytics tool to get usage stat. I