Average Quanitity Columns in REUSE_ALV_HIERSEQ_LIST_DISPLAY

Hi there,
I'm using REUSE_ALV_HIERSEQ_LIST_DISPLAY FM and I need to do Average for one of the quantity fields. I tried passing 'C' to DO_SUM parameter in Field Catalog. But, it doesn't seem to be working for Hierarcial Display. Is it that I'm missing out some parameters?
Please put in your views on this.
Thanks!

Tell the user that he cant get it. Excel does not know what hierachical is, thats why it is disabled. The hierachical realtionship father/child does not have something corresponding in excel. The user has to live with that.

Similar Messages

  • SSRS 2008 R2 - Add moving average to column group

    I have a column group of dollar amounts.  The row is a year/month.  I would like to add a moving average column to the right of the last 6 months.  My SQL Server data source is already complex enough and I'd really prefer not to add a column
    there.  Is there anything I can do within the report itself?  Some way to reference the previous records in a matrix?
    Thank you!

    Hi mateoc15,
    According to your description, you have a matrix in your report. Now you want to calculate the average value of last 6 month. Right?
    In Reporting Service, we can put custom code into report to deal with complicated logic. Add one more column/row inside of group and call the functions defined in custom code. For your requirement we modified Robert’s code to achieve your goal. We tested
    your case in our local environment with sample data. Here are steps and screenshots for your reference:
    Put the custom code into report:
    Private queueLength As Integer = 6
    Private queueSum As Double = 0
    Private queueFull As Boolean = False
    Private idChange As String=""
    Dim queue As New System.Collections.Generic.Queue(Of Integer)
    Public Function CumulativeQueue(ByVal currentValue As Integer,id As String) As Object
    Dim removedValue As Double = 0
    If idChange <> id then
            ClearQueue()
                    idChange = id
                    queueSum = 0
                    queueFull = False
                    CumulativeQueue(currentValue,id)
    Else
                    If queue.Count >= queueLength Then
                                    removedValue = queue.Dequeue()
                    End If
                    queueSum += currentValue
                    queueSum -= removedValue
                    queue.Enqueue(currentValue)
                    If queue.Count < queueLength Then
                    Return Nothing
                    ElseIf queue.Count = queueLength And queueFull = False Then
                    queueFull = True
                    Return queueSum / queueLength
                    Else
                    Return (queueSum) / queueLength
                    End If
    End If
    End Function
    public function ClearQueue()
    Dim i as Integer
    Dim n as Integer = Queue.Count-1
    for i=n To 0 Step-1
                    queue.Dequeue()
    next i
    End function
    Add one more row inside of group, call the function defined in custom code.
    Save and preview. It looks like below:
    Reference:
    Moving or rolling average, how to?
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • Displaying Average of Columns in ALV Blocked List Display

    Hi,
    I am using ALV Blocked List Display. For the 1st block, I need to display the average of certain columns.
    I am using the following code in the field catalog of the RATE column to display the average , but it is not displayed.
    wa_disptab_field-col_pos = 8.
      wa_disptab_field-fieldname = 'RATE''.
      wa_disptab_field-ref_tabname = 'IT_DISPTAB'.
      wa_disptab_field-seltext_m = 'RS PER KL'.
      wa_disptab_field-do_sum  =  'C'.
      wa_disptab_field-datatype  = 'QUAN'.
      append wa_disptab_field to it_disptab_field.
      clear wa_disptab_field.
    For the same column, the sum is displayed with the same code if I change this part:
    wa_disptab_field-do_sum  =  'C'.   To   wa_disptab_field-do_sum  =  'X'.
    Please Help..

    Hi Debarati,
    go For function/pattern [reuse_alv_grid_display_lvc]
    do the following as mentioned in the previous reply's.
    And  To find the Average of your requirement, pass the field names as per the requirement. 
    gs_sort-fieldname = 'RATE'.
    gs_sort-tabname = 'T_DISPTAB' "Final Internal table
    gs_sort-subtot = 'X'.
    APPEND gs_sort TO gt_sort.
    gs_sort-fieldname = 'RATE1'.
    gs_sort-tabname = 'T_DISPTAB' "Final Internal table
    gs_sort-subtot = 'X'.
    APPEND gs_sort TO gt_sort.
    gs_sort-fieldname = 'RATE2'.
    gs_sort-tabname = 'T_DISPTAB' "Final Internal table
    gs_sort-subtot = 'X'.
    APPEND gs_sort TO gt_sort.
    gs_sort-fieldname = 'RATE3'.
    gs_sort-tabname = 'T_DISPTAB' "Final Internal table
    gs_sort-subtot = 'X'.
    APPEND gs_sort TO gt_sort.
    CALL FUNCTION ' REUSE_ALV_GRID_DISPLAY_lvc'
       EXPORTING
          i_callback_program      = sy-cprog
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat              = wa_disptab
          it_events               = gt_events
          it_sort                   = gt_sort
          i_default               = 'X'
          i_save                  = 'U'
        TABLES
          t_outtab                = gt_final
       EXCEPTIONS
         program_error                  = 1
         OTHERS                         = 2
      IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    i think this will  workout.
    Thanks & Regards,
    Abhisek
    Edited by: Abhisek Pradhan on Sep 29, 2011 7:55 PM

  • Display average in Column chart retreieving the data from Filters

    Hello Experts,
    I have filters and Bar chart as a combination. I would like to display the average of the source data on my bar chart based on the selection using filters. Is this possible? if yes, how??
    Thanks in advance
    Regards,
    Santosh

    Hi,
    Please sent me if you have any test data to parvathaneni.satish at gmail
    I can do it and sent it to acrosss...
    This is a kind of easy things...
    FYI :please refer to sample in xcelsius which will give you a better idea....

  • How to select a color of cell in REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi.
    I need to select a color of a cell in REUSE_ALV_HIERSEQ_LIST_DISPLAY.
    I have found an example, but 
    It shows how to select a color of sell in REUSE_ALV_LIST_DISPLAY.
    Can you give me an example of code?
    Thanks.

    Here ia a simple example of the method how to paint a cell / line / column using REUSE_ALV_HIERSEQ_LIST_DISPLAY  function.
      Programm:    zalv_hierseq_color
      Paint a line, a colomn, or a cell
      using REUSE_ALV_HIERSEQ_LIST_DISPLAY
      Victor Stupin, Russia 2009
    REPORT zalv_hierseq_color.
    TABLES: spfli.
    TYPE-POOLS: slis.
    SELECTION-SCREEN BEGIN OF BLOCK rad1.
    PARAMETERS:
            p_row TYPE i,
            p_col TYPE i.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN ULINE.
    SELECTION-SCREEN COMMENT /1(50) comm1.
    SELECTION-SCREEN COMMENT /1(50) comm2.
    SELECTION-SCREEN COMMENT /1(50) comm3.
    SELECTION-SCREEN END OF BLOCK rad1.
    INITIALIZATION.
      comm1 = 'Paint a line: fill ONLY p_row (p_col is empty)'.
      comm2 = 'Paint a colomn: fill ONLY p_col (r_row is empty)'.
      comm3 = 'Paint a cell: fill P_COL and R_ROW'.
      DATA:
            t_fieldcat TYPE slis_t_fieldcat_alv,
            fs_fieldcat LIKE LINE OF t_fieldcat,
            fs_layout TYPE slis_layout_alv ,
            w_color(4) ,
            w_row TYPE i,
            w_fieldname(20),
            w_prog TYPE sy-repid.
      DATA:
      BEGIN OF t_spfli OCCURS 0,
            color(4),
            checkbox ,
            cell     TYPE slis_t_specialcol_alv,
            carrid   TYPE spfli-carrid,
            connid   TYPE spfli-connid,
            cityfrom TYPE spfli-cityfrom,
            cityto   TYPE spfli-cityto,
            distance TYPE spfli-distance,
            keyln    TYPE int4,
            box      TYPE char1,
            lineno   TYPE int4,
      END OF t_spfli.
      DATA:
      fs_cell LIKE LINE OF t_spfli-cell.
      DATA: gt_item    LIKE TABLE OF t_spfli WITH HEADER LINE,
            gt_header  LIKE TABLE OF t_spfli WITH HEADER LINE,
            gs_keyinfo TYPE slis_keyinfo_alv.
    START-OF-SELECTION.
      SELECT *
      FROM spfli
      INTO CORRESPONDING FIELDS OF TABLE t_spfli.
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 1.
      fs_fieldcat-tabname = 'GT_HEADER'.
      fs_fieldcat-fieldname = 'CARRID'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = 'X'.
      fs_fieldcat-hotspot = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat .
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 2.
      fs_fieldcat-tabname = 'GT_HEADER'.
      fs_fieldcat-fieldname = 'CONNID'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = 'X'.
      fs_fieldcat-hotspot = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat .
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 3.
      fs_fieldcat-tabname = 'GT_HEADER'.
      fs_fieldcat-fieldname = 'DISTANCE'.
      fs_fieldcat-key = ' '.
      fs_fieldcat-edit = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat.
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 4.
      fs_fieldcat-tabname = 'GT_HEADER'.
      fs_fieldcat-fieldname = 'CITYFROM'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = ' '.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat .
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 5.
      fs_fieldcat-tabname = 'GT_ITEM'.
      fs_fieldcat-fieldname = 'CARRID'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = 'X'.
      fs_fieldcat-hotspot = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat .
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 6.
      fs_fieldcat-tabname = 'GT_ITEM'.
      fs_fieldcat-fieldname = 'CONNID'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = 'X'.
      fs_fieldcat-hotspot = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat.
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 7.
      fs_fieldcat-tabname = 'GT_ITEM'.
      fs_fieldcat-fieldname = 'DISTANCE'.
      fs_fieldcat-key = ' '.
      fs_fieldcat-edit = 'X'.
      APPEND fs_fieldcat TO t_fieldcat.
      CLEAR fs_fieldcat.
      fs_fieldcat-row_pos = 1.
      fs_fieldcat-col_pos = 8.
      fs_fieldcat-tabname = 'GT_ITEM'.
      fs_fieldcat-fieldname = 'CITYFROM'.
      fs_fieldcat-ref_tabname = 'SPFLI'.
      fs_fieldcat-key = ' '.
      APPEND fs_fieldcat TO t_fieldcat.
      p_col = p_col + 4.
      LOOP AT t_fieldcat INTO fs_fieldcat WHERE tabname = 'GT_ITEM'.
        IF fs_fieldcat-col_pos EQ p_col.
          fs_fieldcat-emphasize = 'C600'.
          w_fieldname = fs_fieldcat-fieldname.
          IF p_row IS INITIAL AND p_col GT 0.  " <---- paint only column if p_row is empty
            MODIFY t_fieldcat FROM fs_fieldcat TRANSPORTING emphasize.
          ENDIF.
        ENDIF.
      ENDLOOP.
      fs_cell-fieldname = w_fieldname .
      fs_cell-color-col = 6.
      fs_cell-nokeycol = 'X'.
      APPEND fs_cell TO t_spfli-cell.
      IF p_row IS NOT INITIAL AND p_col IS NOT INITIAL.  " <---- paint a cell
        MODIFY t_spfli INDEX p_row TRANSPORTING cell.
      ENDIF.
      fs_layout-info_fieldname = 'COLOR'.
      fs_layout-coltab_fieldname = 'CELL'.
      fs_layout-f2code = '&ETA'.
      gs_keyinfo-header01 = 'KEYLN'.
      gs_keyinfo-item01   = 'KEYLN'.
      LOOP AT t_spfli INTO gt_item.
        gt_item-keyln = 1.
        gt_item-lineno = gt_item-lineno + 1.
        APPEND gt_item.
      ENDLOOP.
      READ TABLE t_spfli INDEX 1 INTO gt_header.
      gt_header-keyln = 1.
      gt_header-lineno = 0.
      APPEND gt_header.
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
          is_layout                      = fs_layout
          it_fieldcat                    = t_fieldcat
          i_tabname_header               = 'GT_HEADER'
          i_tabname_item                 = 'GT_ITEM'
          is_keyinfo                     = gs_keyinfo
        TABLES
          t_outtab_header                = gt_header
          t_outtab_item                  = gt_item
    EXCEPTIONS
      PROGRAM_ERROR                  = 1
      OTHERS                         = 2
      IF sy-subrc = 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

  • Regarding addition of new column in existing  appraisal templates

    hi gurus,
    i m working on the existing appraisal templates in which i have to add one more column named "Avereage Rating"
           in which the average of "MID YEAR ACHIEVEMENT COLUMN TOTAL VALUE" & "FINAL APPRAISAL RATING COLUMN TOTAL VALUE"
           for eg:"(3.5+4.0)/2 = 3.75" i.e the value 3.75 will come in the average rating column,plz help me to sort out
           this column,for this,no doubt i have added the column for this but for the  value "3.75" what "value list",
           "value class" & "value determination" sud i use against this column plz help me....

    solved

  • Summary Column and repeating frames

    I have a report that shows customer orders(1 per page). If a customer orders 3 pizzas and 2 of them are identical, same size, same toppings, crust i want the quanitity column to sum as 2. So for this example instead of having 3 rows with two of them being identical with the quanity column dispalying 1 for each, I want 2 rows with quanity showing 2 for the identical pizzas and 1 for the other.
    I have everything in the same group/repeating frame right now and it is showing all 3 pizzas on there own row. Do i need a summary column and change my groupings? How can i achieve this the summed quanity for identical orders?
    CURRENT:
    Crust......Toppings......size.....quantity
    Thin.......Cheese........small....1
    Thin.......Cheese........small....1
    thick.......meat.........large....1
    NEW:
    Crust......Toppings......size.....quantity
    Thin.......Cheese........small....2
    thick.......meat.........large....1

    Forget summary columns. This can easily be just a group by query:
    with t as (select 'Thin' crust, 'Cheese' top ,'Small' sze, 1 qty from dual
               union all
               select 'Thin' , 'Cheese'  ,'Small' , 2 from dual
               union all
               select 'Thick' , 'Meat'  ,'Large', 1  from dual
    select t.crust, t.top, t.sze, sum(qty)
    from t
    group by crust,top,sze;
    CRUST TOP    SZE     SUM(QTY)
    Thin  Cheese Small          3
    Thick Meat   Large          1

  • Hide column result in pivot grand total row

    Hello
    Do you know if it is possible to hide the result of a particular column in a pivot grand total row?
    I have several columns to which makes sense use a grand total row (as in a sum) but for others (such as average) it does not make sense in the light of the client business rules.
    Any help on this matter is highly appreciated :)
    Thanks in advance,
    J Marques

    I have a measure that represents the average time according to the dimensions it uses - and that works properly.
    However, the grand total for that column shows me the average of the average times above. This is not correct that is why I want to hide it.As said by kishore, In pivot go to that time average time column -> Aggregation rule -> None, This won't affect the column avg value.
    The grant total value will not come.
    By setting this, are you getting wrong values?
    Thanks,
    Vino

  • Total of average

    Hello. I am a simple discoverer report which has 3 columns:
    'Product' and 'Cost' and 'Average Cost'
    The 'Product' and 'Cost' columns are summation columns straight from a business area, that is produced from a table:
    SUM(Product), SUM(Cost)
    The 'Average Cost' column is the follwing Calcuation:
    AVG(Cost).
    The average caculates properly.
    However when I try to total the 'Average Cost' column, the total does not calculate properly.
    Is there any way to fix this?

    If I'm understanding you correctly, you have something like
    product line A
    units 50
    cost 1000
    average cost 20
    product line B
    units 10000
    cost 100000
    average cost 10
    and you want the average cost across all products, which is (101000/10050), which is about 10.05.
    So what are you doing, and what result do you get?
    -- jim

  • Scalar distance across columns

    I need to calculate the scalar (Euclidean) distance between two vectors, each dimension represented by columns in a table. I have a procedure that does it the slow and painful way: loop over all vector pairs/loop over all columns/look up the individual cell values/sum over all the differences. It appears to me though, that there should be a more straightforward way to do this using the:
    SELECT * FROM TST INTO vREF_DATA WHERE REGNO=1;
    SELECT * FROM TST INTO vCMP_DATA WHERE REGNO=2;
    syntax in PL/SQL, then loop over the variables/column elements to sum the differences. However, I can't figure out how to keep the pointers for each variable in sync.
    E.g.: coord1(1,2,3), coord2(2,3,1), differences(1,1,2), sum=4.
    I can do this in Perl using hashes/arrays, but not in PL/SQL. What is the right frame/syntax to do this? If it were a couple of hundred rows, I'd do it in Perl, but with millions of rows and hundreds of columns, it gets real tedious, not to mention easily out-of-sync with the database contents.
    I'd appreciate any suggestions!

    Michiel:
    Glad that it works for you. So, you want a fishing lesson :-).
    First, the full documentation for the DBMS_SQL package can be found here .
    Essentially, DBMS_SQL is an industrial strength version of EXECUTE IMMEDIATE (well, properly, EXECUTE IMMEDIATE is a highly simplified version of DBMS_SQL, since DBMS_SQL came first). It has many advantages over EXECUTE IMMEDIATE because it allows you full control over virtually everything to do with the query. So, you can relatively easily create bind variables on the fly to create statements with an unknown number of binds. It also allows you to find the columns from any arbitrary query through DBMS_SQL.Describe_Columns.
    You never actually see any values returned, because I never actually return any. Since you wanted your output in another table, I decided to build one big insert statement, rather than iterate through all the rows, calculate the distance, and then insert one row at a time. It seemed more efficient to me. I also decided to "hard code", through a bind variable, each of the column values from the ref_id, rather than try to dynamically build a join, which seemd simpler to me.
    1. DBMS_SQL.Describe_Columns returns a table of records, one record for each column, that gives information much like that in the xxx_tab_columns views. If some id columns may be numeric, you can test the col_type field in the table of records and put a dummy VARCHAR variable into the character columns. Just be aware that the col_type field returns a numeric version of the column_type, not a string. If you look at the text from user_tab_cols:
    SELECT text
    FROM dba_views
    WHERE view_name = 'USER_TAB_COLS'You can see where Oracle DECODES the numeric type to the NUMBER, VARCHAR2 etc. Essentially, NUMBER is 1 and VARCHAR2 is 2.
    2. I replaced the FOR scale_rec IN ... LOOP block with another DBMS_SQL built query to pull the AVG and VARIANCE from the table, it is commented in the code below.
    3. You cannot really put a threshold on the computation of the distance, since the distance is not really known to the query until it is fully executed (i.e. at the time of inserting). However, you could modify the insert query to filter values with distances greater than 3. I will leave that modification as a exercise for the fiherman, but the end sql statement would look something like:
    INSERT INTO diag
    SELECT src, id, dist
    FROM (SELECT :src_id src, id,
            SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) - POWER((col1 - :mean2)/:var2, 2))+
                     (POWER((:sc3 - :mean3)/:var3, 2) - POWER((col2 - :mean3)/:var3, 2))+
                     (POWER((:sc4 - :mean4)/:var4, 2) - POWER((col3 - :mean4)/:var4, 2)))) dist
          FROM t
          WHERE id <> :src_id)
    WHERE dist <= 3Now here is a heavily commented version taking into account the proper formula.
    CREATE or replace PROCEDURE euclidean_distance (p_src_tab IN VARCHAR2) AS
       -- Associative Array for scaling factors
       TYPE scale_cols_tp IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
       mean_cols scale_cols_tp; -- Will hold average of columns
       var_cols scale_cols_tp;  -- Will hold variance of columns
       -- Array to hold column values for the reference id
       TYPE src_cols_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       src_cols src_cols_tp;
       l_dummyn NUMBER;  -- Dummy Number for Define Column
       l_ignore NUMBER;  -- Receives rows processed from queries
       l_sqlstr VARCHAR2(32767);  -- For sql statements
       src_cur  NUMBER;  -- Reference ID Cursor handle
       src_tab  DBMS_SQL.Desc_Tab;  -- Table of Records describing passed table
       src_col_cnt NUMBER;   -- Number of columns in passed table
       ins_cur  NUMBER;  -- Insert Cursor handle
       mv_cur  NUMBER;  -- Cursor handle for Mean and Variance of table
       l_col_pos NUMBER; -- Index into src_tab
       l_res_pos NUMBER; -- Column position in mv_cur
       l_x1     VARCHAR2(10);  -- Dynamic bind variable for source column values
       l_x2     VARCHAR2(30);  -- Column name from source columns
       l_meani  VARCHAR2(10);  -- Dynamic bind variable for mean of table
       l_vari   VARCHAR2(10);  -- Dynamic bind variable for variance of table
    BEGIN
       -- Get a "handle" for a cursor, and parse the query
       src_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(src_cur, 'SELECT * FROM '||p_src_tab||' WHERE id = :src_id',DBMS_SQL.Native);
       -- Describe the table to get number of columns, their names and their types
       DBMS_SQL.Describe_Columns(src_cur, src_col_cnt, src_tab);
       -- I now have a table of records (src_tab) showing similar info
       -- to that shown in xxx_tab_columns, one record per column
       -- and the number of columns in the table (actually the number of records
       -- in src_tab) is in src_col_cnt
       -- Define the column types for src_cur.  This just tell DBMS_SQL that
       -- the column at position i (based on the column list in the select)
       -- is of the passed data type.  It is not setting a variable to
       -- receive the column value.
       -- I am assuming all inluding ID are NUMBER.
       -- If id may be alpha can test src_tab(i).col_type to check data type
       FOR i IN 1 .. src_col_cnt LOOP
          DBMS_SQL.DEFINE_COLUMN(src_cur, i, l_dummyn);
       END LOOP;
    -- This section replaces the FOR scale_rec IN LOOP
       -- Get mean and variance for passed table
       -- Build the sql statement
       l_sqlstr := 'SELECT ';
       FOR i IN 2 .. src_col_cnt LOOP
          l_sqlstr := l_sqlstr||'AVG('||src_tab(i).col_name||'),'||
                'VARIANCE('||src_tab(i).col_name||'),';
       END LOOP;
       -- l_sqlstr is now:
       -- SELECT AVG(col1), VARIANCE(col1),AVG(col2), VARIANCE(col2),
       --        AVG(col3), VARIANCE(col3),
       -- So trim the trailing , and add FROM
       l_sqlstr := RTRIM(l_sqlstr,',');
       l_sqlstr := l_sqlstr||' FROM '||p_src_tab;
       -- Set up the cursor
       mv_cur := DBMS_SQL.OPEN_CURSOR;
       DBMS_SQL.Parse(mv_cur, l_sqlstr, DBMS_SQL.Native);
       -- Getting 2 results (AVG and VARIANCE) for each column
       -- and we know that they are all numeric
       -- but need to ignore the id column so
       FOR i In 1 .. (src_col_cnt - 1) * 2 LOOP
          DBMS_SQL.DEFINE_COLUMN(mv_cur, i, l_dummyn);
       END LOOP;
       -- Now Run the query and assign columns into associative array
       l_ignore := DBMS_SQL.EXECUTE_AND_FETCH(mv_cur);
       l_col_pos := 2;  -- start in Record 2 of src_tab
       l_res_pos := 1;  -- start in Column 1 of result set
       WHILE l_col_pos <= src_col_cnt LOOP
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos, mean_cols(src_tab(l_col_pos).col_name));
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos + 1, var_cols(src_tab(l_col_pos).col_name));
          l_col_pos := l_col_pos + 1;
          l_res_pos := l_res_pos + 2;
       END LOOP;
       -- I end up with two associative arrays, both indexed by column name
       -- mean_cols values are the average for each column
       -- var_cols values are the variance for each column
       -- We're done with this query so
       DBMS_SQL.Close_Cursor(mv_cur);
    -- END replacement FOR scale_rec IN LOOP
       -- Build the insert statement
       -- I took the ABSolute value of the SUM of L(i) because with
       -- my data I was getting negative values which blew the SQRT
       l_sqlstr := 'INSERT INTO diag SELECT :src_id, id, SQRT(ABS(';
       FOR i IN 2 .. src_col_cnt LOOP
          -- Dynamically create bind variables to hold "fixed" values
          -- (i.e. reference values, mean, and variance
          -- and plug the correct column names for the target columns
          l_x1 := ':sc'||i; -- For i = 2 gives :sc2
          l_x2 := src_tab(i).col_name; -- For i = 2 gives COL1
          l_meani := ':mean'||i; -- For i = 2 gives :mean2
          l_vari := ':var'||i; -- For i = 2 gives :var2
          -- Append this column formula to sql statement
          l_sqlstr := l_sqlstr ||'(POWER(('||l_x1||' - '||l_meani||
                      ')/'||l_vari||', 2) - POWER(('||l_x2||' - '||
                      l_meani||')/'||l_vari||', 2)) + ';
       END LOOP;
       -- Here, l_sqlstr is:
       -- INSERT INTO diag
       -- SELECT :src_id, id, SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) -
       --                               POWER((col1 - :mean2)/:var2, 2))+
       --                              (POWER((:sc3 - :mean3)/:var3, 2) -
       --                               POWER((col2 - :mean3)/:var3, 2))+
       --                              (POWER((:sc4 - :mean4)/:var4, 2) -
       --                               POWER((col3 - :mean4)/:var4, 2))+
       -- so get rid of the trailing + and space
       l_sqlstr := RTRIM(l_sqlstr,'+ ');
       -- Now close the open bracket from SQRT and ABS and add FROM and WHERE
       l_sqlstr := l_sqlstr||')) FROM '||p_src_tab||' WHERE id <> :src_id';
       -- Now we have a valid insert statement so
       -- Prepare and parse the insert cursor
       ins_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(ins_cur, l_sqlstr, DBMS_SQL.Native);
       -- bind in the mean and variance which are fixed for this set of columns
       FOR i IN 2 .. src_col_cnt LOOP
          DBMS_SQL.Bind_Variable(ins_cur,':mean'||i, mean_cols(src_tab(i).col_name));
          DBMS_SQL.Bind_Variable(ins_cur,':var'||i, var_cols(src_tab(i).col_name));
          -- for i = 2, These two calls resolve as:
          -- DBMS_SQL.Bind_Variable(ins_cur,:mean2, mean_cols(COL1));
          -- DBMS_SQL.Bind_Variable(ins_cur,:var2, var_cols(COL1));
          -- which means bind the value found in mean_cols('COL1') to
          -- the bind variable :mean2 and the value found in var_cols('COL1') to 
          -- the bind variable :var2
       END LOOP;
       -- Get the reference IDs
       FOR intrest_rec IN (SELECT ref_id FROM query) LOOP
          -- For each reference ID bind into the source query
          DBMS_SQL.Bind_Variable(src_cur,':src_id', intrest_rec.ref_id);
          -- So, here, on the first iteration, we are about to execute
          -- the statement
          -- SELECT * FROM t WHERE id = 1     
          l_ignore := DBMS_SQL.Execute_And_Fetch(src_cur);
          -- Get the column values from each source row and
          -- bind that value (e.g. 1 in my sample) to variable :src_id
          DBMS_SQL.Bind_Variable(ins_cur,':src_id', intrest_rec.ref_id);
          FOR i IN 2 .. src_col_cnt LOOP
             -- Retrieve the value of each column of the source row
             -- into the table of NUMBERS
             DBMS_SQL.COLUMN_VALUE(src_cur, i, src_cols(i));
             -- Then bind it into the insert cursor
             DBMS_SQL.Bind_Variable(ins_cur,':sc'||i, src_cols(i));
          END LOOP;
          -- execute the insert statement
          l_ignore := DBMS_SQL.EXECUTE(ins_cur);
       END LOOP;
       COMMIT;
       DBMS_SQL.Close_Cursor(src_cur);
       DBMS_SQL.Close_Cursor(ins_cur);
    END;If you still have questions, I will be around until Thursday, then back January 4.
    John

  • Totalling Averages

    Hi,
    I have a column of averages in a report. I need to total them, which
    obviously means taking the average of all the averages, not just totalling the
    averages. I am using a pivot table. Even when I set the 'Average' on the column within
    the Pivot table view:
    Column -> More Options -> Aggregation Rule -> Average
    it doesn't seem to be totalling the averages correctly on the totals line.
    Is there anything for the totals line itself, which is doing other totals on the
    same line which aren't averages, I should be doing so get the average total column to
    calculate properly.
    Thanks for any ideas.
    - Alan.

    Duplicate question:
    Totalling Averages
    Alan please close this one so people only reply in one place.

  • Difference Between the grouped column

    Hi ,
    I have matrix based report in which the columns are dynamically generated based on the month and year.
    3 filter value in the report
    quarter,
    year and
    Previous 12 months .
    Katherine community moderator reporting services helped me achieving the with a similar kind of report. Due to some difference from the previous requirement am posting a new question .
    Current Matrix Outcome :
    Desired Outcome
    Please note that the Month columns are dynamically generated so for example if the filter value is quarterly 
    3 months will be generated , march-14,april-14,may-14 and then i need to display the difference
    in new columns like march-14 - april-14 ,april-14-may-14. The column headers of the new differential columns i can achieve
    but the difference between the types on monthly basis am unable to achieve.
    Similarly it goes for the yearly and previous 12 months filter value.
    Kindly let me know if more detail is required .
    Thanks
    Priya

    Hi Priya,
    According to your description, you have a matrix in your report. Now for each month, you want to always get the difference value between current month and previous month with columns generated. Right?
    In Reporting Service, if we want to compare values of two adjacent columns in a matrix, the best way is using custom code to deal with the logic. In this scenario, we want to compare the current value with previous value. The difference value is always along
    with columns generated. So we suggest put this column inside of group instead of appending them at the end of the matrix. In this column, we can call the function defined in the custom code. We have tested this case in our local environment. Here are steps
    and screenshots for your reference:
    Put the custom code into report:
    Private queueLength As Integer = 2
    Private queueSum As Double = 0
    Private queueFull As Boolean = False
    Private idChange As String=""
    Dim queue As New System.Collections.Generic.Queue(Of Integer)
    Public Function CumulativeQueue(ByVal currentValue As Integer,id As String) As Object
    Dim removedValue As Double = 0
    If idChange <> id then
            ClearQueue()
                    idChange = id 
                    queueSum = 0 
                    queueFull = False
                    CumulativeQueue(currentValue,id)
    Else  
                    If queue.Count >= queueLength Then
                                    removedValue = queue.Dequeue()
                    End If
                    queueSum += currentValue
                    queueSum -= removedValue
                    queue.Enqueue(currentValue)
                    If queue.Count < queueLength Then
                    Return Nothing
                    ElseIf queue.Count = queueLength And queueFull = False Then
                    queueFull = True
                    Return (queueSum-currentValue-currentValue) 
                    Else
                    Return (queueSum-currentValue-currentValue) 
                    End If
    End If
    End Function
    public function ClearQueue()
    Dim i as Integer
    Dim n as Integer = Queue.Count-1
    for i=n To 0 Step-1
                    queue.Dequeue()
    next i
    End function
    Create a matrix based on your information. Put expression into corresponding position.
    A: =Code.CumulativeQueue(Fields!Amount.Value,Fields!Type.Value)
    B: =IIF(Previous(Fields!Month.Value) is nothing,"",MonthName(IIF(Previous(Fields!Month.Value) is nothing,1,Previous(Fields!Month.Value)))&" - "&MonthName(Fields!Month.Value))
    C: =MonthName(Fields!Month.Value)
    Ps : You may need to modify the custom code and expression based on the data type in your dataset.
    Create parameter for filtering data.
    Save and preview. It looks like below:
    Reference:
    SSRS 2008 R2 - Add moving average to column group
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou
      

  • Runnning averages for a gradesheet

    Ok, so I had this nice, amazing, single formula that did exactly what I needed without accessesing separate tables.  The problem is that I lost it (and everything else) when the dog knocked my macbook off the couch and crashed the hard drive.  Sadly, I cannot figure how I did it in the first place...here's my issue.
    I have a Header column with student's names, and then two header rows, one with the assignment name, and a second with the value for said assignment, looks like this:
                   A                      B                 C               D                 E                    F
    1         Name               Lab 1          Lab 2          Lab 3          Lab 4          Average
    2                                    50               40                50               20               %
    3         Dave
    4         Steve
    5         Sarah
    The second row is the maximum value of points that can be obtained on that assignment.  I need the equation for the average to only account for cells in which a grade value has been entered.  Basically if I have entered in grades for columns B, C, and D, I only want the average to reflect those, and not count and empty E column against the average.  Also, I had it where a dash, or '-' was just seen as an empty cell, not sure how I managed that either.  I think I remember the formula using a good amount of IF's and LOOKUPS....I'm just drawing such a blank
    If someone can help me get started, maybe formatting the first two or three rows, I could take it from there, and be eternally thankful!

    Would this work? Ignore the 'marks', they're there to give me predictable results.
    Formulas:
    F3, filled down to F10: =IF(COUNT($B3:$E3)>0,SUM($B3:$E3)/SUMIF($B3:$E3,">0",$B$2:$E$2),"")
    B11, Filled right to E11: =AVERAGE(B)/B$2
    F11: =AVERAGE(F)
    Column F and (Footer) Row 11 cells formatted as Percentage.
    Error triangle in E11 is due to a division by zero error. It can be ignored, or avoided by wrapping formulas in this row in an IFERROR statement, or by using an IF statement similar to the one used in column F.
    Regards,
    Barry

  • SYS_REFCURSOR takes more time than direct query execution

    I have a stored proc which has 4 inputs and 10 output and all outputs are sys_refcursor type.
    Among 10 ouputs, 1 cursor returns 4k+ records and all other cursors has 3 or 4 records and average 5 columns in each cursors. For this, it takes 8 sec to complete the execution. If we directly query, it gives output in .025 sec.
    I verified code located the issue with cursor which returns 4k+ only.
    The cursor opening from a temporary table (which has 4k+ records ) without any filter. The query which inserted into temporary is direct inserts only and i found nothing to modify there.
    Can anyone suggest, how we can bring the results in less than 3 sec? This is really a challenge since the code needs to go live next week.
    Any help appreciated.
    Thanks
    Renjish

    I've just repeated the test in SQL*Plus on my test database.
    Both the ref cursor and direct SQL took 4.75 seconds.
    However, that time is not the time to execute the SQL statement, but the time it took SQL*Plus in my command window to print out the 3999 rows of results.
    SQL> create or replace PROCEDURE TEST_PROC (O_OUTPUT OUT SYS_REFCURSOR) is
      2  BEGIN
      3    OPEN  O_OUTPUT FOR
      4      select 11 plan_num, 22  loc_num, 'aaa' loc_nm from dual connect by level < 4000;
      5  end;
      6  /
    Procedure created.
    SQL> set timing on
    SQL> set linesize 1000
    SQL> set serverout on
    SQL> var o_output refcursor;
    SQL> exec test_proc(:o_output);
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.04
    SQL> print o_output;
      PLAN_NUM    LOC_NUM LOC
            11         22 aaa
            11         22 aaa
            11         22 aaa
            11         22 aaa
            11         22 aaa
    3999 rows selected.
    Elapsed: 00:00:04.75
    SQL> select 11 plan_num, 22  loc_num, 'aaa' loc_nm from dual connect by level < 4000;
      PLAN_NUM    LOC_NUM LOC
            11         22 aaa
            11         22 aaa
            11         22 aaa
            11         22 aaa
            11         22 aaa
            11         22 aaa
    3999 rows selected.
    Elapsed: 00:00:04.75
    That's the result I expect to see, both taking the same amount of time to do the same thing.
    Please demonstrate how you are running it and getting different results.

  • How do I reference a cell in a matrix that performs the aggregate?

    Assuming I have a Matrix such as:
    Year
    Customer Name SUM(sales amount)
    ... and the text control the aggregate takes place in (the sum function) is named "matrix1_tb_sum"...
    After the report is executed, there will be a column for each year.  Let's say 2013 and 2014 both return.
    What will be the name of the text control for each year?  If I reference "ReportItems!matrix1_tb_sum.Value" from any scope it returns the value of the "right most" column grouping.  How do I reference other column groupings?
    My goal is to add out-of-grouping columns to the right to show additional data, but I don't want to re-type the formulas.  For example, I would add an out-of-group column to the right and add something like:
    =ReportItems!matrix1_tb_sum[2014].Value - ReportItems!matrix1_tb_sum[2013].Value
    ...to show the difference between the two columns without making a SUM IIF.

    Hi Mini Button,
    Base on your description, you have a matrix in your report which you want to add an aggregation field of the Sales Amount for each year and finally add an column to show the difference between two years. Right?
    In Reporting Service, if we want to compare values of two adjacent columns in a matrix, the best way is using custom code to deal with the logic. I have tested in our local environment. In this scenario, we can compare the current value with previous value.
    The difference value is always along with columns generated. So we suggest put this column inside of group instead of appending them at the end of the matrix. In this column, we can call the function defined in the custom code. Here are steps and screenshots
    for your reference:
    Custom code:
    Put the custom code into report:
    Private queueLength As Integer = 2
    Private queueSum As Double = 0
    Private queueFull As Boolean = False
    Private idChange As String=""
    Dim queue As New System.Collections.Generic.Queue(Of Integer)
    Public Function CumulativeQueue(ByVal currentValue As Integer,id As String) As Object
    Dim removedValue As Double = 0
    If idChange <> id then
    ClearQueue()
    idChange = id
    queueSum = 0
    queueFull = False
    CumulativeQueue(currentValue,id)
    Else
    If queue.Count >= queueLength Then
    removedValue = queue.Dequeue()
    End If
    queueSum += currentValue
    queueSum -= removedValue
    queue.Enqueue(currentValue)
    If queue.Count < queueLength Then
    Return Nothing
    ElseIf queue.Count = queueLength And queueFull = False Then
    queueFull = True
    Return (queueSum-currentValue-currentValue)
    Else
    Return (queueSum-currentValue-currentValue)
    End If
    End If
    End Function
    public function ClearQueue()
    Dim i as Integer
    Dim n as Integer = Queue.Count-1
    for i=n To 0 Step-1
    queue.Dequeue()
    next i
    End function
    Click the report Properties and click the “Code” than add above custom code in it, click ok.
    Create a matrix based on your information. Put expression into corresponding positions:
    Expression in the first row: =IIF(Previous(Fields!Year.Value) is nothing,"",IIF(Previous(Fields!Year.Value) is nothing,1,Previous(Fields!Year.Value))&" - "&Fields!Year.Value)
    Expression in the second row: =Code.CumulativeQueue(Fields!SalesAmount.Value,Fields!CustomerName.Value))
    Expression in the third row: =Code.CumulativeQueue(sum(Fields!SalesAmount.Value),Fields!CustomerName.Value)
    Note : You may need to modify the custom code and expression based on the data type in your dataset.
    Save and preview. It looks like below:
    Below similar threads are for your reference:
    SSRS 2008 R2 - Add moving average to column group
    Difference Between the grouped column
    If you still have any question, please feel free to ask.
    Regards
    Vicky Liu

