Summing

Hi all]
just need a bit of help i have to write a javascript program to add numbers i can find plenty on adding just 2 numbers together but im having trouble as i have to add 1 to 10 or even 1 to 10,000. Im not having much help when i search the internet i have to use a for loop to do this
<HTML>
<HEAD>
<SCRIPT LANGUAGE = "java script"
// a program for summing numbers from 1 to biggest Number
Var biggestNumber;
Var theSum = 0;
text goes here
window. alert ( 'The sum of the numbers from 1 to ' + biggestNumber + ' + theSum);
Adding two numbers is easy yeah but adding anitialise biggest number to 20 or even 10,000 I'm ripping my hair out now
vicki

Hi Little Lady,
Here I am..............
Store the 2 nos. in 2 variables---
var a = f1; //First No. (The Smaller No.)
var b = f2; //Second No.(The Bigger No.)
var d = (f2*(parseInt(f2)+1)/2);
var e = (f1*(f1-1)/2);
var summ = d-e;//Summ will give you the summation between2 numbers(f1&f2)
To Sum Up----
E.g> Summation between 50 and 500
var a = 50;
var b = 500;
var d = (b*(parseInt(b)+1)/2); // 125250
var e = (a*(a-1)/2); //1225
var summ = d-e;
alert(summ); // Will alert you 124025Tata...
Cheers!

Similar Messages

  • IF statement in Calculated Field for Share point, doesnt calculate sum in my Excel Pivot table.

    Hi Everyone
    I used this in SP calculated column field.
    =IF([Shift Sched]="1pm to 10pm","0",IF([Shift Sched]="2pm to 11pm","1",IF([Shift Sched]="3pm to 12am","2",IF([Shift Sched]="4pm to 1am","3",IF([Shift Sched]="5pm to 2am","4",IF([Shift
    Sched]="6pm to 3am","5",IF([Shift Sched]="7pm to 4am","6",IF([Shift Sched]="8pm to 5am","7",IF([Shift Sched]="9pm to 6am","8",IF([Shift Sched]="10pm to 7am","8",IF([Shift
    Sched]="11pm to 8am","7",IF([Shift Sched]="12pm to 9am","6",IF([Shift Sched]="1am to 10am","5",IF([Shift Sched]="2am to 11am","4",IF([Shift Sched]="3am to 12pm","3",IF([Shift
    Sched]="4am to 1pm","2",IF([Shift Sched]="5am to 2pm","1",IF([Shift Sched]="6am to 3pm","0",IF([Shift Sched]="7am to 4pm","0",IF([Shift Sched]="8am to 5pm","0",IF([Shift
    Sched]="9am to 6pm","0",IF([Shift Sched]="10am to 7pm","0",IF([Shift Sched]="11am to 8pm","0",IF([Shift Sched]="12pm to 9pm","0"))))))))))))))))))))))))    
    it was able to work fine however my issue is when i extract the information to excel and use a pivot table the table is not able to calulate the sum of the value for this field. Can you please help me with this. this is for an Attendance traker for Night
    Differential pay for employees. they create a daily log of their shift schedule and if i summarize this in pivot the value in the calculated field for this is not getting the sum.
    Thanks,
    Norman

    Hi Everyone
    I used this in SP calculated column field.
    =IF([Shift Sched]="1pm to 10pm","0",IF([Shift Sched]="2pm to 11pm","1",IF([Shift Sched]="3pm to 12am","2",IF([Shift Sched]="4pm to 1am","3",IF([Shift Sched]="5pm to 2am","4",IF([Shift
    Sched]="6pm to 3am","5",IF([Shift Sched]="7pm to 4am","6",IF([Shift Sched]="8pm to 5am","7",IF([Shift Sched]="9pm to 6am","8",IF([Shift Sched]="10pm to 7am","8",IF([Shift
    Sched]="11pm to 8am","7",IF([Shift Sched]="12pm to 9am","6",IF([Shift Sched]="1am to 10am","5",IF([Shift Sched]="2am to 11am","4",IF([Shift Sched]="3am to 12pm","3",IF([Shift
    Sched]="4am to 1pm","2",IF([Shift Sched]="5am to 2pm","1",IF([Shift Sched]="6am to 3pm","0",IF([Shift Sched]="7am to 4pm","0",IF([Shift Sched]="8am to 5pm","0",IF([Shift
    Sched]="9am to 6pm","0",IF([Shift Sched]="10am to 7pm","0",IF([Shift Sched]="11am to 8pm","0",IF([Shift Sched]="12pm to 9pm","0"))))))))))))))))))))))))    
    it was able to work fine however my issue is when i extract the information to excel and use a pivot table the table is not able to calulate the sum of the value for this field. Can you please help me with this. this is for an Attendance traker for Night
    Differential pay for employees. they create a daily log of their shift schedule and if i summarize this in pivot the value in the calculated field for this is not getting the sum.
    Thanks,
    Norman

  • Discoverer  report does not sum up the column

    Hi All,
    I am running the discoverer report from discoverer desktop and was
    trying to use the sum function to sum the total amount of the report.
    The sum function does not work and it only display Cell
    Sum: (blank) with no actual data.
    When i checked the report details some columns are calculated based on the columns which i want to sum up.
    Any ideas please share with me
    Thanks in advance.

    b) What is the difference between sum and cell sum? Well, I certainly won't claim to be a Discoverer guru. From what little I have seen, the practical result is not any difference really between the two. SUM of a calculated row is adding up the calculation to the total. Whereas cell sum is like adding up the individual values behind the calculation you see. The distinction makes more sense when you have SUM DISTINCT and CELL SUM DISTINCT being involved. Then you will see a difference in the calculated total. But for SUM and CELL SUM itself, I have not seen any difference between the two, but I am still pretty new to Discoverer.
    e) Aggregate field from a folder. Well, this may be one where you have to play around with your own data to understand. Let me try to give you a simple example. Let's say you have a sales table with 100 rows. You have sales data for 5 cities, and each city has 20 rows of sales history. If you pick Sales Dollars Detail and City Name for your workbook and run, you will get 100 rows in your result (complete detail listing). So that is what happens with no aggregation. Now, instead of doing Sales Dollars Detail, you pick Sales Dollars Sum (the same thing as saying SUM(Sales Dollars) in an SQL statement). Run the workbook. You will now get 5 rows of data, instead of 100 rows of data. You will get one row for each city. If you look at the SQL that Discoverer generates, you will see that it has now done a GROUP BY in the SQL statement. Notice I have not said anything about DISTINCT (just trying to keep things simple).
    Now, lets say you do a workbook for City, Part Number, and Sales Dollars Sum. Run the workbook. You get a summarized result (say maybe 10 rows of summary data this time). If you look at the Discoverer SQL, the GROUP BY is now by city and part number, automatically doing that because you picked the SUM version of sales dollars.
    Now lets say you add Sales Units Detail to the workbook. Discoverer will give you a warning message that you are have both an aggregate and a non-aggregate and that you may end up with unpredictable results. Run the workbook. You will be back to 100 rows, because you specified sales units in detail.
    Most of the time I do not want to see detail rows in a workbook. So most of the time I am picking the SUM aggregate for an amount item.
    Hope this explains things a bit. Sounds like maybe you need to take the Discoverer Create Queries and Reports class. Would help you understand these things better. Good luck.
    John Dickey

  • Sum function within if/then/else (xdofx:if)

    I'm attempting to display a total at a particular group within my report. This total is conditional and should choose to display a placeholder value or the sum of another placeholder value (in a child group).
    I have been able to vary my output based on the value I want to check: FIXED_QUOTE_FLAG - I have the if/then/else working in a simplified fashion
    I can display literals and some placeholders correctlly eg. print a literal value of 00110011 or the value of placeholder QUOTED_PRICE
    I can also display a calculated placeholder, using sum within the group I am concerned with: sum (current-group()/ACTIVITY_CHRG)
    But when I try to get everythign working together ...
    I cannot get the sum to work inside the if/then/else condition. The result is NULL (blank in HTML output).
    The following is the snippet which is not working correctly:
    <?xdofx:if FIXED_QUOTE_FLAG = 'Y' then QUOTED_PRICE else sum (current-group()/ACTIVITY_CHRG) end if?>
    Message was edited by:
    gareth_adamson

    To answer you first question, perhaps sum is not a supported function in the xdofx namespace. It's annoying when this problem comes up because xdofx namespace seems to be the only way to do if then else clauses. I'm not entirely certain on the above, but you could resort to using BI Publisher's built-in if statement.
    For your problem, something like this:
    <?if: FIXED_QUOTE_FLAG='Y'?>
    QUOTED_PRICE
    <?end if?>
    <?if: FIXED_QUOTE_FLAG!='Y'?>
    <?sum(current-group()/ACTIVITY_CHRG)?>
    <?end if?>
    EDIT:
    There is a way to do if else without xdofx namespace. It is done with <?choose:?> <?when:?> and <?otherwise:?> tags. Here is example syntax copied from Tim Dexter's blog:
    <?choose:?>
    <?when:count(TRX_NUMBER) > 0?>
    Invoice Table
    <?end when?>
    <?otherwise:?>
    No Data Found
    <?end otherwise?>
    <?end choose?>
    To answer the second question about a running total, you will need to use the <?xdoxslt:set_variable($_XDOCTX,'var_name',var_value)?> and the <?xdoxslt:get_variable($_XDOCTX,'var_name')?>. This method of working with variables is the only method that allows you to update a variable. This makes it good for running totals. Consult the official user guide under "Creating an RTF Template" the section about using variables and calculating running totals.
    So, in your problem, once you get the first part working, you will have to add that value to your running total. It will look something like this:
    <?xdoxslt:set_variable($_XDOCTX,'running_total',xdoxslt:get_variable($_XDOCTX,'running_total') + conditional_value)?>
    Remember to initialize the running total to zero! Hope this helps.
    Thanks,
    Matt Soukup
    Message was edited by:
    Matt Soukup

  • Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount 28

    Post Author: tadj188#
    CA Forum: Formula
    Needed: Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount > 28
    Background:
    1) Report SQL is created with unions to have detail lines continue on a page, until it reaches page footer or report footer, rather than using  subreports.    A subreport report is now essentially a group1a, group1b, etc. (containing column headers and other data within the the report    with their respective detail lines).  I had multiple subreports and each subreport became one union.
    Created and tested, already:
    1) I have calculated @TotalLineForEachOfTheSameGroup, now I need to sum of the individual same group totals to get the total line count on a page.
    Issue:
    1) I need this to create break on a certain line before, it dribbles in to a pre-printed area.
    Other Ideas Appreciated:
    1) Groups/detail lines break inconveniently(dribble) into the pre-printed area, looking for alternatives for above situation.
    Thank you.
    Tadj

    export all image of each page try like this
    var myDoc = app.activeDocument;
    var myFolder = myDoc.filePath;
    var myImage = myDoc.allGraphics;
    for (var i=0; myImage.length>i; i++){
        app.select(myImage[i]);
        var MyImageNmae  = myImage[i].itemLink.name;
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
        app.jpegExportPreferences.exportResolution = 300;
           app.selection[0].exportFile(ExportFormat.JPG, File(myFolder+"/"+MyImageNmae+".JPEG"), false);
        alert(myImage[i].itemLink.name)

  • How to create a sum on change of a detailed record without using groups

    Hi,
    I'm working on an overtime/payroll report.  Overtime hours are calculated based on hours worked greater than 40 within the span of Sunday to Saturday.  Further, pay periods are every two weeks and do not align with the calendar week of sunday to saturday.
    I've managed to figure out how to do the overtime calculation from sunday to saturday and then the totals for each of these calendar weeks. However, I'd also like to calculate the totals for the pay periods.  I cannot group on both the calendar week AND the pay period id because sometimes the calendar week starts before the pay period starts and sometimes the pay period starts before the calendar week. So, one is not a sub-group of the other.  I tried setting both up as groups but it, unfortunately, resets by hour calculations at the wrong point because when one group is still going the other is ending.
    So, the report is working well with just the one group - calendar week (oh, and there is a higher level group - employee id as this calculation is done for each employee). I can include the pay period id in the detail lines and I can see when it changes. So, if I could create a formula that summed the hours by pay period id and than reset when a new pay period id begins that is what I am after. I just want the sum of hours upon each change of pay period id.  I'll attempt to show what the data looks like below:
    Group 1: Employee Name (say Fred Jones)
       Group 2: Week Beginning January 8, 2012
    Date  RegularHours   OvertimeHours  PayPeriodId
    Jan 8        12                              0                            1
    Jan 9        12                              0                            1
    Jan 10      12                              0                            1
    Jan 11       4                               8                            1
    Jan 12       0                               12                          1
    Jan 13       0                               9                            1
    Jan 14       0                               6                            1
    Total      40                          35                   
    Group 2: Week Beginning January 15, 2012
    Date  RegularHours   OvertimeHours  PayPeriodId
    Jan 15      12                              0                            1
    Jan 16      12                              0                            1
    Jan 17      12                              0                            1
    Jan 18       4                               9                            2
    Jan 19       0                               10                          2
    Jan 20       0                               8                            2
    Jan 21       0                               7                            2
    Total      40                          34                   
    So, the total hours for pay period #1 should be:
    RegularHours   OvertimeHours
    76                                35
    And, the total hours for pay period #2 should be:
    RegularHours   OvertimeHours
    4                                   34
    I tried creating a formula: Distinctcount ({@OT Hours}, {Command.pay_periods_id}) but Crystal says I cannot summarize the formula that is in it.
    I'm not a programmer but it feels like a loop of some sort (For each, unique pay period id sum the OT Hours).
    Any and all help much appreciated in advance!
    Mark
    Edited by: mahewitt on Feb 14, 2012 4:42 AM

    Hi Mark,
    Here's something I have come up with:
    1) Create this formula and place it on the details section beside the PayPeriodID field.Replace in the formula with PayPeriodId, with RegularHours and with OvertimeHours.
    WhilePrintingRecords;
    numbervar array reg_hrs;
    numbervar array ot_hrs;
    numbervar array payid;
    numbervar reg;
    numbervar ot;
    numbervar x;
    numbervar y;
    if not({PayperId} in payid) then
        y := y + 1;
        redim preserve payid[y];
        payid[y] := {PayperId};
    if onlastrecord then
        reg := reg + {Regular};
        ot := ot + {Overtime};
        x := x + 1;
        redim preserve reg_hrs[x];
        redim preserve ot_hrs[x];
        reg_hrs[x] := reg;
        ot_hrs[x] := ot;
    else if {PayperId} = next({PayperId}) then
        reg := reg + {Regular};
        ot := ot + {Overtime};
    else
        reg := reg + {Regular};
        ot := ot + {Overtime};
        x := x + 1;
        redim preserve reg_hrs[x];
        redim preserve ot_hrs[x];
        reg_hrs[x] := reg;
        ot_hrs[x] := ot;
        reg := 0;
        ot := 0;
    2) Create this formula and place it on the Group Footer 1 (Employee Name group):
    WhilePrintingRecords;
    numbervar array payid;
    numbervar array reg_hrs;
    numbervar array ot_hrs;
    numbervar i;
    stringvar final;
    for i := 1 to ubound(payid) do
        final := final + "For Pay Period # "&payid<i>&chr(13)&chr(13)&"Regular Working Hours are :"&reg_hrs<i>&chr(13)&"Overtime Hours are :"&ot_hrs<i>&chr(13)&chr(13)&chr(13)
    final;
    3) Right-click this field and select Format Field > Common tab > Check the 'can grow' option and increase the horizontal size of the formula field to around 3.5 to 4'
    4) Create this formula to reset the variables at the Group Header 1. This will make sure it prints the Regular and Overtime hours for every employee:
    whileprintingrecords;
    numbervar array reg_hrs := 0;
    numbervar array ot_hrs := 0;
    numbervar array payid := 0;
    numbervar reg := 0;
    numbervar ot := 0;
    numbervar x := 0;
    numbervar y := 0;
    numbervar i := 0;
    stringvar final := "";
    You may then hide the 1st and the last formula (Right-click > Format field > Common tab > Suppress)
    Let me know how this goes!
    -Abhilash

  • Average & SUM in a Single criteria in the Pivot View

    Hi,
    Can you plese let me know whether it is possible to have SUM at the Grand Total level & Average on the Right Hand side of the Pivot Table view at the same time.
    Thanks & Regards
    Siva.

    Hi,
    The way you want to do it is not possible.
    What you can do is make a union of 2 reports one is using the Sum and the other the AVG and not use the Grand total provided by OBIEE.It's kind of creating your own Grand Totals
    Look at this thread it will help:
    http://obiee101.blogspot.com/2010/08/obiee-combine-with-similar-request.html
    If you are using pivot table you can think about a new calculate item as a GT
    http://varanasisaichand.blogspot.com/2010/12/aggregate-functions-on-grand-total.html
    Best regards
    Adil
    PS: Please don't forget to close the thread and assign points when your question is answered
    Edited by: adil.harrab on Jun 6, 2011 1:36 PM

  • SSRS 2008 R2 Report - Sum Totals of a Filtered Group

    I'm at a loss here, so any help will me much appreciated. I will do my best to explain, but if you need additional information, please let me know:
    I have a very large dataset of patient data. Specifically for the numbers I need, I have a patient number field, a county field, a 1 or 0 for LastYear field, and a 1 or 0 for CurrentYear field.
    Example:
    PtNo    County  PY  CY
    45676  Scott     0    1
    45322  Cape     1     0
    47686  North     0     1
    The thing I am shooting for on my report is, "Volume growth in 3 counties (+20 cases)."
    I created a group and grouped by County (group name County) and I included a group filter to only include "total cases of CY" are greater than "total cases of PY" to narrow my data to only counties that had a higher current year sum
    than previous year sum.
    Example:
    County  PY    CY  Difference
    Scott    141  143     2
    Cape     90    98      8
    North    78     88    10 
    All is working well, except I don't need to see the Counties themselves, I just need the 3 counties and a difference of 20. 
    I explored online and found tutorials that said to right click on the field and select "Add Total" but this total did not have my filter in it and gave me everyone. I also tried adding a row outside the group and used the RunningValue function
    (i.e. RunningValue(Fields!FYTD_Current_Year.Value, Sum, "County"))  but it gave me a message that states "The Value expression for the text box 'Textbox456' has a scope parameter that is not valid for an aggregate function. The scope
    parameter must be set to a string constant that is equal to either the name of a containing data region or the name of a dataset."
    When I move the row with the RunningValue function inside the group, it runs but I get the same information repeated twice for each county with no final total.
    So I am not sure how to go about getting my values I need for my report. Anybody know how to resolve this?
    Thanks,
    Cyndi
    cpemtp1

    Hi Cyndi,
    Based on my understanding, you specify a filter condition in group properties. Then you want to sum the filtered values for each field.
    In this scenario, we need to specify a filter condition on group level. If we use sum() function out of group, the expression will calculate the total values on dataset level instead of group level. So we can’t simply use expression to achieve this goal.
    However, we can use custom code to record the filtered values for each field, then we can calculate the total based on these values. Please refer to the steps and screenshots below:
    1. Add the custom code below into the report:
    Public Shared Value1 as Integer=0
    Public Shared Function GetValue1(Item as Integer) as Integer
    value1= value1 + Item
    return Item
    End Function
    Public Shared Function GetTotal1()
    return value1
    End Function
    Public Shared Value2 as Integer=0
    Public Shared Function GetValue2(Item as Integer) as Integer
    value2= value2 + Item
    return Item
    End Function
    Public Shared Function GetTotal2()
    return value2
    End Function
    2. Design the tablix like below:
    3. The result looks like below:
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu

  • SSRS Using Sum and = in a conditional operator

    Hi,
    Still getting to grips with SSRS so any help would be appreciated.
    My aim is to calculate a conditional field using the SSRS expression feature, the datasource is a shared dataset which i can't alter so i can't just go an alter the SQL query or anything.
    In SQL my query would be like this: SELECT COUNT(TotalHours) FROM TableName WHERE TotalHours <= 24
    Is there anyway to combined the Iff and Sum operator's to get a result like the above?
    At present all i managed to come up with is the below but obviously it's not returning the correct amount.
    =IIf(Fields!TotalHours.Value <= "24", Sum(Fields!TotalHours.Value), 0 )
    Please help!
    Edit: Please note that i'm not trying to sum a field based on a condition that relates to another column, i just need a sum of 'TotalHours' that are less than or equal to 24, please also note there is another field called category, each category needs a
    sum of the above.
    Regards,
    Marcus
    Plain_Clueless

    Hi Marcus,
    According to your description, you want to count [TotalHours] when the value of this field is less than 24, right?
    In your scenario, you could use the expression like below:
    =Sum(IIF(Fields!TotalHours.Value<=24,1,0))
    Please note don’t put this expression in the detail rows, you could refer to our test results:
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • SSRS expression sum question

    I want to add a column after Total lets say..'Progress' where Progress = sum(Actual)/sum(Budget)
    The only filter on Progress is to consider only those values from months where both Actual and Budget are present.
    So, e.g.
    For first row: 0/0 = 0
    For second row: 0/0 = 0
    For third row: 28334/67060(instead of 200511) = 0
    if there would have been an Actual value for the month of August e.g. 100, then (28334+100)/(67060+66614)
    For fourth row: 0/0 = 0
    How can I achieve this using expressions in SSRS?
    Thanks in advanc

    Hi rockstar283,
    As per my understanding, you want to add a column names Progress, it is calculated from the values of Actual and Budget. In current month, Progress = sum(Actual)/sum(Budget), else, it is set to 0. If so, please refer to the following expression:
    =IIF(Month(Fields!pmonth.Value)=Month(Today()),Sum(Fields!Actual.Value),0)/IIF(Sum(Fields!budget.Value)=0,1,Sum(Fields!budget.Value))
    The following screenshot is for your reference:
    If my understanding is not correct, please feel free to let me know. I would appreciate it if you could give us detailed description of your requirements, it’s also better to provide the table structure and some sample data. It will help us move more quickly
    toward a solution.
    Thanks,
    Wendy Fu

  • While importing a request error message' Check-sum error in data file'

    Hi Friends
    I have a problem.
    We are trying to inport a request after putting the files in cofile and data file folders( 4.6C System).While doing so an error message is seen in the log " Check-sum error in data file after XXXX bytes".
    Can some one help me with this?
    Thanks
    Regards
    Ankur

    Hi Ankur,
    It is sure your file is corrupted or not present.
    Check in cofiles and data directory under /usr/sap/trans your transport request number.
    Best Wishes.
    Kumar

  • SQL Query Help: Average of Sums !

    Hi Folks !
    I've been tasked with wirting a program that queries Oracle DB. And I'm not used to SQL a lot. May be my question is very basic. Please bear with me.
    I've simplified the table structure for this question.
    The table Order has 4 fields:
    1. Order_id
    2. Trial_No.
    3. Response_Time.
    4. Order_Time
    Now the first two fields (Order_id, Trial_number) together make up the Primary Key (It is a composite key). My goal is to find the Average Response time for each Order ID in the past 10 minutes. Order_Time is the time at which Order was placed. An order can take more than one trail to complete the order. Order Reponse time is the sum of all the Trail response times.
    A basic query like this
    select AVG(Response_Time) from Order where Order_time < sysdate -10/1440.
    gives me the Average of the response time but here is the catch : It produces the Average no matter how many trials the Order had. An order's response time is SUM of all the Trail Response times it had.
    Consider the following data in the table
    Order_id Trial_No Resopnse_Time (ms)
    1 1 1000
    2 1 1000
    2 2 1000
    2 3 1000
    If I just use "select AVG(RESPONSE_Time), it will result in 1000ms. (4000/4).
    But in reality, Order 2 had taken 3000ms to complete (3 trials). And the Avg Order Response time should be (1000+3000)/2 = 2000ms. Can you see it?
    In other words, How do I calcluater the Avg of the sums of the rows, instead of Avg of all the rows. I've gone through some docs about 'group by' clause and 'subqueries', but don't seem to find the answer.
    Thanks very much for reading such a long post. Looking forward to some guideance.
    - K

    You'll want some analytics on this:
    SYS%xe> --select sum(sum_resp_time)/sum(rn) avg
    SYS%xe> --from (
    SYS%xe> with dataset as
      2  (select  1 Order_id, 1 Trial_No, 1000 Response_Time from dual union all
      3   select  2         , 1         , 1000 from dual union all
      4   select  2         , 2         , 1000 from dual union all
      5   select  2         , 3         , 1000 from dual
      6  )
      7  select order_id
      8  ,      response_time
      9  ,      row_number() over ( partition by order_id  order by order_id) rn
    10  ,      sum(response_time) over ( partition by order_id  order by order_id) sum_resp_time
    11  from dataset
    12  -- ) where rn = 1;
      ORDER_ID RESPONSE_TIME         RN SUM_RESP_TIME
             1          1000          1          1000
             2          1000          1          3000
             2          1000          2          3000
             2          1000          3          3000
    4 rijen zijn geselecteerd.
    Verstreken: 00:00:02.15
    SYS%xe> select sum(sum_resp_time)/sum(rn) avg
      2  from (
      3  with dataset as
      4  (select  1 Order_id, 1 Trial_No, 1000 Response_Time from dual union all
      5   select  2         , 1         , 1000 from dual union all
      6   select  2         , 2         , 1000 from dual union all
      7   select  2         , 3         , 1000 from dual
      8  )
      9  select order_id
    10  ,      response_time
    11  ,      row_number() over ( partition by order_id  order by order_id) rn
    12  ,      sum(response_time) over ( partition by order_id  order by order_id) sum_resp_time
    13  from dataset
    14  ) where rn = 1;
           AVG
          2000
    1 rij is geselecteerd.But you could do without them, as Raj showed.
    ( I guess this is one of my weirdest queries ;-) )
    Edited by: hoek on Apr 7, 2009 6:17 PM

  • Can not use SUM in a simple query because of a syntax error?

    Hi
    Thank you for reading my post.
    I am trying to execute the following query:
    q = em.createQuery("SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))");
                  q.setParameter("contractor", contractor);
    q.setParameter("diameter", diameter);
         l =  (Long) q.getSingleResult();And I get the following error:
    Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
    Exception Description: Syntax error parsing the query [SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))], line 1, column 12: unexpected token [(].
    Internal Exception: line 1:12: unexpected token: (
            at oracle.toplink.essentials.exceptions.EJBQLException.unexpectedToken(EJBQLException.java:389)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.handleANTLRException(EJBQLParser.java:350)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.addError(EJBQLParser.java:278)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.reportError(EJBQLParser.java:378)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1416)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectExpression(EJBQLParser.java:1158)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectClause(EJBQLParser.java:403)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectStatement(EJBQLParser.java:178)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.document(EJBQLParser.java:135)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.parse(EJBQLParser.java:166)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree(EJBQLParser.java:127)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:215)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:189)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:153)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:114)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:99)
            at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
            at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204)
            ... 30 more
    Caused by: line 1:12: unexpected token: (
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1365)
            ... 43 morePlease let me know what am I doing wrong?
    Thanks.

    Hello,
    From the grammar in the JPA spec, SUM only takes a state_field_path_expression which is defined as
    state_field_path_expression := {identification_variable | single_valued_association_path_expression}.state_field
    Please feel free to file an enhancement to have this expanded upon.
    Best Regards,
    Chris

  • SUM Function in RTF Template

    Hi buddies,
    can we use functions like SUM,AVG etc. in the RTF Template.
    If possible please give adivce for the below scenario
    I have one column in the main body table "Extended Amount", I want to sum this field for the another column Total Extended Amount below this Main table.
    with regards
    Ram

    Hi All,
    I have a problem in calculating the SUM in RTF template with condition,
    Here is the XML
    - <LIST_G_LINE_NOTES>
    - <G_LINE_NOTES>
    <LINE_TRX_ID>1567856</LINE_TRX_ID>
    <LINE_ID />
    - <LIST_G_TRX_LINE>
    - <G_TRX_LINE>
    <CF_ITEM_NO>SDCN1144B</CF_ITEM_NO>
    </G_TRX_LINE>
    </LIST_G_TRX_LINE>
    - <LIST_G_LINE_EQUIVALENT_UNIT_PRICE>
    - <G_LINE_EQUIVALENT_UNIT_PRICE>
    <LINE_EQUIVALENT_UNIT_PRICE>-15.99</LINE_EQUIVALENT_UNIT_PRICE>
    <LINE_EXCHANGE_EXTENDED_AMOUNT>-223.86</LINE_EXCHANGE_EXTENDED_AMOUNT>
    <CUSTOMER_TRX_LINE_ID>1567856</CUSTOMER_TRX_LINE_ID>
    </G_LINE_EQUIVALENT_UNIT_PRICE>
    </LIST_G_LINE_EQUIVALENT_UNIT_PRICE>
    - <LIST_G_TRX_LINE>
    - <G_TRX_LINE>
    <CF_ITEM_NO></CF_ITEM_NO>
    </G_TRX_LINE>
    </LIST_G_TRX_LINE>
    I need the summation of field LINE_EXCHANGE_EXTENDED_AMOUNT with the condition CF_ITEM_NO!=''
    can anybody help me with the solution.
    Thanks in Advance

  • Performing a Sum on a Conditional if statement (in Business Objects)

    Post Author: Rhonda Jackson
    CA Forum: Formula
    I have been trying to debug a sum statement that evaluates a code (for example 0001) which then maps the corresponding dollar amount to a new column.  This part is working.  Unfortunately when I try to sum the values in the new column with the mapped values that meet the criteria, I receive a syntax error at the second If statement.  Any assistance of suggestions would be appreciated.  I have tried Sum(If....) and it still provides a syntax error.  Here is a sample of the code.
    =If(&#91;Acct - Account Purpose Code&#93;="0001";&#91;Acct - Sum Loan Amount X-collateral&#93;; If(&#91;Acct - Account Purpose Code&#93;="0003";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0008";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0009";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0010";&#91;Acct - Sum Loan Amount X-collateral&#93;; If(&#91;Acct - Account Purpose Code&#93;="0011";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0012";&#91;Acct - Sum Loan Amount X-collateral&#93;;If(&#91;Acct - Account Purpose Code&#93;="0014";&#91;Acct - Sum Loan Amount X-collateral&#93;;"0"))))))))

    Post Author: branko
    CA Forum: Formula
    Where is your sum located ? Where is your mapped value  located? Here are some shooting in the dark that might light a bulb.I assume you are using Crystal 9 or above. You might want to try running total. For each code EG. 0001 you would create running total that looks like this You
    would select field you want to sum ( eg. dolar value) then you would
    click on formula icon "x-2" in evaluate section and type something like
    this. (&#91;Acct - Account Purpose Code&#93;="0001"Then put  running total in  in the footer. Create text box and type something like this "SUM OF "TEXT BOX -
    SUM OF 0001 = your running total you made (e.g.RT0001) Repeat steps 1 and 2 for rest of the codes. ALTERNATIVE**** You might want to consider this approach also.Create a group base on (&#91;Acct - Account Purpose Code&#93;) created field. You would create a formula. And then put it in the detail section. Select it and make it a group. Then you can have sums per group.

  • TableCalcs method Sum does not work

    Hi all.
    I am newcomer in the ADOBE forms world and I am facing the following issue (although I 've been reading posts in SDN and respective manuals for over 3 days)
    My form's hierarchy is:
    (xfa.form.)
    -data
      -MasterPageSet1 (Page Set)
        ---Page1  (Master)
           --ContentArea
           --HeaderData (positioned subform with various elements)
           --FooterData (positioned subform with various elements)
        ---MainWindow (Flowed subform)
           --t_subf (Flowed subform)
            --Table (table which will show data from respective interface table)
               --Header
               --RowData (actual line items)
               --PageSum (table footer)
      Both RowData and PageSum have a decimal field named "DMBTR_S"
      At the end of every page, in the PageSum-DMBTR_S field, I want to sum the page's RowData[*]-DMBTR_S data to produce a "carry Fwd" for the next page.
      Looking through SDN and LiveCycle designer help, I have tried both using JavaScript and using the tableCalcs but with no luck
      Given that I am a newbie in both ADOBE forms and JS, I assume that I am missing some details.
      So, I suppose that the tableCalcs (with the parameters for the current page) can help me the most, without needing me writing JS.
      However, I do not understan at which level in the aforementioned hierarchy should I insert the tableCalcs.
      I tried inserting it under MainWindow subform and renamed the unnamed subform to "tcalc"
      Then, I set PageSum-DMBTR_S field to Calculated-ReadOnly, with Normal Bindin, and I write in the calculate event:
    if ( xfa.layout.page(this) == xfa.layout.pageCount())
    //I copy the header's amount as the final total :P
    this.rawValue = t_subf.TOT.rawValue;
    else
    //calculate the cummulative from age 0 to current
    this.rawValue = MainWindow.tcalc.tableCalcs.Sum("Table.RowData[*].DMBTR_S",0, xfa.layout.absPage(this)-1);
    When I preview the PDF inside the Form Builder (trans: SFP), PDF is generated successfully, without any warnings/errors at all.
    What am I missing here?
    Thank you in advance,
    George

    Hello Otto and thanks for the reply.
    a) I could indeed do it in the backend but that means that I have to hardocde the max number of line items per page. I always prefer to decouple application logic (the printing program) from the presentation medium ( the form). However, that would be me utmost way of doing it, as the time is against me...
    b) I understand what you mean, but I don't have a single clue how to do it with Javascript Pretty smart, but I would prefer the (a)  approach, as I can code it way much faster with ABAP in the printing program
    c) another solution may be the tableCalcs. This "collection" of objects/methods has already implemented a Sum method which seems to do exactly what I need. I have read both the PDF documents you mention but unfortunately I haven't managed yet to make it work in a... stylish (!!!) way.
    In page 103, the "lc_designer_scripting_basics.pdf" offers a JS snippet to "calculate the sum of repeating fields". I have alse tried this approach but it seems that the statement  var fields = xfa.resolveNodes("RowData[].DMBTR_S[]"); doesn't work at all. I have included it in a "try-finally" block and it fails...
    Anyway, I will keep trying and come back to the post. If you have done anything similar I would appreciate it if you could post any relevant JS code snippet.
    Thanks again,
    George

Maybe you are looking for