[10g/8i] Need help calculating a hierarchical total

Hi all...
I am trying to determine the total quantity of each unique part number in a bill of materials (big list of parts that go into a final product). The total needs to take into account the quantity of the parent parts--what I mean by this is, if you have final product 'A' that takes 1 x part 'B' and 2 x part 'C', and part 'C' takes 1 x part 'B' and 3 x part 'D' then the totals of all unique parts in product 'A' would be: 3 x B, 2 x C, 6 x D.
It would be nice if this query ran under 8i, but if it's much more complex than the equivalent query for 10g, don't worry about making it work for 8i.
Here is some sample data:
CREATE TABLE     BOM
(     part_nbr     CHAR(25)
,     bill_seq     VARCHAR2(140)
,     bill_level     NUMBER
,     parent_part     CHAR(25)
,     line_nbr     NUMBER(5)
,     child_part     CHAR(25)
,     qty_per          NUMBER(9,5)
INSERT INTO BOM VALUES ('12345-1','   10019970303',1,'12345-1',100,'12345-76',1);
INSERT INTO BOM VALUES ('12345-1','   20019970303',1,'12345-1',200,'12345-272',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303',1,'12345-1',300,'12345-267',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   10019830901',2,'12345-267',100,'12345-268',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   10019830901   10019830901',3,'12345-268',100,'12345-268-1',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   20019830901',2,'12345-267',200,'12345-269',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   30019830901',2,'12345-267',300,'12345-270',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   40019830901',2,'12345-267',400,'HARDWARE-4',1);
INSERT INTO BOM VALUES ('12345-1','   30019970303   50019830901',2,'12345-267',500,'HARDWARE-5',1);
INSERT INTO BOM VALUES ('12345-1','   40019970303',1,'12345-1',400,'HARDWARE-6',2);
INSERT INTO BOM VALUES ('12345-1','   50019990824',1,'12345-1',500,'A12345-475',1);
INSERT INTO BOM VALUES ('12345-1','   60019970303',1,'12345-1',600,'HARDWARE-7',1);
INSERT INTO BOM VALUES ('12345-1','   70019990824',1,'12345-1',700,'A12345-476',1);
INSERT INTO BOM VALUES ('12345-1','   70019990824   10019990824',2,'A12345-476',100,'A12345-476-1',1);
INSERT INTO BOM VALUES ('12345-1','   80019970303',1,'12345-1',800,'12345-222',1);
INSERT INTO BOM VALUES ('12345-1','   90019970303',1,'12345-1',900,'12345-157',1);
INSERT INTO BOM VALUES ('12345-1','   90019970303   10119980922',2,'12345-157',101,'RAW-2',6.2);
INSERT INTO BOM VALUES ('12345-1','  100019990215',1,'12345-1',1000,'A12345-494',2);
INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216',2,'A12345-494',100,'A12345-486',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10019000101',3,'A12345-486',100,'12345-158',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10019000101   10119960118',4,'12345-158',101,'RAW-3',6.75);
INSERT INTO BOM VALUES ('12345-1','  100019990215   10019990216   10120000317',3,'A12345-486',101,'RAW-3',6.75);
INSERT INTO BOM VALUES ('12345-1','  100019990215   20019970303',2,'A12345-494',200,'12345-155',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   30019970303',2,'A12345-494',300,'12345-266',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   40019990215',2,'A12345-494',400,'A12345-493',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   50019970303',2,'A12345-494',500,'HARDWARE-8',1);
INSERT INTO BOM VALUES ('12345-1','  100019990215   60019970303',2,'A12345-494',600,'HARDWARE-9',1);
INSERT INTO BOM VALUES ('12345-1','  110019970303',1,'12345-1',1100,'HARDWARE-10',1);
INSERT INTO BOM VALUES ('12345-1','  120019970303',1,'12345-1',1200,'HARDWARE-9',1);
INSERT INTO BOM VALUES ('12345-1','  130019970303',1,'12345-1',1300,'HARDWARE-11',2);
INSERT INTO BOM VALUES ('12345-1','  140020000228',1,'12345-1',1400,'HARDWARE-12',1);
INSERT INTO BOM VALUES ('12345-1','  150020000228',1,'12345-1',1500,'HARDWARE-13',2);
INSERT INTO BOM VALUES ('12345-1','  160020000228',1,'12345-1',1600,'HARDWARE-14',2);
INSERT INTO BOM VALUES ('12345-1','  170020000228',1,'12345-1',1700,'12345-250',8);
INSERT INTO BOM VALUES ('12345-1','  180020000228',1,'12345-1',1800,'FLUID1',0.00001);
INSERT INTO BOM VALUES ('ABC-123','   10019000101',1,'ABC-123',100,'ABC-123-1',1);
INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101',2,'ABC-123-1',100,'AYZ-1',2);
INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   10019000101',3,'AYZ-1',100,'AYZ-2',1);
INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   10019000101   10019000101',4,'AYZ-2',100,'RAW-1',1);
INSERT INTO BOM VALUES ('ABC-123','   10019000101   10019000101   20019000101',3,'AYZ-1',200,'HARDWARE-1',10);
INSERT INTO BOM VALUES ('ABC-123','   20020001110',1,'ABC-123',200,'HARDWARE-2',15);
INSERT INTO BOM VALUES ('ABC-123','   30020001121',1,'ABC-123',300,'HARDWARE-1',26);
INSERT INTO BOM VALUES ('ABC-123','   40019000101',1,'ABC-123',400,'AYZ-25',1);
INSERT INTO BOM VALUES ('ABC-123','   50020001121',1,'ABC-123',500,'HARDWARE-3',5);Here are the results I expect (I don't care about the order, this is just the order I hand-calculated the results in):
PART_NBR    CHILD_PART  TOTAL_QTY  
ABC-123     ABC-123-1   1          
ABC-123     HARDWARE-1  46         
ABC-123     HARDWARE-2  15         
ABC-123     HARDWARE-3  5          
ABC-123     RAW-1       1          
ABC-123     AYZ-1       2          
ABC-123     AYZ-2       2          
ABC-123     AYZ-25      1          
12345-1     12345-155   1          
12345-1     12345-157   1          
12345-1     12345-158   2          
12345-1     12345-222   1          
12345-1     12345-250   8          
12345-1     12345-266   1          
12345-1     12345-267   1          
12345-1     12345-268   1          
12345-1     12345-268-1 1          
12345-1     12345-269   1          
12345-1     12345-270   1          
12345-1     12345-272   1          
12345-1     12345-76    1          
12345-1     A12345-475  1          
12345-1     A12345-476  1          
12345-1     A12345-476-11          
12345-1     A12345-486  2          
12345-1     A12345-493  1          
12345-1     A12345-494  2          
12345-1     FLUID1      0.00001    
12345-1     HARDWARE-10 1          
12345-1     HARDWARE-11 2          
12345-1     HARDWARE-12 1          
12345-1     HARDWARE-13 2          
12345-1     HARDWARE-14 2          
12345-1     HARDWARE-4  1          
12345-1     HARDWARE-5  1          
12345-1     HARDWARE-6  2          
12345-1     HARDWARE-7  1          
12345-1     HARDWARE-8  1          
12345-1     HARDWARE-9  2          
12345-1     RAW-2       6.2        
12345-1     RAW-3       27          Clearly this query:
SELECT     part_nbr
,     child_part
,     SUM(qty_per)
FROM     BOM
GROUP BY     part_nbr
,          child_part
ORDER BY     part_nbr
,          child_part
;will not give the desired results, as it doesn't take into account the quantity required of each child's parent, but I can't figure out how to do that.
The sample data I have provided represents data from a table or materialized view that is, roughly, the result of a hierarchical query of data in another table or three. If it's simpler to work off the tables on which this table is based, let me know, and I can put together some sample data from those tables.

Hi,
user11033437 wrote:
Hi all...
I am trying to determine the total quantity of each unique part number in a bill of materials (big list of parts that go into a final product). The total needs to take into account the quantity of the parent parts--what I mean by this is, if you have final product 'A' that takes 1 x part 'B' and 2 x part 'C', and part 'C' takes 1 x part 'B' and 3 x part 'D' then the totals of all unique parts in product 'A' would be: 3 x B, 2 x C, 6 x D.That's a very good explanation in general terms. No doubt, for you, applying that to the specific data is trivial, but most of us aren't as familiar with your application as you are. It would help a lot if you posted a similar explanation using specific ids from the sample data. For example, why do the desired results include:
PART_NBR    CHILD_PART  TOTAL_QTY  
ABC-123     HARDWARE-1  46     If someone explores the data enough, they might guess that the number 46 is the sum of 26 and 20=2*10, but it would sure save a lot of time if you, to whom this is second nature, could explain it.
It would be nice if this query ran under 8i, but if it's much more complex than the equivalent query for 10g, don't worry about making it work for 8i. Sorry, I don't know any simple way to do this in Oracle 8.1. The SYS_CONNECT_BY_PATH function, introduced in Oracle 9, is essential to the solution below.
Here is some sample data:
CREATE TABLE     BOM
INSERT INTO BOM VALUES ('ABC-123','   50020001121',1,'ABC-123',500,'HARDWARE-3',5);
Good job.
It looks like only about half of the columns have anything to do with this problem. Here's another place where sharing your knowlege ot he application could really help people. Don't post things that are irrelvant to the problem you're asking. If there's a sincere doubt, then say somthing like "I need part_nbr, bill_seq and bill_level in the output for my real problem. I don't think they have anything to do with getting the total qty, but I'm posting them just in case."
Here are the results I expect (I don't care about the order, this is just the order I hand-calculated the results in):
PART_NBR    CHILD_PART  TOTAL_QTY  
ABC-123     ABC-123-1   1          
ABC-123     HARDWARE-1  46    
12345-1     RAW-3       27          Clearly this query:
SELECT     part_nbr
,     child_part
,     SUM(qty_per)
FROM     BOM
GROUP BY     part_nbr
,          child_part
ORDER BY     part_nbr
,          child_part
;will not give the desired results, as it doesn't take into account the quantity required of each child's parent, but I can't figure out how to do that.Thanks for posting the query. Even though it doesn;t work, it helped me understand what you wanted, and saved me some time.
The sample data I have provided represents data from a table or materialized view that is, roughly, the result of a hierarchical query of data in another table or three. If it's simpler to work off the tables on which this table is based, let me know, and I can put together some sample data from those tables.I don't know if it would be any simpler. It might be more efficient, but I don't know how much that matters to you. Try the solution below. If it takes, say, 60 seconds, is it worthwhile trying to see if we can get it to run in 15?
This seems to get the right results:
SELECT     part_nbr
,     child_part
,     SUM (eval_number ('1' || SYS_CONNECT_BY_PATH (qty_per, '*')))     AS total_qty
FROM     bom
START WITH     parent_part     = part_nbr
CONNECT BY     parent_part     = PRIOR child_part
GROUP BY  part_nbr
,       child_part
ORDER BY  part_nbr
,       child_part
;Do some experiments, on variations of this query, if you don't understand what SYS_CONNECT_BY_PATH is doing. You'll see that it's returning a string, such as '*2*1*1*6.75' that reflects the quantities needed at each level of the process. To actually do the multiplication, and get a number, I used this function:
CREATE OR REPLACE FUNCTION     eval_number
(     in_txt     IN     VARCHAR2
,     err_val     IN     NUMBER     DEFAULT     NULL
RETURN     NUMBER
IS
--          **   e v a l _ n u m b e r   **
--          eval_number attempts to evaluate in_txt as a NUMBER,
--          returning that value.  If in_txt can not be interpreted,
--          then err_val is returned.
     result_txt     VARCHAR2 (100);
     return_val     NUMBER;
BEGIN
     EXECUTE IMMEDIATE     'SELECT '
               ||     in_txt
               ||     ' FROM dual'
               INTO     return_val;
--     dbms_output.put_line (result_val || ' = result_txt in eval_number');
     RETURN     return_val;
EXCEPTION
     WHEN OTHERS
     THEN
--          dbms_output.put_line (SQLERRM || ' = error in eval_number');
          RETURN     err_val;
END     eval_number
SHOW ERRORSI hate using "WHEN OTHERS" like this. Perhaps someone can suggest a reasonable set of specific errors that could be caught in the EXCEPTION section.

Similar Messages

  • Need help to sum up total amount in at end of.....endat!!! Please help

    Hi,
    There is one program need to calculat the SUB-TOTAL AMOUNT FOR SAME DOCUMENT NUMBER.
    Means: Need to sumup betrg for the same belnr.
    QUESTION:
    How can I write the sorce cord In AT END OF...ENDAT.
    TO SUMUP THE AMOUNT FOR SAME DOCUMENT NUMBER.
    Please help!!
    Thanks.
    Here is the sourc code.
    DATA: BEGIN OF t OCCURS 0,
            bukrs   LIKE knb1-bukrs,
    *<<<<< CR01
            zuonr   Like bsid-zuonr,                        "sort key  "CR01
    *>>>>> CR01
            belnr   LIKE bsid-belnr,
            kunnr   LIKE kna1-kunnr,
            bldat   LIKE bsid-bldat,
            budat   LIKE bsid-budat,
            netdt   LIKE bsega-netdt,
            waers   LIKE bsid-waers,
            wrbtr   LIKE bsid-wrbtr,
            shkzg   LIKE bsid-shkzg,
            xblnr   LIKE bsid-xblnr,                            "WD041005a
            sgtxt   LIKE bsid-sgtxt,
            dmbtr   LIKE bsid-dmbtr,
          END OF t.
    Description of Interface-record RECON
    DATA: BEGIN OF s,
            belnr(10),                     " document number
    *<<<< CR01 STRAT ADD ZUONR
            zuonr(10),                     "sort key  " CR01
    *>>>> CR01 END ADD ZUONR
            filler1(1),
          KUNNR(5),                      " customer no."WD290705a
            kunnr LIKE kna1-kunnr,         " customer no."WD290705a
            filler2(1),
            bldat(10),                     " date
            filler3(1),
            budat(10),
            filler4(1),
            netdt(10),                     " due date for payment
            filler5(1),
            betrg(14),                     " amount
            filler6(1),
            waers(3),                      " currency
            filler7(1),                    " document field - blank
            compcode(4),                   " company-code         "fw070905
            filler8(1),                    " comment - blank
            sgtxt(50),                     " Text             "INS MG020207
            filler9(1),
            kmmnt(30),
            filler10(1),
            vbeln(12) ,
            filler11(1),
            xblnr(16),                     "WD041005a hier Referenznr rein
            filler12(1),
            lifn2(11),
            filler13(1),                   " remark - blank
            dmbtr(14),
            filler14(1),
            twaer(3),
          END OF s.
    DATA: BEGIN OF outtab OCCURS 1000,
                s LIKE s,
          END OF outtab.
    *<<<<< INS MG020207
    TYPES: BEGIN OF ty_outalv,
             belnr(10),                     " document number
    *<<<< CR01 START ADD ZUONR
             zuonr,                         " sort key  " CR01
    *>>>>CR01 END ADD AUONR
             kunnr LIKE kna1-kunnr,         " customer no."WD290705a
             bldat(10),                     " date
             budat(10),                     " posting date
             netdt(10),                     " due date for payment
             betrg(14),                     " amount
             waers(3),                      " currency
             compcode(4),                   " company-code         "fw070905
             sgtxt(30),                     " comment
             kmmnt(30),                     " comment
             vbeln(12),                     " delivery number
             xblnr(16),                     "WD041005a hier Referenznr rein
             lifn2(11),                     " customer number
             dmbtr(14),
             twaer(3),                     " currency company code
           END OF ty_outalv.
    DATA: gt_outalv TYPE STANDARD TABLE OF ty_outalv.
    DATA: gs_outalv TYPE ty_outalv.
    *>>>>> INS MG020207
    DATA: l_date TYPE sy-datum.
    DATA: g_date TYPE sy-datum.
    DATA: g_budat TYPE bsik-budat.
    *<<<< CR01 START   ADD DATA STATEMENT
    DATA: wk_belnr LIKE bsid-zuonr,
          wk_x_belnr LIKE bsid-zuonr,
          ZUONR LIKE BSID-ZUONR,
          WRBTR LIKE BSID-WRBTR,
          WK_ZUONR LIKE BSID-ZUONR,
          WK_WRBTR LIKE BSID-WRBTR.
    *>>>> CR01 END  ADD DATA STATEMENT
    DATA: l_it_bsik TYPE STANDARD TABLE OF bsik.               "INS MG050706
    DATA: l_wa_bsik TYPE bsik.                                 "INS MG050706
    TYPE-POOLS: slis.                                          "INS MG020207
    DATA:                                                      "INS MG020207
    gt_fieldcat TYPE slis_t_fieldcat_alv,                     "INS MG020207
    gs_layout   TYPE slis_layout_alv,                         "INS MG020207
    gs_fieldcat TYPE slis_fieldcat_alv.                       "INS MG020207
    END-OF-SELECTION.
      SORT t.
      LOOP AT t.
        AT NEW bukrs.
          CLEAR anz_dl.
          CLEAR htext-anzahl.
          CLEAR htext-datei.
          htext-text1 = ' records writen in file '.
          CLEAR p_pfad.
          CONCATENATE
              i_pfad
              'CU_CC'
              t-bukrs
              sy-datum+6(2)
              sy-datum+4(2)
              sy-datum(4)
              sy-uzeit
              '.txt'
         INTO p_pfad.
          CLEAR outtab.
          REFRESH outtab.
          REFRESH: gt_outalv.                                  "INS MG020207
        ENDAT.
       IF t-shkzg = 'H'.
         h_betrg  = t-wrbtr * -1.
       ELSE.
        h_betrg  = t-wrbtr.
        h_dmbtr  = t-dmbtr.
       ENDIF.
        s-filler1 = s-filler2 = s-filler3 = s-filler4 = s-filler5 = ';'.
        s-filler6 = s-filler7 = s-filler8 = ';'.
        s-filler9 = s-filler10 = s-filler11 = s-filler12 = s-filler13 = ';'.
        s-filler14 = ';'.
        s-belnr = t-belnr.
        IF t-xblnr NE space.                                    "WD041005a
          s-xblnr      = t-xblnr.                               "WD041005a
        ELSE.                                                   "WD041005a
          s-xblnr      = t-belnr.                               "WD041005a
        ENDIF.                                                  "WD041005a
        WHILE s-xblnr(1) EQ '0'.                            "INS MG130606
          SHIFT s-xblnr LEFT.                               "INS MG130606
        ENDWHILE.                                            "INS MG130606
        WRITE t-kunnr TO s-kunnr NO-ZERO.
        s-lifn2 = s-kunnr.
        shift s-lifn2 RIGHT.
        s-lifn2(1) = 'R'.
      S-KUNNR = T-KUNNR+5(5).
        s-bldat+2(1) = '/'.
        s-bldat+5(1) = '/'.
        s-bldat0(2) = t-bldat4(2).
        s-bldat3(2) = t-bldat6(2).
        s-bldat6(4) = t-bldat0(4).
        s-budat+2(1) = '/'.
        s-budat+5(1) = '/'.
        s-budat0(2) = t-budat4(2).
        s-budat3(2) = t-budat6(2).
        s-budat6(4) = t-budat0(4).
        s-netdt+2(1) = '/'.
        s-netdt+5(1) = '/'.
        s-netdt0(2) = t-netdt4(2).
        s-netdt3(2) = t-netdt6(2).
        s-netdt6(4) = t-netdt0(4).
        s-waers      = t-waers.
        s-dmbtr      = t-dmbtr.
        s-sgtxt      = t-sgtxt.
        CLEAR s-twaer.
        SELECT SINGLE waers INTO s-twaer
                            FROM t001
                            WHERE bukrs = t-bukrs.
        IF h_betrg < 0.
          hs_betrg+0(1) = '-'.
        ELSE.
          hs_betrg+0(1) = ' '.
        ENDIF.
        WRITE h_betrg CURRENCY t-waers TO hs_betrg+1 NO-GROUPING
                                                        NO-SIGN
                                                        LEFT-JUSTIFIED.
        REPLACE ',' WITH '.' INTO hs_betrg.
        WRITE hs_betrg TO s-betrg.
        IF h_dmbtr < 0.
          hs_betrg+0(1) = '-'.
        ELSE.
          hs_betrg+0(1) = ' '.
        ENDIF.
        WRITE h_dmbtr CURRENCY t-waers TO hs_betrg+1 NO-GROUPING
                                                        NO-SIGN
                                                        LEFT-JUSTIFIED.
        REPLACE ',' WITH '.' INTO hs_betrg.
        WRITE hs_betrg TO s-dmbtr.
        s-compcode   = t-bukrs.                                 "fw070905
        IF p_downl = 'X'.
          MOVE s TO outtab-s.
          APPEND outtab.
          ADD 1 TO anz_dl.
        ENDIF.
        gs_outalv-belnr = s-belnr.                             "INS MG020207
    *<<<< CR01 START ADD as_outalv-zuonr
        gs_outalv-zuonr = s-zuonr.                             "CR01
    *>>>> CR01 EDD   ADD as_outalv-zuonr
        gs_outalv-kunnr = s-kunnr.                             "INS MG020207
        gs_outalv-bldat = s-bldat.                             "INS MG020207
        gs_outalv-netdt = s-netdt.                             "INS MG020207
        gs_outalv-betrg = s-betrg.                             "INS MG020207
        gs_outalv-waers = s-waers.                             "INS MG020207
        gs_outalv-compcode = s-compcode.                       "INS MG020207
        gs_outalv-budat = s-budat.                             "INS MG020207
        gs_outalv-sgtxt = s-sgtxt.
        gs_outalv-kmmnt = s-kmmnt.
        gs_outalv-vbeln = s-vbeln.
        gs_outalv-xblnr = s-xblnr.
        gs_outalv-lifn2 = s-lifn2.
        gs_outalv-dmbtr = s-dmbtr.
        gs_outalv-twaer = s-twaer.
        APPEND gs_outalv TO gt_outalv.                         "INS MG020207
        AT END OF bukrs.
          WRITE anz_dl  TO htext-anzahl.
          WRITE p_pfad  TO htext-datei.
          CONDENSE htext.
          IF p_downl = 'X'.
            SKIP 2.
            WRITE: / htext.
            CALL FUNCTION 'GUI_DOWNLOAD'
              EXPORTING
                filename                = p_pfad
                filetype                = 'ASC'
              TABLES
                data_tab                = outtab
              EXCEPTIONS
                file_write_error        = 1
                no_batch                = 2
                gui_refuse_filetransfer = 3
                invalid_type            = 4
                no_authority            = 5
                unknown_error           = 6
                header_not_allowed      = 7
                separator_not_allowed   = 8
                filesize_not_allowed    = 9
                header_too_long         = 10
                dp_error_create         = 11
                dp_error_send           = 12
                dp_error_write          = 13
                unknown_dp_error        = 14
                access_denied           = 15
                dp_out_of_memory        = 16
                disk_full               = 17
                dp_timeout              = 18
                file_not_found          = 19
                dataprovider_exception  = 20
                control_flush_error     = 21
                OTHERS                  = 22.
            IF sy-subrc <> 0.
             write: / 'Error creating File:', P_Pfad, sy-subrc.
              MESSAGE e405 WITH text-002 p_pfad.
            ENDIF.
          ENDIF.
    *<<<<< INS MG020207
          IF p_alvd EQ 'X'.
            PERFORM build_layout_data.
            CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
              EXPORTING
                i_callback_program     = sy-repid
                i_structure_name       = 'GT_OUTALV'
                is_layout              = gs_layout
                it_fieldcat            = gt_fieldcat[]
                i_callback_top_of_page = 'TOP-OF-PAGE'
              TABLES
                t_outtab               = gt_outalv.
          ENDIF.
    *>>>>> INS MG020207
    ENDAT.
      ENDLOOP.

    HI
    Have alook at below program
    *& Report  ZINTERNALTABLE
    REPORT  zinternaltable.
    TYPES:BEGIN OF itab,
          num TYPE i,
          name(10) TYPE c,
          amt type i,
          END OF itab.
    DATA : wa_itab TYPE itab,
           it_itab TYPE STANDARD TABLE OF itab.
    DATA : v_lines TYPE i.
    wa_itab-num = 1.
    wa_itab-name = 'nag'.
    wa_itab-amt = 1000.
    append wa_itab TO it_itab.
    wa_itab-num = 1.
    wa_itab-name = 'nag'.
    wa_itab-amt = 2000.
    append wa_itab TO it_itab.
    wa_itab-num = 1.
    wa_itab-name = 'nag'.
    wa_itab-amt = 1500.
    append wa_itab TO it_itab.
    wa_itab-num = 2.
    wa_itab-name = 'sri'.
    wa_itab-amt = 500.
    append wa_itab tO it_itab.
    wa_itab-num = 2.
    wa_itab-name = 'sri'.
    wa_itab-amt = 600.
    append wa_itab TO it_itab.
    wa_itab-num = 2.
    wa_itab-name = 'sri'.
    wa_itab-amt = 700.
    append wa_itab TO it_itab.
    wa_itab-num = 3.
    wa_itab-name = 'ganesh'.
    wa_itab-amt = 1200.
    append wa_itab TO it_itab.
    wa_itab-num = 3.
    wa_itab-name = 'ganesh'.
    wa_itab-amt = 1300.
    append wa_itab TO it_itab.
    wa_itab-num = 3.
    wa_itab-name = 'ganesh'.
    wa_itab-amt = 1400.
    append wa_itab TO it_itab.
    wa_itab-num = 4.
    wa_itab-name = 'suresh'.
    wa_itab-amt = 900.
    append wa_itab TO it_itab.
    wa_itab-num = 4.
    wa_itab-name = 'suresh'.
    wa_itab-amt = 300.
    append wa_itab TO it_itab.
    sort it_itab.
    LOOP AT it_itab INTO wa_itab.
    at first.
    write :/ 'details of sales order:'.
    uline.
    endat.
    at new num.
    write :/ 'serial num:', wa_itab-num.
    uline.
    endat.
    WRITE :/ wa_itab-num , wa_itab-name , wa_itab-amt.
    at end of num.
    uline.
    sum.
    write :/ 'total amount:',wa_itab-amt.
    uline.
    endat.
    at last.
    sum.
    uline.
    write:/ 'grand total:',wa_itab-amt.
    endat.
    ENDLOOP.
    describe table it_itab lines  v_lines.
    WRITE:/'no of records :', v_lines.
    Regards
    Nagesh.Paruchuri

  • [Urgent] Need help calculating difference between two dates

    I'm trying to write a code to display the current day and time, then accept two dates from the user and display the difference between the two dates. To display the current date and time, I've used the SimpleDateFormatter library but I'm having difficulty calculating the difference between two dates. Could someone please help me with this?
    Below is my code so far
    import java.util.Date;
    import java.util.Scanner;
    import java.text.SimpleDateFormat;
    public class DateFormatter {
         public void displayNow()
              Date todaysDate = new Date();
              SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
              String formattedDate = formatter.format(todaysDate);
              System.out.println("Today's date and time is: "+formattedDate);
         public void calculateDifference(Date startDate, Date endDate)
              /* This is whre i need help! */
         public static void main(String[] args)
              DateFormatter df = new DateFormatter();
              Scanner sc = new Scanner(System.in);
              df.displayNow();
              System.out.println("Please enter a date: ");
              String date1 = sc.next();
              System.out.println("Please enter another date: ");
              String date2 = sc.next();
    }The methods displayNow() and calculateDifference(Date startDate, Date endDate) are essential and cannot be skipped out.

    tarahmarie101 wrote:
    Dude. I've tried doing assignments under pressure, and it doesn't work. Here's a piece of free advice. Start earlier next time, don't put "urgent" in the title of your post b/c it just pisses people off around here--and is a sure sign of an overdue homework assignment which no one around here likes helping with, and try to ask intelligent questions--don't just say "Help me!"
    Of course, it takes some time to learn what the intelligent questions are. You have my sympathy. Try asking questions about how to do a particular task, instead of asking people to tell you what to do. It starts to get easier after a while.
    actually dude i started on this on monday.. but there were so many other stuff to do along with this.. and i did try referring up the Calendar utility but it was a bit confusing actually.. it was only after that did i come to this forum.. nor am i very good at Java.. anyhoo thanks for your sympathies :P

  • Need help calculating total from flowable rows

    I am trying like a mad man to figure out how to calculate a total field from fields that flow one after another.  I utilized the tutuorial on Adobe, but the process to enter the formcalc forumula does not work in my instance.  I can upload the file to anyone interested in helpting.
    Thanks!
    Mike

    FormCalc is a feature of LiveCycle Designer forms, please repost in their forums.

  • Need Help Calculating Business Days AND omitting Holidays...

    Post Author: dkotenoglou
    CA Forum: Formula
    Thanks to the people here I was able to get a nice formula to help me calculate the amount of business days between two days.//Crystal syntax
    Local DateTimeVar d1 := ;
    Local DateTimeVar d2 := ;
    DateDiff ("d", d1, d2) -
         DateDiff ("ww", d1, d2, crSaturday) - 
         DateDiff ("ww", d1, d2, crSunday) This works great.  I wanted to add the ability to omit US Holidays.  Now this is a straight Crystal Reports install without an SQL backend so I cannot use any formulas there.Is there a parameter? I can use to manually create a table of dates to omit?  The only reason I ask is that our company was closed during the holidays so my day reports are really high. I do not mind typing a long list of days manually (12/24/2007, 12/25/2007, etc) but I need to know how to best integrate that list into the formula.  

    Post Author: V361
    CA Forum: Formula
    If you have CR XI, there is another example as well, in the sample reports,  look at feature examples, custom functions.rpt   this code is from that example.
    Function cdDateAddSkipHolidays (nWorkingDays As Number, startDateTime As DateTime) As DateTime    'the result = startDateTime + nWorkingDays + nHolidays (including weekends)    'the algorithm below also works when nWorkingDays is negative
        Dim totalDays    'give a rough estimate for total days. For each 5 work days there are 7    'days. Also add in an extra 2 weekend days to account for a partial week.    totalDays = Fix(nWorkingDays * 7 / 5 + 1) + 2
        Dim iteratedDiff    iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)
        If (iteratedDiff >= nWorkingDays) Then        Do While iteratedDiff >= nWorkingDays            totalDays = totalDays - 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop        cdDateAddSkipHolidays = startDateTime + totalDays + 1    Else        Do While iteratedDiff < nWorkingDays            totalDays = totalDays + 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop         cdDateAddSkipHolidays = startDateTime + totalDays    End If
    End Function

  • Need Help Creating A Sub-Total Box On 3 Page Invoice

    I have a 3 page Invoice with Grand Total on the last page that already totals all three pages together. No Problem here.
    I copied & pasted a Sub-Total box from the Template Manager and attached it to the bottom of the first two invoice pages.
    The problem is, the Sub-Total amounts continue to add the other page amounts. It's like I have three Grand Total boxes instead of two individual Sub-Total boxes.
    Any help would be greatly appreciated!

    Sorry for the delay in getting back to you ..... I was looking for a sample that I could provide.
    The technique to use would be to get a list of all objects that are on the page that you want to create the subtotal on. Then with this reduced set of objects, search out the individual fields and add then together to make your total. In the example I have we created a function to do this and passed the object subtotal object itself to the function. The function then determines which page the object is on, gets all field objects from that page (in our case we are asking to add all fields called fldSavings), then cycles through each field and totals them and finally returns the sum back to the calling program. Hope this helps .... see the code below we call it in this way:
    scoScript.getPageTotals(this.name);
    Here is the function:
    function getPageTotals(objFld){
    var nPage = xfa.layout.absPage(objFld);
    var oFields = xfa.layout.pageContent(nPage , "field");
    var nFieldCount = oFields.length;
    var numFldTotals = 0;
    for (var nNodeCount = 0; nNodeCount < nFieldCount; nNodeCount++)
    if (oFields.item(nNodeCount).name == "fldSavings")
    numFldTotals = numFldTotals + oFields.item(nNodeCount).rawValue;
    return numFldTotals;

  • I need help calculating the "occupancy rate" of a lodge.

    Hello there. I have a spreadsheet that shows check in, check out times for guests in 5 units: unit 1, 2, 3, 4, & 7 (5 and 6 aren't being rented).
    I would like to have a chart that automatically displays the occupancy rate for each room as a guest is entered into the table. I'm not great at all with charts in numbers and another difficult part is creating formulars that detects the changes of a new month. So I've drawn a rough draft of what I'd like the chart to look like. Can anyone help me come up with a formula to make the chart display this?

    Hi Caleb,
    If I'm reading your table correctly, the unit numbers are i column C, In date in column E, Out date in column F and duration of stay in column G.
    For stays that do not cross from one month to another, a simple SUMIFS statement woud work to calculate the number of occupied days in a given month. As you've found, theough, the stays that begn in one month and end in another are a bit trickier.
    One way to resolve the issue is to use an auxiliary table which calculates the occuped days (for all units) using a separate column for each month, then a summary table to sum the monthly data for each unit.
    Here's an example, using random data over a two and a half month span.
    Note that the dates in the header row of Aux and Summary are actual Date and Time Values set to the first of each month, and formatted to show only the month and year. These are used in the calculations.
    The only formula in Bookings is =F-E in each cell of column G (Stay).
    Aux has two formulas:
    A2, and filled down: =Bookings :: C2
    This simpy copies the values from column C of Bookings to column A of Aux.
    B2, and filled down and right:
    =IF(AND(Bookings :: $E2>=B$1,Bookings :: $F2<EOMONTH(B$1,0)+1),Bookings :: $F2-Bookings :: $E2,IF(AND(Bookings :: $E2<B$1,Bookings :: $F2>B$1),Bookings :: $F2-B$1,IF(AND(Bookings :: $E2<=EOMONTH(B$1,0),Bookings :: $F2>EOMONTH(B$1,0)),EOMONTH(B$1,0)+1-Bookings :: $E2,"no")))
    Same formula, separated into sections:
    =
    IF(AND(Bookings :: $E2>=B$1,Bookings :: $F2<EOMONTH(B$1,0)+1),Bookings :: $F2-Bookings :: $E2,
    IF checks if the IN date AND the OUT Date are both in the month for this column. If so, the calculation is done and the formula is done; if not, control is passed to the next if:
    IF(AND(Bookings :: $E2<B$1,Bookings :: $F2>B$1),Bookings :: $F2-B$1,
    IF checks it the IN date is before the month for this column AND the OUT date is after the beginning of this month. If so,th calculaton is done and the formula is done; if not, contorl is passed to the thrid IF:
    IF(AND(Bookings :: $E2<=EOMONTH(B$1,0),Bookings :: $F2>EOMONTH(B$1,0)),EOMONTH(B$1,0)+1-Bookings :: $E2,
    IF checks if the IN Date is before the end of the month for this coumn AND the OUT date is after the end of the month. If so, the calculation is done; if not, the text blow is returned to the cell.
    "no")))
    This text was chosen to give me a visual indication of the result. In practice, I would replace it with the empty string ( "" ).
    Summary has a single formula:
    B2, and filled down and right:
    =IFERROR(DUR2DAYS(SUMIF(Aux :: $A,$A2,Aux :: B))/DAY(EOMONTH(B$1,0)),"")
    SUMIF sums the duatons of Stay for each unit in a specific month for each column.
    DUR2DAYS converts the duration to a number of days.
    DAY(EOMONTH(B$1,0) returns the number of days in the month whose date is in row 1.
    The first is divided by the second, and the result is formatted as percentage, with 0 decimal places.
    IFERROR traps the error that occurs when the source column on Aux contain only text values, and replaces the error message with the empty string.
    Regards,
    Barry

  • Error in installing oracel 10g ..need help

    hi,
    i have installed oracle 10g in windows vista and it was working fine.
    but wen i tried to install 9i it threw errors and 10 g also got corrupted.
    so i completely uninstalled 10g and tried to install new copy then it is throwing an error " cant continue installation as oracle serviceXE is already presesnt in your system.try to stop it and reboot and try installation."
    i uninstalled oracle 10g and service xe service is disabled in my services , but still i get the same error..
    i would be glad to hear a sollution to this problem..
    its
    srikanth

    The only certified product is the Oracle XE, 9i is not certified, that's why probably you got that error.
    The services entry is not found under the Oracle registry key.
    If I'm not mistaken it is found under
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
    But before you delete anything from the registry, I strongly recommend you take a backup of that specific entry, in case anything goes wrong you can restore the key.
    Delete the oracle service entry and try.
    Regards,
    Tony Garabedian

  • Need help pairing bluetooth headset [totally solved]

    OK, I have the two following pieces of hardware:
    Motorola H350 Headset
    ASUS Bluetooth USB Dongle, using a CSR radio
    I'm trying to use btsco to use my bluetooth headset. I haven't gotten it to work yet. What I'm posting here is what I'm doing, my config files: and the results I get.
    /etc/bluetooth/rfcomm.conf:
    # RFCOMM configuration file.
    rfcomm0 {
    # Automatically bind the device at startup
    bind yes;
    # Bluetooth address of the device
    device 00:0C:55:AA:A3:A9;
    # RFCOMM channel for the connection
    channel 1;
    # Description of the connection
    comment "Motorola H350 Headset";
    /etc/bluetooth/hcid.conf
    # HCI daemon configuration file.
    # HCId options
    options {
    # Automatically initialize new devices
    autoinit yes;
    # Security Manager mode
    # none - Security manager disabled
    # auto - Use local PIN for incoming connections
    # user - Always ask user for a PIN
    security auto;
    # Pairing mode
    # none - Pairing disabled
    # multi - Allow pairing with already paired devices
    # once - Pair once and deny successive attempts
    pairing multi;
    # Default PIN code for incoming connections
    passkey "0000";
    # Default settings for HCI devices
    device {
    # Local device name
    # %d - device id
    # %h - host name
    name "BlueZ (%d)";
    # Local device class
    class 0x3e0100;
    # Default packet type
    #pkt_type DH1,DM1,HV1;
    # Inquiry and Page scan
    iscan enable; pscan enable;
    # Default link mode
    # none - no specific policy
    # accept - always accept incoming connections
    # master - become master on incoming connections,
    # deny role switch on outgoing connections
    lm accept;
    # Default link policy
    # none - no specific policy
    # rswitch - allow role switch
    # hold - allow hold mode
    # sniff - allow sniff mode
    # park - allow park mode
    lp rswitch,hold,sniff,park;
    I anonymized the MAC of the Bluetooth headset because otherwise, somebody would probably yell at me for the security vulnerability. Because with that MAC, someone could uh ..... they could ...... uhm ...... well I anonymized it anyways.
    So without further ado, here's what I do to try and get my bluetooth headset going:
    [root@yvonne bluetooth]# lsmod | grep ^snd_bt_sco
    snd_bt_sco 14028 0
    [root@yvonne bluetooth]#
    That ensures I've got the appropriate module loaded.
    [root@yvonne bluetooth]# ps ax | fgrep "hcid
    > dbus"
    2987 ? Ss 0:00 /usr/bin/dbus-daemon --system
    3000 ? Ss 0:00 /usr/sbin/hcid -f /etc/bluetooth/hcid.conf
    3494 tty1 S 0:00 /usr/bin/dbus-launch --sh-syntax --exit-with-session
    3495 ? Ss 0:00 dbus-daemon --fork --print-pid 8 --print-address 6 --
    4758 pts/4 R+ 0:00 grep -F hcid?dbus
    [root@yvonne bluetooth]#
    I've got HCID going, with DBus started first (read up about that on the forums)
    [root@yvonne bluetooth]# rm /var/lib/bluetooth/00:08:2B:03:68:D2/linkkeys && touch /var/lib/bluetooth/00:11:1B:09:31:E5/linkkeys
    [root@yvonne bluetooth]# hcitool scan
    Scanning ...
    00:0C:55:AA:A3:A9 Motorola H350
    [root@yvonne bluetooth]# btsco -v 00:0C:55:AA:A3:A9
    btsco v0.42
    Device is 1:0
    Voice setting: 0x0060
    Can't connect RFCOMM channel: Connection refused
    [root@yvonne bluetooth]# rfcomm connect 00:0C:55:AA:A3:A9
    Can't connect RFCOMM socket: Connection refused
    [root@yvonne bluetooth]# rm /var/lib/bluetooth/08:08:1C:91:71:D2/linkkeys && touch /var/lib/bluetooth/00:08:D2:44:35:D2/linkkeys
    [root@yvonne bluetooth]# hcitool scan
    Scanning ...
    00:0C:55:AA:A3:A9 Motorola H350
    [root@yvonne bluetooth]# hcitool cc 00:0C:55:AA:A3:A9
    [root@yvonne bluetooth]# btsco -v 00:0C:55:AA:A3:A9
    btsco v0.42
    Device is 1:0
    Voice setting: 0x0060
    Can't connect RFCOMM channel: Connection refused
    [root@yvonne bluetooth]#
    Note that each time after I wipe out the keys from /var/lib/bluetooth, I'm putting the headset back into pairing mode by holding down its "phone" button.
    So I'm kind of at the end of my rope here. Something is going wrong during pairing, but what is it? dmesg isn't giving me any clues here either. Is the PIN not getting transmitted properly or something?[/code]

    Ok, there's some strange things happening with bluetooth these days it seems. I had a lot of trouble setting up a connection to my phone, even after following avery bit of advice I found on the net.
    But somehow I found a way, and now it works. I had to do some things not documented anywhere, excepte from some obscure places from 2003 etc.
    The most significant problem I encountered was that my phone would never find my computer, even though I set pscan and iscan enabled.
    Here's a line of code I found that fixed the problem for me. It could work for you too, since your problem looks exactly like the things I saw when the phone couldn't see my computer.
    dbus-send --system --dest=org.bluez /org/bluez/hci0
    org.bluez.Adapter.SetMode string:discoverable
    I write this after the bluetooth system has started.
    Hope it helps 

  • Need Help Calculating Credit Card Payments

    Okay, let's say that I owe my credit card company $2000.00, and they're charging me 20% APR, based on my average daily balance. If I send them $30/week, then how many weeks will it take me to pay them off?
    It seems like there should be a Financial Function for stuff like this, but if there is, I can't figure out which one to use or how it would work. I'm currently doing something like this:
    =(Current Balances :: Balance Chase*(1+Current Balances :: APR Chase/365)^7)-30
    … to figure out what I still owe at the end of the first week, then then doing a Fill Down with this formula:
    =(A2*(1+Current Balances :: $APR $Chase/365)^7)-30
    Then I do a:
    =COUNTIF(Payment Schedule :: Chase,">50")
    … figuring that if the balance is below $50, I'll just pay it off.
    Anyway, not only is this an incredibly tedious process, and probably wildly inaccurate, it's also hard to work with it in the rest of my spreadsheet. Isn't there some Function that will figure this out for me? It doesn't have to be super accurate, as long as it can give me a ballpark idea of when I'll be paid off.
    Thanks in advance,
    surfer

    Surfer,
    There's a handy financial formula that was designed to do just what you want. It's not really that difficult to find, as it's named NPER for Number of Periods.
    Here's an example using your data:
    I converted the APR to weekly using 365.25 days in a year and 7 days in a week. There may be some error in this calculation, but it should get you within a payment.
    In this case, your Period is a Week, since that's how often you are paying.
    Your Payment is negative since it's paying down, not up.
    Future Value is zero.
    This should put you in the ballpark.
    Jerry

  • Need help calculating power consumption

    I am calculating the power consumption for my new system but I have no idea how much power a radeon 9500 Pro and an athlon 2400 consume. Does anyone know?

    as the 9500 performs in a similar fashion to a high end gf4 i would guess 70 to 100 watts the xp 2400 is in the 75 watt range
    stick to 200 plus watt combined with 28a or so 3.3v
    or antec over 400 watts and you should be ok

  • Need help calculating PLEASE:-)...

    im running L8 on a G5 dual 2.0 with a RME Hammerfall PCI card.
    i keep L8 set at a 256 buffer setting. so when tracking guitars through guitar rig 3, i monitor the plug as i track. when i play back its always ahead (of course). how do i figure out the 'delay' setting for the track to put it back in the 'right' place. i just usually play with the setting till it sounds good, but thought it would be easier if there was a standard, so far its been the '1/192' setting.
    i hope my question makes sense.
    thanks!

    Here is a recent thread about it:
    http://discussions.apple.com/thread.jspa?messageID=8889821&#8889821

  • Need help getting YTD total

    I've got a period to date report with following columns:
    week1 tots, week2 tots, week3 tots, week4 tots, week5 tot, period-to-date tots, year-to-date tots
    I have a SELECT statement which totals data for the entire year and separates current period totals
    by grouping on the week_nbr . Any date between beginning of year and the end of the previous period will be week 0
    The Select statement retursn 6 rows: 1 for each week in period and one with week_nbr = 0 which represents the totals from the beginning of year
    to the end of the previous period.
    the select statement returns the data correctly . I need help getting the YTD total for (weeks 1 - 5) + (totals for week 0) for each column.
    This means that I will have a 7th record containing the YTD totals. ( I am not concerned with the PTD totals)
    I tried sum by partition but complex decode statement gave me problems.
      CREATE TABLE PERIOD_DATA
       (     "HOT_DOG_STAND_ID" NUMBER NOT NULL ENABLE,
         "WEEK_DATE" DATE,
         "NET_SALES2" NUMBER,
         "BUNS24434" NUMBER,
         "PICKELS_AW38" NUMBER,
         "MUSTARD_TB56" NUMBER,
         "CHICKENHEADS33" NUMBER,
         "PIECES_SOLD34" NUMBER,
         "SCRAPS35" NUMBER,
         "PIECES_UNACCOUNTED" NUMBER
    REM INSERTING into PERIOD_DATA
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('29-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),14301.39,13951.26,3431.13,0,3680,2484,378,818);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('05-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),14651.37,14651.37,3249.55,0,3200,2419,505,276);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('12-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),14169.89,14169.89,2463.53,0,3136,2080,474,582);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('19-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),15864.46,15864.46,3245.49,0,3472,2764,475,233);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('26-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),15961.2,15916.23,3395.51,0,3648,2838,392,418);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('02-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),19066.4,19066.4,4165.07,0,4336,3682,333,321);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('09-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18415.74,18415.74,4024.74,0,4032,3365,482,185);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('16-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18014,17849,3486.33,0,3840,3238,374,228);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('23-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),18671.09,18626.12,3729.42,0,3888,2970,353,565);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('02-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),17636,17636,3815,0,3424,2840,490,94);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('09-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),17235.52,17145.58,3897.42,0,3504,2928,421,155);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('16-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),15989.27,15989.27,3372.95,0,3728,3051,369,308);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('23-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),19067.69,18960.41,4152.6,0,4048,3293,442,313);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),18717.99,18717.99,3923.69,0,4408,3219,593,596);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('06-APR-09','DD-MON-RR HH.MI.SSXFF AM'),17335.16,17335.16,3769.08,0,3928,2997,514,417);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('13-APR-09','DD-MON-RR HH.MI.SSXFF AM'),18967.39,18967.39,4157.76,0,4144,2991,527,626);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('20-APR-09','DD-MON-RR HH.MI.SSXFF AM'),23090.88,23090.88,4427.96,0,5544,4493,560,491);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('27-APR-09','DD-MON-RR HH.MI.SSXFF AM'),24197.98,24132.99,4248.66,0,6680,5190,606,884);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('04-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),20202.21,20137.22,3714.68,0,7052,6170,422,460);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('11-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),18514.48,18514.48,3266.06,0,5508,4178,571,759);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('18-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),18678.68,18678.68,3814.07,0,5824,4345,633,846);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('25-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),17937.18,17937.18,3051.52,0,4844,4986,529,-671);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('01-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17445.75,17445.75,3079.91,0,5028,4810,656,-438);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('08-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17327.88,17327.88,3263.29,0,6112,4674,672,766);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('15-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17241.72,16937.33,3328.27,0,5792,4490,567,735);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('22-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),16625.83,16625.83,3485.18,0,5408,4319,761,328);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('29-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),17002.84,17002.84,3091.09,0,5664,4369,544,751);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('06-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),16339.19,16274.2,3075.3,0,4784,3440,697,647);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('13-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),17165.12,16885.14,3458.03,0,4320,3296,640,384);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('20-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),17029.77,16899.79,3198.91,0,4448,3449,645,354);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('27-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),16596.89,16596.89,3015.54,0,4624,3288,665,671);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('03-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),16468.58,16468.58,2981.35,0,2224,3495,564,-1835);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('10-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),18625.48,18550.5,3524.44,0,4856,3482,578,796);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('17-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),24538.54,24323.55,5580.71,0,5260,3771,608,881);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('24-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),18081.37,18081.37,3533.45,0,5980,3080,553,2347);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('31-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),17183.25,17183.25,3487.12,0,2544,3262,615,-1333);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('07-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),17688.41,17575.29,3424.17,0,4800,3480,591,729);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('14-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),18211.29,18211.29,3806.32,0,3968,3104,527,337);
    Insert into PERIOD_DATA (HOT_DOG_STAND_ID,WEEK_DATE,NET_SALES2,BUNS24434,PICKELS_AW38,MUSTARD_TB56,CHICKENHEADS33,PIECES_SOLD34,SCRAPS35,PIECES_UNACCOUNTED) values (141,to_timestamp('21-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),16809.21,16744.22,3014.61,0,4128,3124,710,294);
    SELECT HOT_DOG_STAND_ID
    , DECODE(TRUNC(week_date , 'iw') ,
             to_date('24-AUG-09' , 'dd-mon-rr') , 1 ,
             to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 ,
             to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 ,
             to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 ,
             to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 , 0) AS week_nbr
    , SUM(NET_SALES2)                                                                                                                                                                                                                                                     AS net_sales2
    , SUM(BUNS24434 ) BUNS24434
    , SUM(PICKELS_AW38) PICKELS_AW38
    , SUM(MUSTARD_TB56) MUSTARD_TB56
    , SUM(CHICKENHEADS33) CHICKENHEADS33
    , SUM(PIECES_SOLD34) PIECES_SOLD34
    , SUM(SCRAPS35) SCRAPS35
    , SUM(PIECES_UNACCOUNTED) * - 1 PIECES_UNACCOUNTED
       /*--== Head average  net_sales / chickenusage*/
    , CASE
          WHEN NVL( SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
          ELSE ROUND(SUM(net_sales2) / ( SUM(ChickenHeads33) / 8 ) , 2)
       END AS Head_average
       /*--=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100*/
    , CASE
          WHEN NVL(SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
          ELSE ROUND((((SUM(ChickenHeads33) / 8 ) - ( SUM(scraps35) / 8 ) - (SUM(pieces_unaccounted) / 8 )) / (SUM(ChickenHeads33) / 8 )) * 100 , 2)
       END AS efficiency
    FROM period_data per
    WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IY') AND TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IW') + 6 + 7 * 4
    GROUP BY hot_dog_stand_id
    , DECODE(TRUNC(week_date , 'iw') ,
          to_date('24-AUG-09' , 'dd-mon-rr') , 1 ,
          to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 ,
          to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 ,
          to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 ,
          to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 ,
          0)
    ORDER BY DECODE(TRUNC(week_date , 'iw') , to_date('24-AUG-09' , 'dd-mon-rr') , 1 , to_date('24-AUG-09' , 'dd-mon-rr') + 7 , 2 , to_date('24-AUG-09' , 'dd-mon-rr') + 14 , 3 , to_date('24-AUG-09' , 'dd-mon-rr') + 21 , 4 , to_date('24-AUG-09' , 'dd-mon-rr') + 28 , 5 , 0);The expected results will be:
    HOT_DOG_STAND_ID       WEEK_NBR               NET_SALES2             BUNS24434              PICKELS_AW38           MUSTARD_TB56           CHICKENHEADS33         PIECES_SOLD34          SCRAPS35               PIECES_UNACCOUNTED     HEAD_AVERAGE           EFFICIENCY            
    141                    7                      697067.09              694887.4               139149.91              0                      175808                 139454                 21036                  15318                  31.72                  79.32                  You can get these dame results by running endpot-to-endpoint query:
    SELECT  HOT_DOG_STAND_ID
         , max(7) as week_nbr
         ,sum(NET_SALES2)      net_sales2
          ,sum(BUNS24434 )        BUNS24434
          ,sum(PICKELS_AW38)      PICKELS_AW38
          ,sum(MUSTARD_TB56)     MUSTARD_TB56
          ,sum(CHICKENHEADS33)   CHICKENHEADS33
          ,sum(PIECES_SOLD34)    PIECES_SOLD34
          ,sum(SCRAPS35)         SCRAPS35
          ,sum(PIECES_UNACCOUNTED)   PIECES_UNACCOUNTED
        ---===== Copied code from outer query
              --==  net_sales / chickenusage 
                      ,   CASE
                             WHEN NVL( sum(ChickenHeads33) / 8    ,0)  = 0 then 0
                             ELSE ROUND(sum(net_sales2)/   ( sum(ChickenHeads33) / 8    ) , 2)
                          END as Head_average
                        --=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100
                        ,   CASE
                                  WHEN NVL(sum(ChickenHeads33) / 8    ,0)  = 0 then 0
                                  ELSE   ROUND((((sum(ChickenHeads33) / 8 )  - ( sum(scraps35) / 8 ) - (sum(pieces_unaccounted) / 8 )) / (sum(ChickenHeads33) / 8 )) * 100, 2)
                          END as efficiency  
    from period_data
    WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' ,'DD-MON-YY'), 'IY') AND TO_DATE( '27-sep-09' ,'DD-MON-YY')
    group by hot_dog_stand_id;Thanks In Advance

    Hi,
    Welcome to the forum!
    Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful. You could teach something to some people who have been using this forum for years (except that nobody can teach them).
    user12335325 wrote:
    The expected results will be:
    HOT_DOG_STAND_ID       WEEK_NBR               NET_SALES2             BUNS24434              PICKELS_AW38           MUSTARD_TB56           CHICKENHEADS33         PIECES_SOLD34          SCRAPS35               PIECES_UNACCOUNTED     HEAD_AVERAGE           EFFICIENCY            
    141                    7                      697067.09              694887.4               139149.91              0                      175808                 139454                 21036                  15318                  31.72                  79.32                 
    Do you mean the expected results will include the row above, and that the results will be this row along with the 6 rows you're already getting? (If you wanted just that one row, I suppose you would just run your second query.)
    That sound like a job for ROLLUP.
    VARIABLE   start_date     VARCHAR2 (11);
    EXEC         :start_date  := '24-AUG-2009';
         SELECT  HOT_DOG_STAND_ID
         ,      NVL (CASE
                   WHEN  week_date >= TO_DATE( :start_date, 'DD-MON-YYYY')
                   AND   week_date <  TO_DATE( :start_date, 'DD-MON-YYYY') + 35
                   THEN  1 + FLOOR ( (week_date - TO_DATE( :start_date, 'DD-MON-YYYY'))
                                             / 7
                   ELSE  0
                      END
                 , 7
                 )          AS week_nbr
    , SUM(NET_SALES2)                                                                                                                                                                                                                                                     AS net_sales2
    , SUM(BUNS24434 ) BUNS24434
    , SUM(PICKELS_AW38) PICKELS_AW38
    , SUM(MUSTARD_TB56) MUSTARD_TB56
    , SUM(CHICKENHEADS33) CHICKENHEADS33
    , SUM(PIECES_SOLD34) PIECES_SOLD34
    , SUM(SCRAPS35) SCRAPS35
    , SUM(PIECES_UNACCOUNTED) * - 1 PIECES_UNACCOUNTED
       /*--== Head average  net_sales / chickenusage*/
    , CASE
          WHEN NVL( SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
          ELSE ROUND(SUM(net_sales2) / ( SUM(ChickenHeads33) / 8 ) , 2)
       END AS Head_average
       /*--=== Efficiency =   (ChickenUsage  - scrappedDiv8 - unaccountedDiv8) / ChickenUsage)  * 100*/
    , CASE
          WHEN NVL(SUM(ChickenHeads33) / 8 , 0) = 0 THEN 0
          ELSE ROUND((((SUM(ChickenHeads33) / 8 ) - ( SUM(scraps35) / 8 ) - (SUM(pieces_unaccounted) / 8 )) / (SUM(ChickenHeads33) / 8 )) * 100 , 2)
       END AS efficiency
    FROM period_data per
    WHERE week_DATE BETWEEN TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IY') AND TRUNC(TO_DATE( '24-AUG-09' , 'DD-MON-YY') , 'IW') + 6 + 7 * 4
    GROUP BY  hot_dog_stand_id
    ,           ROLLUP (
                 CASE
                   WHEN  week_date >= TO_DATE( :start_date, 'DD-MON-YYYY')
                   AND   week_date <  TO_DATE( :start_date, 'DD-MON-YYYY') + 35
                   THEN  1 + FLOOR ( (week_date - TO_DATE( :start_date, 'DD-MON-YYYY'))
                                             / 7
                   ELSE  0
                 END          -- week_nbr
    ORDER BY  week_nbr
    ;Notice I simplified the computation of week_nbr.
    Some other people have asked questions about hot dog stands recently.
    I'm curious; is this from a course? If so, where? What is the textbook (if any)?
    Thanks.

  • Need Help with Average of a calculated field

    Good Morning ,
    In the cube that i built i have a calculated field "AvgAbandonTime"=round(([Measures].[C8]/[Measures].[C9]),0). C8 and C9 in the calculation are calculated fields in the DSV based off the fields from the Database.
    In the browser i'm having a problem. In the below sample data set , if you look i'm calculating the "AvgAbandonTime" per each location and this value is in seconds. C8 and C9 are the fields used in the calculation. For example C8/C9=11588/126=92
    (ROUNDED).Similarly for the other two rows. The problem is when it comes to the Grand Total , i'm expecting average of AvgAbandonTime over the 3 locations and that should be (92+16+73)/3=60, but where as what its doing is Summing all the C8 and all
    the C9 values and giving me the SUM(C8)/SUM(C9)=74. Please need help or advice.
    Thanks

    Thanks David,
    But no its not giving those values instead its giving
    C8
    C9
    Avg
    AvgAbandonTime11
    newcalc
    sum
    11588
    126
    92
    8191
    8191
    24753
    157
    10
    16
    157
    157
    24753
    62160
    857
    73
    16405
    16405
    24753
    GrandTotal
    73905
    993
    74
    99
    1.#INF
    24753

  • Need help with calculator project for an assignment...

    Hi all, I please need help with my calculator project that I have to do for an assignment.
    Here is the project's specifications that I need to do"
    """Create a console calculator applicaion that:
    * Takes one command line argument: your name and surname. When the
    program starts, display the date and time with a welcome message for the
    user.
    * Display all the available options to the user. Your calculator must include
    the arithmetic operations as well as at least five scientific operations of the
    Math class.
    -Your program must also have the ability to round a number and
    truncate it.
    -When you multiply by 2, you should not use the '*' operator to perform the
    operation.
    -Your program must also be able to reverse the sign of a number.
    * Include sufficient error checking in your program to ensure that the user
    only enters valid input. Make use of the String; Character, and other
    wrapper classes to help you.
    * Your program must be able to do conversions between decimal, octal and
    hex numbers.
    * Make use of a menu. You should give the user the option to end the
    program when entering a certain option.
    * When the program exits, display a message for the user, stating the
    current time, and calculate and display how long the user used your
    program.
    * Make use of helper classes where possible.
    * Use the SDK to run your program."""
    When the program starts, it asks the user for his/her name and surname. I got the program to ask the user again and again for his/her name and surname
    when he/she doesn't insert anything or just press 'enter', but if the user enters a number for the name and surname part, the program continues.
    Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??
    Here is the programs code that I've written so far:
    {code}
    import java.io.*;
    import java.util.*;
    import java.text.*;
    public class Project {
         private static String nameSurname = "";     
         private static String num1 = null;
         private static String num2 = null;
         private static String choice1 = null;
         private static double answer = 0;
         private static String more;
         public double Add() {
              answer = (Double.parseDouble(num1) + Double.parseDouble(num2));
              return answer;
         public double Subtract() {
              answer = (Double.parseDouble(num1) - Double.parseDouble(num2));
              return answer;
         public double Multiply() {
              answer = (Double.parseDouble(num1) * Double.parseDouble(num2));
              return answer;
         public double Divide() {
              answer = (Double.parseDouble(num1) / Double.parseDouble(num2));
              return answer;
         public double Modulus() {
              answer = (Double.parseDouble(num1) % Double.parseDouble(num2));
              return answer;
         public double maximumValue() {
              answer = (Math.max(Double.parseDouble(num1), Double.parseDouble(num2)));
              return answer;
         public double minimumValue() {
              answer = (Math.min(Double.parseDouble(num1), Double.parseDouble(num2)));
              return answer;
         public double absoluteNumber1() {
              answer = (Math.abs(Double.parseDouble(num1)));
              return answer;
         public double absoluteNumber2() {
              answer = (Math.abs(Double.parseDouble(num2)));
              return answer;
         public double Squareroot1() {
              answer = (Math.sqrt(Double.parseDouble(num1)));
              return answer;
         public double Squareroot2() {
              answer = (Math.sqrt(Double.parseDouble(num2)));
              return answer;
         public static String octalEquivalent1() {
              int iNum1 = Integer.parseInt(num1);
    String octal1 = Integer.toOctalString(iNum1);
    return octal1;
         public static String octalEquivalent2() {
              int iNum2 = Integer.parseInt(num2);
              String octal2 = Integer.toOctalString(iNum2);
              return octal2;
         public static String hexadecimalEquivalent1() {
              int iNum1 = Integer.parseInt(num1);
              String hex1 = Integer.toHexString(iNum1);
              return hex1;
         public static String hexadecimalEquivalent2() {
              int iNum2 = Integer.parseInt(num2);
              String hex2 = Integer.toHexString(iNum2);
              return hex2;
         public double Round1() {
              answer = Math.round(Double.parseDouble(num1));
              return answer;
         public double Round2() {
              answer = Math.round(Double.parseDouble(num2));
              return answer;
              SimpleDateFormat format1 = new SimpleDateFormat("EEEE, dd MMMM yyyy");
         Date now = new Date();
         SimpleDateFormat format2 = new SimpleDateFormat("hh:mm a");
         static Date timeIn = new Date();
         public static long programRuntime() {
              Date timeInD = timeIn;
              long timeOutD = System.currentTimeMillis();
              long msec = timeOutD - timeInD.getTime();
              float timeHours = msec / 1000;
                   return (long) timeHours;
         DecimalFormat decimals = new DecimalFormat("#0.00");
         public String insertNameAndSurname() throws IOException{
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        while (nameSurname == null || nameSurname.length() == 0) {
                             for (int i = 0; i < nameSurname.length(); i++) {
                             if ((nameSurname.charAt(i) > 'a') && (nameSurname.charAt(i) < 'Z')){
                                       inputCorrect = true;
                        else{
                        inputCorrect = false;
                        break;
                        try {
                             BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("Please enter your name and surname: ");
                             nameSurname = inStream.readLine();
                             inputCorrect = true;
                        }catch (IOException ex) {
                             System.out.println("You did not enter your name and surname, " + nameSurname + " is not a name, please enter your name and surname :");
                             inputCorrect = false;
                        System.out.println("\nA warm welcome " + nameSurname + " ,todays date is: " + format1.format(now));
                        System.out.println("and the time is now exactly " + format2.format(timeIn) + ".");
                        return nameSurname;
              public String inputNumber1() throws IOException {
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("\nPlease enter a number you want to do a calculation with and hit <ENTER>: ");
                             num1 = br.readLine();
                             double number1 = Double.parseDouble(num1);
                             System.out.println("\nThe number you have entered is: " + number1);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("\nYou did not enter a valid number: " + "\""+ num1 + "\" is not a number!!");
                             inputCorrect = false;
                        return num1;
         public String calculatorChoice() throws IOException {
              System.out.println("Please select an option of what you would like to do with this number from the menu below and hit <ENTER>: ");
              System.out.println("\n*********************************************");
              System.out.println("---------------------------------------------");
              System.out.println("Please select an option from the list below: ");
              System.out.println("---------------------------------------------");
              System.out.println("1 - Add");
              System.out.println("2 - Subtract");
              System.out.println("3 - Multiply");
              System.out.println("4 - Divide (remainder included)");
              System.out.println("5 - Maximum and minimum value of two numbers");
              System.out.println("6 - Squareroot");
              System.out.println("7 - Absolute value of numbers");
              System.out.println("8 - Octal and Hexadecimal equivalent of numbers");
              System.out.println("9 - Round numbers");
              System.out.println("0 - Exit program");
              System.out.println("**********************************************");
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader inStream = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("Please enter your option and hit <ENTER>: ");
                             choice1 = inStream.readLine();
                             int c1 = Integer.parseInt(choice1);
                             System.out.println("\nYou have entered choice number: " + c1);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("You did not enter a valid choice number: " + "\""+ choice1 + "\" is not in the list!!");
                             inputCorrect = false;
                        return choice1;
         public String inputNumber2() throws IOException {
              boolean inputCorrect = false;
                   while (inputCorrect == false) {
                        try {
                             BufferedReader br2 = new BufferedReader (new InputStreamReader(System.in));
                             System.out.print("\nPlease enter another number you want to do the calculation with and hit <ENTER>: ");
                             num2 = br2.readLine();
                             double n2 = Double.parseDouble(num2);
                             System.out.println("\nThe second number you have entered is: " + n2);
                             System.out.println("\nYour numbers are: " + num1 + " and " + num2);
                             inputCorrect = true;
                        } catch (NumberFormatException nfe) {
                             System.out.println("You did not enter a valid number: " + "\""+ num2 + "\" is not a number!!");
                             inputCorrect = false;
                        return num2;
         public int Calculator() {
              int choice2 = (int) Double.parseDouble(choice1);
              switch (choice2) {
                        case 1 :
                             Add();
                             System.out.print("The answer of " + num1 + " + " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 2 :
                             Subtract();
                             System.out.print("The answer of " + num1 + " - " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 3 :
                             Multiply();
                             System.out.print("The answer of " + num1 + " * " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 4 :
                             Divide();
                             System.out.print("The answer of " + num1 + " / " + num2 + " is: " + decimals.format(answer));
                             Modulus();
                             System.out.print(" and the remainder is " + decimals.format(answer));
                             break;
                        case 5 :
                             maximumValue();
                             System.out.println("The maximum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
                             minimumValue();
                             System.out.println("The minimum number between the numbers " + num1 + " and " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 6 :
                             Squareroot1();
                             System.out.println("The squareroot of value " + num1 + " is: " + decimals.format(answer));
                             Squareroot2();
                             System.out.println("The squareroot of value " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 7 :
                             absoluteNumber1();
                             System.out.println("The absolute number of " + num1 + " is: " + decimals.format(answer));
                             absoluteNumber2();
                             System.out.println("The absolute number of " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 8 :
                             octalEquivalent1();
                             System.out.println("The octal equivalent of " + num1 + " is: " + octalEquivalent1());
                             octalEquivalent2();
                             System.out.println("The octal equivalent of " + num2 + " is: " + octalEquivalent2());
                             hexadecimalEquivalent1();
                             System.out.println("\nThe hexadecimal equivalent of " + num1 + " is: " + hexadecimalEquivalent1());
                             hexadecimalEquivalent2();
                             System.out.println("The hexadecimal equivalent of " + num2 + " is: " + hexadecimalEquivalent2());
                             break;
                        case 9 :
                             Round1();
                             System.out.println("The rounded number of " + num1 + " is: " + decimals.format(answer));
                             Round2();
                             System.out.println("The rounded number of " + num2 + " is: " + decimals.format(answer));
                             break;
                        case 0 :
                             if (choice2 == 0) {
                                  System.exit(1);
                             break;
                   return choice2;
              public String anotherCalculation() throws IOException {
                   boolean inputCorrect = false;
                   while (inputCorrect == false) {
                             try {                              
                                  BufferedReader br3 = new BufferedReader (new InputStreamReader(System.in));
                                  System.out.print("\nWould you like to do another calculation? Y/N ");
                                  more = br3.readLine();
                                  String s1 = "y";
                                  String s2 = "Y";
                                  if (more.equals(s1) || more.equals(s2)) {
                                       inputCorrect = true;
                                       while (inputCorrect = true){
                                            inputNumber1();
                                            System.out.println("");
                                            calculatorChoice();
                                            System.out.println("");
                                            inputNumber2();
                                            System.out.println("");
                                            Calculator();
                                            System.out.println("");
                                            anotherCalculation();
                                            System.out.println("");
                                            inputCorrect = true;
                                  } else {
                                       System.out.println("\n" + nameSurname + " thank you for using this program, you have used this program for: " + decimals.format(programRuntime()) + " seconds");
                                       System.out.println("the program will now exit, Goodbye.");
                                       System.exit(0);
                             } catch (IOException ex){
                                  System.out.println("You did not enter a valid answer: " + "\""+ more + "\" is not in the list!!");
                                  inputCorrect = false;
              return more;
         public static void main(String[] args) throws IOException {
              Project p1 = new Project();
              p1.insertNameAndSurname();
              System.out.println("");
              p1.inputNumber1();
              System.out.println("");
              p1.calculatorChoice();
              System.out.println("");
              p1.inputNumber2();
              System.out.println("");
              p1.Calculator();
                   System.out.println("");
                   p1.anotherCalculation();
                   System.out.println("");
    {code}
    *Can you please run my code for yourself and have a look at how this program is constructed*
    *and give me ANY feedback on how I can better this code(program) or if I've done anything wrong from your point of view.*
    Your help will be much appreciated.
    Thanks in advance

    Smirre wrote:
    Now my question is this: How can I restrict the user to only enter 'letters' (and spaces of course) but allow NO numbers for his/her surname??You cannot restrict the user. It is a sad fact in programming that the worst bug always sits in front of the Computer.
    What you could do is checking the input string for numbers. If it contains numbers, just reprompt for the Name.
    AND you might want to ask yourself why the heck a calculator needs to know the users Name.

Maybe you are looking for

  • American express website does not allow me to pay my bill online

    I am running firefox 3.5.13 on windows XP SP2. The previous release of Firefox worked fine. When I go to the american express web site and try to do the online bill paying routine it fails to work. It will show my account info as expected but when I

  • Oracle 10g Database 64 bit setup file

    Hi Friends, I want 10g oracle database 64 bit or any Oracle 10g database setup file which is compatible with windows 7 64 bit. I have searched in torrents and Google every where for this. I dont have Oracle support a/c to order CD. Please help by sha

  • Yosemite FileVault resizes application reopened windows after login

    HI, I have a weird behaviour of reopened application windows (Reopen windows when logging back in feature) after I switched on the FileVault disk encryption. I think that it could be due to the fact that login screen is in 1280x800 resolution and my

  • Webdynpro for Java Edit and Save.

    Dear all, ter cal iam working on webdynpro for java i want simple code for EDIT and SAVE  after calling a rfc in for using NWDS webdynpro for java. 1)HOW TO SAVE AND EDIT THE FRONT WEBDYNPRO FOR JAVA APPLICATION 2)AFTER SAVING AND THE DATA THAT SHOUL

  • Local printer management --Spooler Issues--

    Trouble: of the 3 production printers on a local machine 1 to many of the printers may have a Job get stuck in printing for some unknown issue. Clicking cancel job / Delete fails to remove the Job from the List. At this point i am forced to Kill the