Maybe you are looking for

  • How can I test the SCORM 2004 compliant based output from captivate

    Hi everyone, I have created a SCORM 2004 compliant based output file from Captivate itself. Before sharing it with client, I want to check that whether it is compliant or not. Is there any tool to check the compliance check in LMS? I am new to this,

  • Responsive Charts

    Hi I'm trying to make charts responsive in APEX 4.2.1. The problem is that you can't define percentage values in the apex builder for the width and the height of the chart. Now when I look in the javascript source code (#IMAGE_PREFIX#libraries/apex/w

  • JRE 1.5 crashed

    Hi, I have encounter a problem where by the JVM crashed. As I know the way to solve this problem is dependant on the reason that cause it crashed (Correct me if I'm wrong). Below is the log that i get. Can anyone who understand the log file explain w

  • No Enterprise Manager - 500 error

    I have installed CF9 Enterprise (32bit install) on a Windows 2008 Server SP2, 32 bit server (two of them, in fact), with Web Server / IIS role installed. Installed Role Services of  Application Development (ASP.NET, ASP, CGI, ISAPI extensions/filters

  • Manual transfer *replaced* my iPod contents! How prevent this?

    New iPod owner here... I have a very large collection of music on my hard drive already (I have a Squeezebox). Much of this is in FLAC and WMA formats, but there's enough mp3 content to get going. Ultimately, it is my intention not to even try to kee