Conditional Sum and look at next record

First off, here is an example XML structure
<DATASET>
<DATASET_ROW>
<DEPARTMENT>1</DEPARTMENT>
<FEE>30</FEE>
<DIVISION>Displayed Title</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>1</DEPARTMENT>
<FEE>20</FEE>
<DIVISION>Displayed Title2</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>1</DEPARTMENT>
<FEE>40</FEE>
<DIVISION>Displayed Title3</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>2</DEPARTMENT>
<FEE>30</FEE>
<DIVISION>Displayed Title 5</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>2</DEPARTMENT>
<FEE>80</FEE>
<DIVISION>Displayed Title 6</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>3</DEPARTMENT>
<FEE>90</FEE>
<DIVISION>Displayed Title 7</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>3</DEPARTMENT>
<FEE>90</FEE>
<DIVISION>Displayed Title 8</DIVISION>
</DATASET_ROW>
<DATASET_ROW>
<DEPARTMENT>4</DEPARTMENT>
<FEE>30</FEE>
<DIVISION>Displayed Title 9</DIVISION>
</DATASET_ROW>
</DATASET>
Is there any way to get a sum of a field grouped by two different fields? Example in my RTF I have a repeating group based on DIVISION which inserts section breaks. Using the example I have posted here what I have in my RTF template is a sum of FEE (assume there are multiple records for DIVISION though only 1 is shown here) that displays on every page for the current group. Each DIVISION is printed on its own page. However, at the end of each DEPARTMENT, I also need to print a summary total of the sum of FEE over all records for that DEPARTMENT on the same page as the last page of the last DIVISION.
So far, I have been able to get it to do the subtotals for each DEPARTMENT as they are within the scope of my loop. The tricky part I am unsure of how best to go about doing is getting and displaying the conditional grand total. My initial idea was to use a variable and do it manually in my template but then I relaized I did not know how to find out if the next record was the first record in the next Department or not. In this case, I am hoping to stick within the realm of using straight SQL Query as my datasource because its already done. The other option I considered was nested loops and a data template but then I realized that I wasn't too sure about manually inserting the section breaks.
Any thoughts?

Yes, you can do that,
Pass me the template and XML :)
<?if:position() = last()?>
Last Record
<? end if ?>
then display the sub-total for department at the last division.
This link , gives you idea of , how to display at the last
http://blogs.oracle.com/xmlpublisher/2008/08/continued.html
Use
xdofo:inline-total display-condition="last"

