Running Total (or) Moving Sum (or) Rollup using Date functions

I have to pass the Begin date and End date using prompt in my application (for daily basis for one month, monthly and yearly).
How can i use the date function for Rollup the days values(running total) for the below mentioned SQL
Table.Date field (@Prompt('Begin_Date','D',,mono,free) and @Prompt('End_Date','D',,mono,free)
@prompt automatically takes the begin date and end date.
I need the sql for rollup(running total) on daily basis for one month say jan 1 to jan 31.
Any idea?

Check the Oracle on-line documentation on the ROLLUP option of the GROUP BY clause. It should be able to give you running totals.

Similar Messages

  • How to  use data function using characterstics variable for calculation on

    how to  use data function using characterstics variable for calculation on  attribute as key figure

    Hi Gayatri
    Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
    In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
    This essentially means, IF A = B THEN C ELSE D
    The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
    IF PART_NUMBER < 'SDK00' THEN pay_amount
    ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
    ELSE pay_amount + 100
    This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
    DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
    In English this can be read as follows:
    IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
    Best wishes
    Michael

  • How to use date functions in BPEL

    Hi All,
    Is there any wayout for calculating no. of years with a given date and current date in BPEL.
    I am developing a small application where I have to calculate the years of experience of the employees. I am given with the date of joining.I want to subtract the date of joining from the current date. Is there any way-out to calculate no. of years from the given date and current date in BPEL using date functions or something else.
    Please suggest something..
    Thanks in Advance
    Roshni Shankar

    you could use something like this in xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
         <xsl:output method="xml"/>
         <xsl:variable name="date1" select="xs:date('2001-01-01')"/>
         <xsl:variable name="date2" select="xs:date('2010-01-10')"/>
         <xsl:variable name="dif" select="$date2 - $date1"/>
         <xsl:template match="/">
         <all>
              <date1>
                   <xsl:value-of select="$date1"/>
              </date1>
              <date2>
                   <xsl:value-of select="$date2"/>
              </date2>
              <dif-days><xsl:value-of select="fn:days-from-duration($dif)"/></dif-days>
              <dif-years1><xsl:value-of select="fn:years-from-duration($dif)"/></dif-years1> <!-- gives 0 for me -->          
              <dif-years2><xsl:value-of select="fn:days-from-duration($dif) div 356"/></dif-years2>                    
              </all>
         </xsl:template>
    </xsl:stylesheet>

  • Previous quarter from the current date using Date functions

    hi all,
    how can i get the value of the previous quarter and previous month using using NOW() function in the formula.
    regards,
    Rk
    Edited by: Rk on Feb 13, 2009 9:28 AM

    Hi Pk,
    This "DSTR(DADD(NOW(),-1,'Q'),'YYYYQ')" will give you just an year 2008 (if you run this today).
    But this "DSTR(DADD(NOW(),-1,'Q'),'YYYYMM)" will give you an year and month of prev quarter
    200811(if you run this today)
    Ola

  • Print a DayName without using Date functions

    Hi,
    I have an assignment like without using any date functions i should print a calendar.
    Below is the code without using any datefunctions like dateadd, datediff, datename a calendar has been generated for month and year entered. I want a week name for the dates like sunday ... monday etc. 
    I can take any date from calendar as reference  and calculate based on that date.
    ex: today is 2/20/2014 thursday . Next 7days again will be thursday, same way before 7days will be thursday.
    I need to loop in below procedure and get weekname. 
    Plz help in the code,
    I am using SQL server 2008
    IF OBJECT_ID ('dbo.Calendar1') IS NOT NULL
         DROP PROCEDURE dbo.Calendar1
    GO
    CREATE  PROCEDURE [dbo].Calendar1 --4,1991
       @month int,
       @Year  int
     AS  
     BEGIN
     declare 
     @startdateofMonthYear date,
     @EnddateofMonthYear Date
    Set @startdateofMonthYear=(Select cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'01')
    Set @EnddateofMonthYear = (SELECT case when @month IN (1,3,5,7,8,10,12) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'31'
    when @month IN(4,6,9,11) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'30'
    else  cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+(CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN '29' else '28' End) 
    End) 
    ;WITH CTE_DatesTable
    AS
    Select 1 daysint, Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(1 as varchar(2)) as DATE) Calendardates
    UNION ALL
    SELECT   daysint+1,Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(daysint+1 as varchar(2)) as DATE) Calendardates
    FROM CTE_DatesTable
    WHERE  daysint<= 
    (SELECT case when @month IN (1,3,5,7,8,10,12) then 31
    when @month IN(4,6,9,11) then 30
    else  (CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN 29 else 28 End) 
    End)-1
    Select 
    [DWDateKey]=Calendardates,
    [DayDate]=daysint,
    [MonthNumber]=@Month,
    [MonthName]=Case when @month = 1 then 'January'
     when @month  = 2 then 'February'
     when @month  = 3 then 'March'
     when @month  = 4 then 'April'
     when @month  = 5 then 'May'
     when @month  = 6 then 'June'
     when @month  = 7 then 'July'
     when @month  = 8 then 'August'
     when @month  = 9 then 'September'
     when @month  = 10 then 'October'
     when @month  = 11 then 'November'
     when @month  = 12 then 'December' 
    End,
    [Year]=@Year
    From CTE_DatesTable
    END
    bhavana

    In the above code, where do i pass the year and month?
    (Select 2000 YearID
    Union All
    Select YearID +1 From cte where YearID <2100
     In above condition from 2000 year its displaying.
    If i want in 90's year , Day name will not be correct.
    Deepa

  • How to use  date function in my procedure

    hi Gurus,
    i have a requirement
    where user passes the end_date parametre from front end which get convered to
    End Date => 2012/05/31 00:00:00
    now i based on this end date value i have to calculate the start date which is only month less than the end date, i know i can use add_months function for this requirement but
    my problem is
    l_start_date :=add_months(fnd_date.canonical_to_date(p_end_date),-1);
    (OR)
    l_start_date := add_months(to_date(end_date,'DD-MON-YYYY'),-1);
    all these are returning date format as DD-MON-YYYY eg;
    if user passes from front end 31-may-2012 , in the backend to my procedure it is passing as 2012/05/31 00:00:00
    and my procedure calculating start date and returning as '01-MAY-12',
    but my requiremnt is
    it should return
    Start Date => 2012/05/01 00:00:00
    any pointers on this is highly appreciable,
    thanks in advancee

    HuaMin Chen wrote:
    BluShadow wrote:
    HuaMin Chen wrote:
    Try
    select trunc(to_date('22-AUG-03'), 'MONTH') from dual;?? That is so wrong.
    Is that date 22nd August 2003? 22nd August 1903? 3rd August 2022? 3rd August 1922?
    You have no date format specified in your to_date function.That is fine for 10g or above versions. Thank you.It way work, if you're lucky, but it depends on your sessions NLS settings...
    SQL>  select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
    TRUNC(TO_DATE('22-AU
    01-AUG-0003 00:00:00
    SQL> alter session set nls_date_format = 'YYYY-MM-DD';
    Session altered.
    SQL>  select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
    TRUNC(TO_D
    0022-08-01
    SQL> alter session set nls_date_format = 'HH:MI:SS YYYY-MM-DD';
    Session altered.
    SQL>  select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
    select trunc(to_date('22-AUG-03'), 'MONTH') from dual
    ERROR at line 1:
    ORA-01849: hour must be between 1 and 12
    SQL>So it's certainly not "fine". It's bad practice.
    This must be fine
    select trunc(to_date('22-AUG-03','dd-MON-RR'), 'MONTH') from dual;That's better.

  • Using Date functions in DP macros

    Hi all,
    I am currently developing a macro in DP...and I need to do an action for the first period of a year.
    I need to identify the first period for this purpose..I m using the date function Bucket_fiscal_period for this purpose but for soem reasons it is not giving a value of 01 for the first period.
    The planning bucket has a weekly bucket pattern.
    I tried to use the layoututvariable_set + layoutvariable and then bucket_fiscal_period to try and see  if the values are getting set.But this seems not to be happening.
    Can anybody tell me whats wrong here?
    Thanks and Regards,
    Anu

    Hello,
    If I am understanding your issue correctly you are trying to identify the weekly bucket in which the first day fo the year falls. To accomplish the same I guess the following should work:
    OPTION 1:
      IF
         WEEK ( DATE ( BUCKET_BDATE ( X ) ) = 1
           THEN
            LAYOUTVARIABLE_SET ( 'FIRSTDAY' )
    ENDIF
    OPTION 2:
    IF
       YEAR_BDATE ( WEEK_BDATE () ) >= WEEK_BDATE ()
        AND
        YEAR_EDATE ( WEEK_BDATE () ) <= WEEK_BDATE ()
             THEN
                LAYOUTVARIABLE_SET ( 'FIRSTDAY' )
    ENDIF
    Hope this helps.
    Regards,
    Abhi

  • PL SQL using date functions to find partitions

    I am trying to teach myself PL SQL and can use a bit of help. I am trying to automate the
    dropping of paritions.
    Can somebody provide me with an example of how to create some code that will return a liist
    of partitions that are older than the N number of years (current year 1/1/2011), or N number of
    months, weeks or days...
    For example, today is 3/4/2011 How would I create code that will find me partitons that are
    older than 2/1/2011 (current first of month -1 month, or ciurrent first of month -N months).
    My partition names for all my tables are all in this formate P_YYYY_MM-DD
    Please keep in mind this query can retrurn no rows, one row or several rows. If nothing is retrurned
    I woiuld liike to print that out for each table.
    Thanks in advance to all who answer

    This would be a combination of sysdate and either add_months(date,number_of_months) or date-number_of_days, along with a conversion of the date to a pattern that matches your partition name format. Fortunately you've chosen a sensible format that sorts correctly.
    So for finding the number of partitions older than so-many years:
    select count(*)
    from   user_tab_partitions
    where table_name = ... and
             partition_name < to_char(add_months(sysdate,-12*5),'"P"_YYYY_MM-DD') Just be careful about whether you want partitions for which the oldest possible date is older than so-many years, or for which the newest possible date is older than so-many years.
    Edit: Oh bear in mind that if you select only COUNT(*) then you'll always get a row back even if no matching partitions are found, and COUNT(*) will be 0. If you selected table_name and count(*) then you would get no rows back for tables that have no matching partitions. COUNT(*) never returns null.
    Edited by: David_Aldridge on Mar 3, 2011 11:15 PM

  • Get particular day by using date functions in bpel

    Hi all,I want to get the 2nd day from every month of every year.Any body please suggest me how to write the xpath expression for this in bpel .Thq!
    Edited by: 851924 on Dec 28, 2011 2:12 AM

    Not possible....you have to use java embedding.

  • How can I display the vendor associated with result of my running total sum

    I have a report that lists vendors with their most vecent order dates.  I need to set up a rotation so that the vendor with the latest order date is next to be selected.  I used the running total summary to pick the latest date.  How can I display the vendor associated with result of my running total summary?

    If your "latest" order date means the "oldest" order date, why don't you try this:
    Go to Report tab -> Record Sort Expert -> Choose your order date in ascending order
    This will make your oldest order your first record shown. 
    You can then create a running total count for each record.
    Lastly, in your section expert under conditional suppress X+2 formula, write this:
    {#CountRecords}>1
    The result will only show the oldest record in your report.
    I hope that helps,
    Zack H.

  • Formula Help - Running Total vs ???

    Post Author: schilders
    CA Forum: Formula
    Good Morning All,
    I'm creating a report that contains a field called CDM Item.  This field indicates whether a particular order set was used for a given record.  Valid entries for this field are numeric 6 through 9.  I would like to create a formula that tells me the number of records that have a cdm item = 6, another formula that tells me the number of records that have a cdm item = 7 etc.  I need to summarize these formulas into pre-defined groups. 
    I was thinking a running total or a manual running total would be useful here.  However, I wanted to get some input from other formula gurus here.  Thanks, in advance, for your help.

    Post Author: yangster
    CA Forum: Formula
    You don't need to create a manual running total for what you are after.simply create 4 running totals ( 1 for each item number) using a running total with the evaluate formula of cdm =  6 (changed for each number)and resetting after whatever grouping you needthe other alternative you could implement if you have mutliple grouping and wanted subtotals on differing levels is to create a formula for each case such as@case_cdm6if cdm = 6 then 1 else 0then insert sum for each formula on all the differing group levels that way you only have to worry about maintaining one formula if the criteria changes

  • SSRS 2008 Running Totals - How are they created at the grouping by level

    I am trying to create the running total column(the right column) month-to-date, and I am new to SSRS.  Is this possible to do on the SSRS-side, or, will I need to do this in the SQL stored procedure that SSRS is calling?
    Number Enrolled
    Number Enrolled
    Enroll Date
    Enroll Type
    Enroll Group
    Enroll Offer
    Enroll Source
    DAILY
    MTD (Running Total)
    10/1/2013
    Online
    Internet
    1234
    ABC
    1
    1
    10/2/2013
    Online
    Internet
    1234
    ABC
    0
    1
    10/3/2013
    Online
    Internet
    1234
    ABC
    6
    7
    10/1/2013
    Online
    Internet
    1234
    DEF
    4
    4
    10/2/2013
    Online
    Internet
    1234
    DEF
    6
    10
    10/3/2013
    Online
    Internet
    1234
    DEF
    0
    10

    Hi Mitch1743,
    According to your description, you want to get the total number on each row. Right?
    In Reporting Service, we can use RunningValue function to do aggregation calculating for each row. Put expression: =RunningValue(Fields!Sales.Value,sum,”Group2”) into the last column (Group2 between “” is the parent group of detail rows).
    We have tested it in our local environment , the table and result will be looks like below:
    Reference:
    RunningValue Function (Report Builder and SSRS)
    Understanding Groups (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Running total as header formula

    I am looking for a simpler, more general, or just plain better way to calculate a running total of a column of numbers, such that the running total cell is the sum of a number in the same row & a different column plus the cell just above it in the same column.
    IOW, if the numbers column is H & the running total column is J, I could use =H5 + J4 in cell J5. In J6, I could use =H6 + J5, & so on. I can extend the formula downward without any problems, but I must make an exception for the first row of data: for instance, if row 2 is the first to have a number to include in the running total, then in J2 I must use =H2, since J1 is a header column.
    This means I can't use a simple formula in a header column for the running total. (I want to do this because I will be adding rows as the table is used, & I want all the formulas to automatically be added to each new row.)
    After trying a lot of functions, I finally came up with this one for the header formula:
    =H + INDIRECT(ADDRESS(ROW()-1,COLUMN(),4))
    It works, but I suspect there is an easier, more elegant, or more general formula that (for instance) won't break if I rearrange the columns in the spreadsheet.
    Any comments would be appreciated.

    Yvan,
    Thank you for your comments, & for the formulas. I was hoping there was a simpler way to do this than with INDIRECT & ADDRESS, but apparently not.
    In this particular spreadsheet, I do not need to worry about any blank values in column H because they are the results of a calculation that yields a number even if the row is otherwise blank.
    The ISERROR clause does allow me to name the running total column since without it the formula would be trying to add a string to a number in row two. However, in this particular spreadsheet I do not need to name that column because it is hidden. (The running total number column is used in another column that formats it as part of a string that contains other conditional information.) In the interests of simplicity, I will not add the ISERROR clause to my formula in this spreadsheet but I will keep it in mind for use in other spreadsheets in which the column will not be hidden & needs to be named.
    Of course, as an alternative I could just create the column name as an independent text object. Wherever possible, I tend to favor workarounds like that to reduce formula complexity.

  • Query with running Total

    Hello,
    I have a insert from query:
         insert into tablexxxx
         SELECT ALL      G.c1, G.c2,
                         CASE
                         WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                         WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                         WHEN G.colt1      =   'A'             THEN &DATASI
                         END colt3,
                     CASE G.colt2 WHEN 'D' THEN  G.IMP1  else 0   END    IMPD,
                    CASE G.colt2 WHEN 'A' THEN  G.IMP1  else 0   END    IMPA,
                         CASE
                         WHEN G.colt1  NOT IN ( 'B', 'C')
                         THEN (&VALU1 -1)
                         ELSE COLX
                         END      COLX,
         FROM table1 G, table2 S, table3 C
         WHERE  G.colt4    = S.colt4      
         AND (     (G.colt1  = 'M' AND  G.DATA1 BETWEEN &DATA_IP AND &DATA_FP AND G.TCOL6 = EXTRACT(YEAR FROM &DATA_IP) - 1 )
                OR (G.colt1 <> 'M' AND  G.DATA1 BETWEEN &DATA_IP AND &DATA_FP)
                OR (G.colt1  = 'A'  AND (&DATASI BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAIE) )
                OR (G.colt1  = 'B'  AND (&DATASF BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAFE) )
                OR (G.colt1  = 'C'  AND (&DATASF BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAFE) )  )
         AND  G.colt5  = C.colt5(+)
         ORDER BY 3,4,5 ; 
         NOW I HAVE TO INSERT in previous query 2 RUNNING TOTALE e.g:
               sum(CASE G.colt2 WHEN 'D' THEN  G.IMP1 + &myvalue1  else 0   END    IMPD) over (order by CASE
                         WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                         WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                         WHEN G.colt1      =   'A'             THEN &DATASI
                         END) running_sum,
             sum(CASE G.colt2 WHEN 'A' THEN  G.IMP1 + &myvalue2  else 0   END    IMPA) over ((order by CASE
                         WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                         WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                         WHEN G.colt1      =   'A'             THEN &DATASI
                         END) running_sum1    Could anyone help me to write it? ( maybe is better write it with SELECT-UNION?)
    Thanks in advance

    Hi IceMan,
    I think about having resolved in this way, I don't sincerely believe that is the optimal solution,
    but of sure it is that simpler,anyway, one opinion of yours would be very pleasant:
    1) I have made an Insert-Select with the 2 runnings total = 0
    INSERT INTO  TABLEX
    SELECT ALL G.c1, G.D2,
    CASE
      WHEN G.colt1 NOT IN ( 'A', 'B', 'C') THEN G.DATA1
      WHEN G.colt1 IN ( 'B', 'C') THEN &DATASF
      WHEN G.colt1 = 'A' THEN &DATASI
    END D1,
    CASE G.colt2 WHEN 'D' THEN G.IMP1 else 0 END IMPD,
    CASE G.colt2 WHEN 'A' THEN G.IMP1 else 0 END IMPA,
    CASE
    WHEN G.colt1 NOT IN ( 'B', 'C')
    THEN (&VALU1 -1)
    ELSE COLX
    END COLX, 0 RUNIMP_D, 0 RUNIMP_A
    FROM table1 G, table2 S, table3 C
    WHERE ........
    ORDER BY 3,4,5 ;2) in the populated table(step 1) I have made an UPDATE-SELECT getting the 2 runnings total
    UPDATE TABLEX A SET  (RUNIMP_D, RUNIMP_A ) =(
    SELECT  --G.D1, G.D2, G.IMPD,G.IMPA,
             SUM(G.IMPD) OVER (ORDER BY G.D1, G.D2,G.IMPD) RS1  ,
           SUM(G.IMPA) OVER (ORDER BY  G.D1, G.D2,G.IMPA) RS2
      FROM TABLEX G
    WHERE  G.ROWID = A.ROWID     
    --ORDER BY 1,2
    where G.D1 is that I get from
    CASE
    WHEN G.colt1 NOT IN ( 'A', 'B', 'C') THEN G.DATA1
    WHEN G.colt1 IN ( 'B', 'C') THEN &DATASF
    WHEN G.colt1 = 'A' THEN &DATASI
    END D1
    and
    G.IMPD is:
    CASE G.colt2 WHEN 'D' THEN G.IMP1 else 0 END IMPDThanks again for your reply

  • Form 6i: filtering data on a running total

    I need to create a column in a group to represent a running total. But I want that running total to only sum rows that meet specific criteria, such as (:m_form.cost) <> 0. How can I accomplish this?
    Thank's in advance!
    [email protected]

    se deben crear dos campos nuevos en el bloque, uno que te calcule el valor deseado determinado por las condiciones dadas, este campo debe tener el pl/sql necesario para determinar el valor, en la seccion calculation-->formula (property palete) (ej. if <condicion> then :campo_x * 1 else :campo_x * 0 end if;). y otro campo que sumarice al anterior, teniendo este "sum" en la seccion summary Function, y el campo anterior en summarized item. Si no me entiendes o esa no era tu pregunta devuelveme y te la escribo en ingles.

Maybe you are looking for