Similar Messages

  • Update and move to next record

    Sorry if this is a simple question.
    I have a form that links to an access database. The page
    calls the fields and there is no problem.
    I want to be able to have users check the database
    information, and make any changes and then update and move to the
    next record.
    In the update button wizard it asks for a page to go to once
    updated - I just need it to move forward.
    Thanks for any help.

    Hi,
    I am not clear what you said. But I assume you mean to say:
    Right after comming in your if statement you want to update the record first and then you need the validation?? If this is right then you have to move the validation just after the update statement and then print a message just before "END IF".
    HTH
    Ghulam Mustafa Butt

  • Jump to next record when current record blocked

    Dear all,
    I have a problem with my oracle forms on the trigger WHEN-VALIDATE-ITEM.
    i used that trigger to validate records...if i have a record status "sealed" i want that record wont show up.
    here is my script:
    if :documents.court_case_number is not null then
              case_id:=court_admin.case_read_pck.CcntoCasId(:documents.court_case_number);
              select sealed into cs_seal from cases where id=case_id;
              if cs_seal='D' then
                   message('court case: '||case_id||' status seal: '||cs_seal); <-- if status "D" mean : sealed >> i want to just skip that record and jump to next record, i need help the script for this stage
              else
                   return;
              end if;
         end if;
    thank you

    Hadi Wijaya wrote:
    Dear all,
    I have a problem with my oracle forms on the trigger WHEN-VALIDATE-ITEM.
    i used that trigger to validate records...if i have a record status "sealed" i want that record wont show up.
    here is my script:
    if :documents.court_case_number is not null then
              case_id:=court_admin.case_read_pck.CcntoCasId(:documents.court_case_number);
              select sealed into cs_seal from cases where id=case_id;
              if cs_seal='D' then
                   message('court case: '||case_id||' status seal: '||cs_seal); <-- if status "D" mean : sealed >> i want to just skip that record and jump to next record, i need help the script for this stage
              else
                   return;
              end if;
         end if;
    thank youDefine Skip!! When?? during navigation, Query??
    You are using WHEN-VALIDATE-ITEM trigger to validate records????
    If you want the records that are "sealed" to be excluded from your query, you can set the block's either DEFAULT_WHERE or ONETIME_WHERE clause programatically using SET_BLOCK_PROPERTY.
    Explain your requirements more clearly so we can help you.
    Tony

  • Standard Report with Condition Type and Condition Records

    Hello to all,
    Is there any standard report available in which Condition Type and Condition values are displayed in either column or row format? The selection criteria can be either Quotation, Contract, Sales Order, Delivery, Invoice or Billing. Thanks anyways...

    Hi Huzefa,
      Pls check the relevant table where the condition records are stored. then do a query with  that condition table and KONP. say for eg: condn type ZINV,ZMRP gets stored in condition table A821, then combine A821 and KONP, u can input condition type and get the values........................
    go to vk13, display and click on layout, u will able to see the condition table.
    Rgds,
    Anitha J

  • My code not give me result and error for move to next record please see

    hi master
    sir i import this file also
    import javax.faces.event.ValueChangeEvent;
    then my error remove
    i am use this code in button event
    getMfatableDataProvider().cursorNext();
    form1.discardSubmittedValues("virtualForm1");
    and my textField is bounded with data provider table field
    please give me idea how i show next rocord in page when user press button
    thank's
    aamir

    thank for reply
    sir your help very usefull for my but when i press F10 then system show massage do you want to save change the record
    sir how i avoid that window and directly move to next record
    please give me idea
    thanking you
    aamir

  • How to fetch n records at a time from a FM and then fetch next n records

    I have a report program which is calling a function module . This function module returns all the records from a table. As the table has millions of records, it cant be returned at a time. How can we return N records from a function module and then return Next n records .The Function module and the report program are in different system .
    Thanks in Advance.

    Use open cursor and fetch cursor.
    Check the program as in SAP Help.
    DATA: BEGIN OF count_line,
            carrid TYPE spfli-carrid,
            count  TYPE i,
          END OF count_line,
          spfli_tab TYPE TABLE OF spfli.
    DATA: dbcur1 TYPE cursor,
          dbcur2 TYPE cursor.
    OPEN CURSOR dbcur1 FOR
      SELECT carrid count(*) AS count
             FROM spfli
             GROUP BY carrid
             ORDER BY carrid.
    OPEN CURSOR dbcur2 FOR
      SELECT *
             FROM spfli
             ORDER BY carrid.
    DO.
      FETCH NEXT CURSOR dbcur1 INTO count_line.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      FETCH NEXT CURSOR dbcur2
        INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
    ENDDO.
    CLOSE CURSOR: dbcur1,
                  dbcur2.
    Regards
    Kannaiah

  • Previous and next records in a table

    Let's say I have a table where I have
    item name sequence customer number
    I want to select these three fields where name = 'INSPECTION', but I'd also like to grab the record prior to this and the record after this, regardless of the name content. I need to do it for each customer number.
    Is it possible for a novice like me to do?
    Thank you

    What is "next record" and "previous record" for you in this context? A database table doesn't have records in any specific order. They have an arbitrary order.
    If for you, the records have the sequence as an ordering information, then you could use LAG and LEAD functions.

  • Trap error within loop and process next record

    Hi,
    I am processing each record inside a loop. Now if any exception occurs processing with a single record within loop I want to continue with the next record with proper error message in the log.
    How to achieve the above scenario? Shall I create a savepoint and whenever any error occurs inside the loop I will rollback to that savepoint. Once it is done shall it process the next record automatically?
    Thanks in advance for your reply.
    Thanks,
    Mrinmoy

    Relational databases are about sets.
    They are not about files and records
    Processing records in a loop will make your code slow, and you should avoid using this strategy.
    That said
    Simply enclose the code in it's own begin end block.
    beginn
    <your code>
    exception
    when <your exception> then
    <process the exception not reraising it>
    end;
    No savepoints required.
    Sybrand Bakker
    Senior Oracle DBA

  • Previous and Next Record

    Is there any additional code needed to replicate the functionality of the previous and next record buttons in the standard toolbar other than the built-ins that are provided? I'm getting some weird results by just using the built-ins. Thanks!

    Well, to give you and example, when I query the first record and then press the button that uses the previous_record built-in I get the message: at first record (same as the toolbar button). However, when I press the next record button, I'll eventually get the message: field must be entered (whereas, the toolbar button will bring up the message: record must be entered or deleted first). I was wondering why the next_record built-in would bring up a different message, and how to get my button to function the same way as the one in the toolbar.

  • How can I modify one column of current and next record depending of some criteria?

    Having DDL
    CREATE TABLE #ServiceChange(
    [ID] [int] identity(1,1),
    [SHCOMP] [char](2) NOT NULL,
    [SHCRTD] [numeric](8, 0) NOT NULL,
    [SHCUST] [numeric](7, 0) NOT NULL,
    [SHDESC] [char](35) NOT NULL,
    [SHTYPE] [char](1) NOT NULL,
    [SHAMT] [numeric](9, 2) NOT NULL,
    [CBLNAM] [char](30) NOT NULL,
    [GROUPID] [char](2) NULL
    And original and desire data in below link
    https://www.dropbox.com/sh/bpapxquaae9aa13/AADnan31ZASublDjN7sa2Vvza
    I would like to know how can I modify one column of current and next record depending of some criteria using SQL2012?
    The criteria is:
    Type should always flow F->T
    if current abs(amount)> next abs(amount) then groupid = 'PD'
    if current abs(amount)< next abs(amount) then groupid = 'PI'
    there is no case when those amounts will be equals
    where current(custid) = next(custid) and current(service) = next(service) and groupid is null
    Any help will be really apreciated.
    Thank you

    I tried that and got this error
    'LAG' is not a recognized built-in function name.
    You said you were using SQL 2012, but apparently you are not. The LAG function was added in SQL 2012. This solution works on SQL 2005 and SQL 2008:
    ; WITH numbering AS (
       SELECT groupid,
              rowno = row_number()  OVER (PARTITION BY custid, service ORDER BY date, id)
       FROM   #ServiceChange
    ), CTE AS (
       SELECT a.groupid,
              CASE WHEN abs(a.amount) < abs(b.amount) THEN 'PD'
                   WHEN abs(a.amount) > abs(b.amount) THEN 'PI'
              END AS newgroupid
       FROM  numbering a
       JOIN  numbering b ON b.custid  = a.custid
                        AND b.service = a.service
                        AND b.rowno   = a.rowno - 1
    UPDATE CTE
    SET   groupid = newgroupid
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Navigate previous record,next record by entering key-up and key-down

    Hi ,
    JDeveloper11g_
    I am trying to solve of how to navigate previous record,next record by entering key-up and key-down in ADF Table.
    If any of you have this solution by JScript of Backing Bean please help me.
    Thanks
    zakir
    ===

    Hi zakir,
    I hope I understood your requirements correctly. You have an editable ADF table. You would like to use the up/down arrow keys to move from one row to the next/prev row of the same column. Since the Tab key moves the cursor to the right and Shift+Tab moves it to the left, now you want to implement the same thing but just up and down, correct? If so, try this.
    /** Javascript **/
    function detectKey(evt) {
        var inputText = evt.getSource();
        var id = inputText.getClientId();
        var start2 = id.indexOf(":") + 1;
        var end2 = id.lastIndexOf(":");
        var numValue = parseInt(id.substring(start2, end2));
        var evt2 = evt.getNativeEvent();
        arrows=((evt2.which)||(evt2.keyCode));
        switch(arrows) {
            // Up arrow
            case 38:
            numValue = numValue - 1;
            break;
            // Down arrow
            case 40:
            numValue = numValue + 1;
            break;
        var newStr = id.replace(/:\d:/, ':' + numValue + ':');
        var comp = AdfPage.PAGE.findComponent(newStr);
        if (comp != undefined) {
            comp.focus();
    /** Jspx. (Place a client listener on each inputText in the ADF table) **/
    <af:column .....>
      <af:inputText value="#{row.bindings.price.inputValue}" .....>
        <af:clientListener type="keyDown" method="detectKey"/>
      </af:inputText>
    </af:column>With this, you get to move Up/Right/Down/Left in the editable ADF table without using the mouse.
    References:
    http://thepeninsulasedge.com/blog/?cat=29
    af:clientListener attributes and methodes of event object in java script
    Regards,
    Chan Kelwin

  • I want to start using the creative cloud programs but it has forced me to "start a trial" and looks like I need a redemption code to "license" the products on my computer for the next year. Where do I find or get this redemption code?

    I want to start using the creative cloud programs but it has forced me to "start a trial" and looks like I need a redemption code to "license" the products on my computer for the next year. Where do I find or get this redemption code?

    If you bought your subscription direct from Adobe, you should not need any codes, only your Adobe ID and password
    -Cloud programs do not use serial numbers... you log in to your paid Cloud account to download & install & activate... you MAY need to log out of the Cloud and restart your computer and log back in to the Cloud for things to work
    -Sign in help http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html
    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html
    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html
    -Cloud Getting Started https://helpx.adobe.com/creative-cloud.html
    -Install, update or UNinstall, and launch after installing
    If you bought your subscription from some other vendor, ask that vendor for help
    -Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

  • SUM and count next to each other

    SUM and count next to each other
    I would like to have the measurements SUM and COUNT cells being next to each other.
    As a default it shows up like this:
    .......SUM............. COUNT
    ......RegionA RegionB RegionA RegionB
    2000..... $..... $..... nn..... nn
    2001..... $..... $..... nn..... nn
    2002..... $..... $..... nn..... nn
    Can I change this somehow to:
    ......RegionA.....RegionB
    ......SUM COUNT ...SUM COUNT
    2000...$....nn......$... nn
    2001...$....nn......$... nn
    2002...$....nn......$... nn
    thnx
    Endre

    Select your axis "Region" and move it over (i.e. on top of) your data points (SUM, COUNT, etc.).

  • HT201269 Have new iPhone 5s and older iPad ( looking to buy new iPad ) question for both is should I hook them up to mu computer and back up the computer on each devise and sink and than the next one.  The second question is should I do the I pad first ca

    Have new iPhone 5s and older iPad ( looking to buy new iPad ) question for both is should I hook them up to y computer and back up the computer on each devise and sink and than the next one.  The second question is should I do the I pad first cause it has photos in my email that have not been downloaded and it is one of or is the first model

    No it's not stealing. They have an allowance that you can share with so many computers/devices. You'll have to authorize her computer to play/use anything bought on your acct. You can do this under the Store menu at top when iTunes is open on her computer.
    As far as getting it all on her computer....I think but I am not sure (because I don't use the feature) but I think if you turn on Home Sharing in iTunes it may copy the music to her computer. I don't know maybe it just streams it. If nothing else you can sign into your acct on her computer and download it all to her computer from the cloud. Not sure exactly how to go about that, I haven't had to do that yet. I wonder if once you authorize her computer and then set it up for automatic downloads (under Edit>Preferences>Store) if everything would download. Sorry I'm not much help on that.

  • Suppressing and aligning next record

    Hi
    I'm in a situation where my report needs to suppress certain headers and detail field based on a parameter chosen. I am able to suppress them accordingly but how do i make the space aligned with the next column header and detail field so that there aren't any gaps. I only wish to have the suppressed fields appear based on parameter i chose from the main report otherwise not appear and also the next column headers gets aligned accordingly.
    Any ideas guys?
    thanks

    Insert the txt object into ur report detail section.Increase the size of text box.
    Add the fileds you want to display into text box.
    Right click on text box.
    go to format text -->CommonTab.
    check chekbox ie.. Supress Embedded field blank lines.
    Click ok
    Now refresh ur report.
    the space that came due to supressing of records is removed,
    Thanks,
    Neetu

Maybe you are looking for