Count&Count Distinct

Hi Gurus,
In one of OBIEE blogs I studied "Aggregation should only be performed on measure columns, with the possible exception of the aggregation COUNT and Count Distinct"....my Question is what happens if we apply count&count distinct aggregation rules to measures because we are using that in our project,what are problems we will face?

User wrote:
you mean it executes a sub query internally to count and later it sum the result..correct.- You can ship the total calculations to the underlying RDBMS if 'Report Based Total' is not ticked, otherwise if it is, the BI Server computes the subtotal.
and in your answers "No" mean results coming by putting sum in criteria are different ..right- Yes thats what I mean, sorry if unclear - Are your totals correct now? Failing that try 'server complex aggregate' but this is usually only requried if your deriving calculations in Answers (ie % of total etc).

Similar Messages

  • I want a count of distinct rows in a table

    I want a count of distinct rows in a table through a single query -- is it possible?
    eg.
    table-
    create table ch1 (a int, b int, c int, d int)
    insert ch1 values (1,1,1,1)
    insert ch1 values (2,2,2,2)
    insert ch1 values (1,1,1,1)
    insert ch1 values (2,2,2,2)
    insert ch1 values (1,3,4,5)

    hi,
    create table ch1 (a int, b int, c int, d int) ;
    insert into  ch1 values (1,1,1,1);
    insert into  ch1 values (2,2,2,2);
    insert  into  ch1 values (1,1,1,1);
    insert into  ch1 values (2,2,2,2);
    insert into  ch1 values (1,3,4,5);
    SQL> select * from ch1;
             A          B          C          D
             1          1          1          1
             2          2          2          2
             1          1          1          1
             2          2          2          2
             1          3          4          5
    SQL> select distinct * from ch1;
             A          B          C          D
             1          1          1          1
             1          3          4          5
             2          2          2          2
    SQL>
      1* select count(*) from( select distinct * from ch1)
    SQL> /
      COUNT(*)
             3
    SQL> ed
    Wrote file afiedt.buf
      1   select count(*) from (select a,b,c,d  from ch1
      2* group by a,b,c,d)
    SQL> /
      COUNT(*)
             3
    SQL> Thanks,
    P Prakash

  • How to get the count of distinct customer in matrix?

    Hi,
    I want to get the count of distinct customer in matrix at the time of validation event.
    Thanks Regards,

    Hi,
    Please close the thread.by marking the correct answer
    regards,
    Prasad

  • Count a distinct column value in an interactive report

    Hi,
    I'm struggling with this and would appreciate any pointers.
    I have built a view here:
    http://apex.oracle.com/pls/otn/f?p=11189:1
    The report can have duplicate column values. I'm tying to find a way using the interactive report functionality (i.e. without modifying the underlying SQL) to count a distinct column value. For example, in the example following the link I'd like to be able to count the unique customer_ids and return 7.
    This may be fundametally impossible depending on the way the SQL is generated for the interactive reports. If this is the case can anyone confirm this?
    Many thanks
    Yog.

    <B>"Not modifying views is fair enough. But not wrapping a SELECT around them? Really? Why? And as I said, that's imposible, the IR already does it."</B>
    This is not a problem. However for the IR's it's a development decision to keep all reported columns ( and analysis on these columns ) as a seperate development process to be controlled centrally by a seperate team. The point to remember is that the app looks at hundereds of views and it was decided that modifying each report to fit each instance would become cumbersome to manage and to put it simply there are not the resources to do it.
    again, I'm not here to justify any of that!
    <B>SELECT *" ? Every single time? Even when you want to populate a LOV with some names</B>
    No just the Reports. It is a very very simple app; a big list an a page for each report.
    <B>"I think you should always ask what you want, not less, not more"</B>
    I agree, and that should include select * from view.
    <B>"Why fetch data you don't want to see"</B>
    Some users will want to see some data from the view and other users will want to see other data, Over the whole user base someone somewhere will want to see all of it.
    <B> Actually, there is something good in this, in the future, when you will be asked to check and try to improve the load time of some page, here is the first place where you should look</B>
    Brilliant! Like it!!
    <B>Does it by any chance fetch a bunch of 20 meg LOBS and then discards them</B>
    No, Thankfully a few varchar2 columns and a lot of numeric columns, nothing huge. The reports are acutally pretty fast at the moment...

  • Getting the count of DISTINCT of several columns

    How can i get the count of DISTINCT of several columns?
    SQL> select count(distinct ename) from emp;
    COUNT(DISTINCTENAME)
                      14
    SQL> select count(distinct ename, job) from emp;
    select count(distinct ename, job) from emp
    ERROR at line 1:
    ORA-00909: invalid number of arguments

    Hello,
    You should separate them out like this
    select count(distinct ename), count(distinct job) from emp;Regards

  • Having count- count(count(1))

    I have two queries below- first of which outputs one record, the Second query doesn't.
    Can you explain why First query returns always records, at least one record? In explanation, can you say which process is runned after which (something like where is runned firstly, then group by, then...)?
    --First:
    select count(count(1)) from dual
    where 1=2
    group by dummy
    having count(dummy) > 0;--1 row, value: 0
    --Second:
    select count(1) from dual
    where 1=2
    group by dummy
    having count(dummy) > 0;--0 rows

    Hi,
    Aggregate queries with nested aggregate functions (such as "COUNT (COUNT (1))") always return exactly 1 row, even if there are no rows in the table (or, as in your first example, no rows survive the WHERE clause).
    The outer layer of nested aggreate functions is evaluated after the GROUP BY and HAVING clauses have been applied.
    If you have a GROUP BY clause, but no nested aggregate fucntions, then the output contains one row for every distinct group, subject to the WHERE- and HAVING clauses. In your second example, no rows are left after the WHERE clause, so there will be no rows in the output.
    You can think of things as happening in this order
    (1) WHERE
    (2) GROUP BY
    (3) (inner) aggregate fucntions
    (4) HAVING
    (5) Nested aggregate functions
    The optimizer may not actually follow the steps above, but you won't notice that.
    Edited by: Frank Kulash on Mar 25, 2010 11:51 AM
    The following thread may help you:
    Re: group function

  • How to make the counter count or start at different time

    Hi,
    How to let the counter count the time, that doesn't start at the same time ?
    This timing system is a sport timing system for canoe competition, it need to track 6 competitor that start at different time .
    I have a problem , I have 6 counter in a VI that use to track 6 competitor, but it start count at the same time, how to make it count separately for each competitor ?
    Do you guys know how to solve this problem ?
    Solved!
    Go to Solution.
    Attachments:
    multi competitor.zip ‏50 KB

    HI, 
    ya, i run it. I mean i know how to make it to 6 competitor already , and yes, it works but the time, it still count or start at the same time. I  need to run each competitor at different time , like this competitor A 20-2-2012.VI . This is the one i do but it cant put a stop button. once i put a stop button, the clock stop counting but the whole VI is running.
    Regadrs,
    Sam
    Attachments:
    competitor A 20-2-2012.vi ‏139 KB
    3switch 3-2-2012.vi ‏14 KB

  • Count(1),count(*),count(rowid)

    i found from oracle book that
    count(1)--fast
    count(*)--slow
    count(rowid)--fast
    but in this forum lot is said about the count function.and i.e count(1)=count(*)=count(rowid)
    then why even in the book fast & slow is mentioned.
    so does oracle internally converts count(*) to count(1) or really fast and slow comes into picture
    thanks

    If you read the various threads on this forum as well as on AskTom, you will see that Oracle internally converts count(<some constant>) to count(*) as part of the query rewrite, so they are essentially identical.
    When you start counting on rowid or particular columns then things can differ a little, but essentially ... not much.

  • Count or "distinct count" number of items in SAP BI 3.5

    Hi all,
    I have a requirement that goes like this:
    In an ODS-object there are two characterisitics among others. Against each client there are several numbers of articles.
    01. I have to count the number of articles against each client.
    02. I have to count the number of distinct articles over all clients.
    Do you think there's a chance to solve BOTH requirements in Query Desinger only? I actually do NOT want to modify the respective ODS or MultiProvider configurations.
    Client --- Article --- Nr. of entries
    301 --- A1000 --- 50
    301 --- A2000 --- 100
    301 --- A3000 --- 50
    302 --- A1500 --- 50
    302 --- A2500 --- 100
    302 --- A3000 --- 50
    303 --- A2000 --- 10
    303 --- A3000 --- 50
    Following is a sample how the results should look like:
    Task "1":
    Client --- Nr. of different articles
    301 --- 3
    302 --- 2
    303 --- 2
    Task "2":
    Nr. of different articles over all clients
    5
    Any pointers about this are most welcome.
    Kind regards,
    Thorsten.

    Hi,
    I'm not sure the count function works in 3.5 since you can't set the proper aggregation setting. You can try the following however:
    Create a new calculated key figure
    In this, create a new formula variable
    Set the formula variable to replacement path
    Choose the infoObject you want to count as replacement object
    Set the replace by to attribute value
    Choose attribute reference, (constant 1)
    Use the formula variable in your calculated key figure.
    Hope it helps.
    Kind regards,
    Alex

  • Filtering- Getting count of distinct doc after filtering

    HI Gurus!
    I have a report that shows the sales order report . In its ALV ouptput I have created a count column which gives me the number of lines in the report and also I have created the top of page in which it gives me the number of distinct sales document numbers count . I.e for a particular selection the count of line items are say 765 and the number of distinct sales documents are 70  which I have printed on the top of the page in the layout. Now if we do some kind of filtering process in the output the number of sales documents printed on top of page remains the same while the coumnt of line items changes a sper the filtering . The count on the top of page for the sales order dosent change as it prints the number from the internal table which is understandable. But is there a possibility that I create another column next to the sales doc number column and at the beginning of each of the new sales document it prints one and for all the other duplicates it prints 0 and then do the sum for it , so that even on filtering it gives me the count that remains after filter while the total number of distinct sale doc remains on top from the internal table.
    Is this possible to do so that I get thenumber of sales doc even after filter process?
    If so please advice how to get it.
    Regards

    Well as of now my report does sommething like this.
    *& Report  ZSD_SALES_ORDERS                                            *
    *&         Sales Orders Report (tcode zva05)                           *
    *&         i.e. For 'admins'/oil field application                     *
    report  zztest message-id zsd no standard page heading.
    * For ALV usage
    type-pools: slis.
    data: gs_layout   type slis_layout_alv,
          tp_print    type slis_print_alv,
          gt_sort     type slis_t_sortinfo_alv,
          gt_events   type slis_t_event,
          t_fieldcat  type slis_t_fieldcat_alv with header line,
          repid       type syrepid,               " ABAP Program.
          gt_list_top_of_page type slis_t_listheader,     " Top of page text.
          alv_variant   type disvariant.           " Customize Disp. Variant
    data: w_field    type slis_fieldcat_alv.
    data: gs_list_top_of_page type slis_listheader.
    data: l_count type I.
    data: count1 type I.
    tables: vbak, vbap, vbpa, knvv.
    * Definition of selection screen                                       *
    *   By plant, storage location, sold-to customers, material and        *
    *   posting date of the sales orders                                   *
    selection-screen begin of block one with frame title text-001.
    parameters:     p_vkorg  type vkorg obligatory memory id vko,"DEVK906677
                    p_vtweg  type vtweg obligatory default '01',
                    p_spart  type spart obligatory default '01'.
    select-options: s_vkbur  for  vbak-vkbur,      " Sales Office     "DEVK906677
                    s_kunnr  for  vbak-kunnr.      " Sold-to customer number.
    select-options: s_shipto for  vbap-oid_ship,   " Ship-to customer number.
                    s_billto for  vbpa-kunnr,      " bill-to from S.O. header.
                    s_load   for  vbpa-kunnr,      " Load confirmation contact.
                    s_truck  for  vbap-oid_extbol. " Trucking ticket number.
    select-options: s_werks for vbap-werks obligatory no intervals. " Plant.
    select-options: s_lgort for vbap-lgort.        " Storage location.
    select-options: s_matnr for vbap-matnr.        " Material number.
    select-options: s_konda for knvv-konda.        " price group
    selection-screen skip 1.
    select-options: s_vdatu for vbak-vdatu default sy-datum.
    selection-screen end of block one.
    * ALV display layout
    selection-screen begin of block layout with frame title text-003.
    parameters: pa_vari type slis_vari default ' '. " Display variant.
    selection-screen end of block layout.
    selection-screen begin of block two with frame title text-028.
    selection-screen comment: /1(79) text-029.
    selection-screen comment: /1(79) text-030.
    selection-screen comment: /1(79) text-031.
    selection-screen comment: /1(79) text-032.
    selection-screen comment: /1(79) text-033.
    selection-screen comment: /1(79) text-034.
    selection-screen comment: /1(79) text-035.
    selection-screen comment: /1(79) text-036.
    selection-screen end of block two.
    * Data Definitions                                                     *
    * Storing Extracted Info.
    types: begin of t_extract,
             vbeln        type vbeln_va,   " Sales order number.
             augru        type augru,      " order reason
             vdatu        type edatu_vbak, " Requested delivery date.
             kunnr        type kunag,      " Sold-to customer number.
             posnr        type posnr_va,   " Item number.
             matnr        type matnr,      " Material number.
             vrkme        type vrkme,      " Sales UoM.
             mseh3        type mseh3,      " UoM text.
             netwr        type netwr_ap,   " Net value of the order item.
             kwmeng       type p length 13 decimals 1, " Quantity.
             werks        type werks_d,    " Plant.
             lgort        type lgort_d,    " Storage location.
             oid_extbol   type oid_extbol, " External BOL or truck ticker header.
             maktx        type maktx,      " Material description.
             soldto_name  type name1_gp,   " Sold-to name.
             oid_ship     type kunwe,      " Ship-to customer number.
             shipto_name  type name1_gp,   " Ship-to name.
             billto       type kunre,      " Bill-to customer number.
             billto_name  type name1_gp,   " Bill-to name.
             load_contact type kunnr,      " Load confirmation contact.
             load_name    type name1_gp,   " Load confirmation contact name.
             truck        type kunnr,      " Truck company number.
             truck_name   type name1_gp,   " Truck company name.
             bstkd        type bstkd,      " PO number.
             ihrez        type ihrez,      " AFE number per the contract/sales order.
             delivery     type vbeln_vl,   " Delivery number.
             posnr_vl     type posnr_vl,   " Delivery item number.
             bill_vbeln   type vbeln_vf,   " Invoice number.
             bill_posnr   type posnr_vf,   " Invoice item number.
             bill_netwr   type netwr_fp,   " Invoice net value.
             statu        type stats,      " Document status.
             auart        type auart,      " order type
             vkorg        type vkorg,      " sales org.
             vtweg        type vtweg,      " distrbtn channel
             spart        type spart,      " division
             vkbur        like vbak-vkbur, " Sales Office DEVK906677
             konda        type konda,      " price group
             tdline       type tdline,     " text for customer account reference
             count        type I ,
             count1       type I,
           end of t_extract.
    data :
          it_extract  type table of t_extract with header line,
          it_extract2 type table of t_extract with header line.
    data: it_text type table of tline with header line.
    data: w_index type sy-index,
          w_tdname type tdobname.
    constants: c_minus1       type netwr_ap value '1.00-'.
    *RANGES: r_auart FOR vbak-auart.
    data: r_auart type range of t_extract-auart,
          r_auart_line like line of r_auart.
    * initialization
    initialization.
      gs_layout-colwidth_optimize = 'X'.
      tp_print-no_print_listinfos = 'X'.
      tp_print-no_coverpage = 'X'.
      perform set_fieldcat.
      perform alv_eventtab_build using:
    **    Event name     Form to execute     Event internal table
       'TOP_OF_PAGE'  'TOP_OF_PAGE'       gt_events[].
    * changed to exclude following order types
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZEQ'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * credit memo
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZPRC'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * debit memo
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZPRD'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZDR'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * Industry sales order correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZSOC'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * oilfield FF correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZOCF'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * oilfield WP correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZOCW'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * Dropdown list for all created ALV layouts, global or user-specific
    at selection-screen on value-request for pa_vari.
      perform alv_variant_f4 changing pa_vari.
    * Main BODY of processing logic
    start-of-selection.
      perform extract_data.
    end-of-selection.
      if not it_extract[] is initial.
    * Build headings for report.
        perform build_top_of_page  using gt_list_top_of_page[].
        perform call_alv.
      endif.
    *&      Form  EXTRACT_KEY_DATA
    * Retreive the data for the report.
    form extract_data.
      clear: it_extract.  refresh: it_extract.
    * orders
      select vbak~vbeln vbak~auart vbak~augru vbak~vkorg vbak~vtweg
             vbak~spart vbak~vdatu vbak~kunnr vbak~vkbur
             vbap~posnr vbap~matnr vbap~vrkme vbap~netwr vbap~kwmeng
             vbap~werks vbap~lgort vbap~oid_extbol vbap~oid_ship
        into corresponding fields of table it_extract
        from vbak inner join vbap
             on  vbak~mandt = vbap~mandt
             and vbak~vbeln = vbap~vbeln where
        vbak~auart not in r_auart and
        vbak~vkorg eq p_vkorg and
        vbak~vtweg eq p_vtweg and
        vbak~spart eq p_spart and
        vbak~vkbur in s_vkbur and                               "DEVK906677
        vbak~vdatu in s_vdatu and
        vbak~kunnr in s_kunnr and
        vbap~matnr in s_matnr and
        vbap~werks in s_werks and
        vbap~lgort in s_lgort and
        vbap~oid_extbol in s_truck and
        vbap~oid_ship in s_shipto .
      if sy-subrc <> 0.
        message i000 with text-002 ' ' ' ' ' '.
      endif.
      sort it_extract by vbeln.
      check sy-subrc = 0.
      loop at it_extract.
    * Retrieve and select by load confirmation contacts from header
        select single kunnr from vbpa into it_extract-load_contact
         where vbeln = it_extract-vbeln
           and posnr = '000000'
           and parvw = 'ZB'.
        if it_extract-load_contact in s_load.
          it_extract-load_name = zcl_kna1=>get_name1( it_extract-load_contact ).
        else.
          delete it_extract.
          continue.
        endif.
    * Retrieve and select by sales order bill-to on header level
    * as well as lookup bill-to customer name/description
        select single kunnr from vbpa into it_extract-billto
         where vbeln = it_extract-vbeln
           and posnr = '000000'
           and parvw = 'RE'.
        if sy-subrc = 0.
          if s_billto is initial.
            it_extract-billto_name = zcl_kna1=>get_name1( it_extract-billto ).
          else.
            if it_extract-billto in s_billto.
              it_extract-billto_name = zcl_kna1=>get_name1( it_extract-billto ).
            else.
              delete it_extract.
              continue.
            endif.
          endif.
        else.
    * Newalta - always has bill-to, following will not occur but included
    *           as good programming practice.
          it_extract-billto_name = it_extract-billto.
        endif.
    * Retrieve and select by price group of sold-to
        select single konda from knvv into it_extract-konda
         where kunnr = it_extract-kunnr
           and vkorg = it_extract-vkorg
           and vtweg = it_extract-vtweg
           and spart = it_extract-spart.
        if sy-subrc = 0.
          if not ( it_extract-konda in s_konda ).
            delete it_extract.
            continue.
          endif.
        endif.
    * Retrieve trucking company customer
        select single kunnr from vbpa into it_extract-truck where
          vbeln = it_extract-vbeln and
          posnr = '000000' and
          parvw = 'ZT'.
        if sy-subrc = 0.
          it_extract-truck_name = zcl_kna1=>get_name1( it_extract-truck ).
        endif.
    * Retrieve sold-to name
        it_extract-soldto_name = zcl_kna1=>get_name1( it_extract-kunnr ).
    * Retrieve ship-to name
        it_extract-shipto_name = zcl_kna1=>get_name1( it_extract-oid_ship ).
    * lookup P.O.
        select single bstkd ihrez from vbkd into (it_extract-bstkd, it_extract-ihrez)
         where vbeln = it_extract-vbeln
           and posnr = '000000'.
    * Retreive the material description.
        it_extract-maktx = zcl_material=>get_maktx( it_extract-matnr ).
    * cosmetic change of material number, donot display leading zeros.
        shift it_extract-matnr left deleting leading '0'.
    * translate unit of measure
        it_extract-mseh3 = it_extract-vrkme.
        select single mseh3 from t006a into it_extract-mseh3
         where spras = sy-langu
           and msehi = it_extract-vrkme.
        w_tdname = it_extract-vbeln.
    * read customer account reference which is under 'text'
        call function 'READ_TEXT'
          exporting
            client                        = sy-mandt
            id                            = 'Z010'
            language                      = sy-langu
            name                          = w_tdname
            object                        = 'VBBK'
    *   ARCHIVE_HANDLE                = 0
    *   LOCAL_CAT                     = ' '
    * IMPORTING
    *   HEADER                        =
          tables
            lines                         = it_text
          exceptions
            id                            = 1
            language                      = 2
            name                          = 3
            not_found                     = 4
            object                        = 5
            reference_check               = 6
            wrong_access_to_archive       = 7
            others                        = 8.
        if sy-subrc = 0.
          read table it_text index 1.
          if sy-subrc = 0.
            it_extract-tdline = it_text-tdline.
          else.
            clear it_extract-tdline.
          endif.
        else.
          clear it_extract-tdline.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        endif.
    * Get the delivery item.
        call method zcl_vbap=>get_delivery
          EXPORTING
            itp_vbeln = it_extract-vbeln
            itp_posnr = it_extract-posnr
          IMPORTING
            etp_vbeln = it_extract-delivery
            etp_posnr = it_extract-posnr_vl.
        if it_extract-delivery is not initial.
          perform process_deliveries.
        else.
          perform invoice_process.
        endif.
        it_extract-count =   1.
        move-corresponding it_extract to it_extract2.
        append it_extract2.
        at new vbeln.
          count1 = count1 +  1.
        endat.
      endloop.
    endform.                    " EXTRACT_DATA
    *&      Form  SET_FIELDCAT
    * Create the field catalogue.
    form set_fieldcat .
      clear w_field.
      clear t_fieldcat.  refresh t_fieldcat.
      w_field-col_pos = 1.
      w_field-fieldname = 'VBELN'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Document.Nbr'.
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 2 .
      w_field-fieldname = 'POSNR'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Item'(023).
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 3 .
      w_field-fieldname = 'VDATU'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Req. Del. Date'(005).
      append w_field to t_fieldcat.
      w_field-col_pos = 4 .
      w_field-fieldname = 'SOLDTO_NAME'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Sold-to'(006).
      append w_field to t_fieldcat.
      w_field-col_pos = 5 .
      w_field-fieldname = 'MATNR'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Material'(007).
      append w_field to t_fieldcat.
      w_field-col_pos = 6 .
      w_field-fieldname = 'KWMENG'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Quantity'(008).
      append w_field to t_fieldcat.
      w_field-col_pos = 7.
      w_field-fieldname = 'MSEH3'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'UOM'(009).
      append w_field to t_fieldcat.
      w_field-col_pos = 8 .
      w_field-fieldname = 'BILL_VBELN'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Invoice #'(010).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 9 .
      w_field-fieldname = 'BILL_NETWR'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Values'(011).
      append w_field to t_fieldcat.
      w_field-col_pos = 10.
      w_field-fieldname = 'WERKS'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Plant'(012).
      append w_field to t_fieldcat.
      w_field-col_pos = 11.
      w_field-fieldname = 'LGORT'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Storage Loc'(013).
      append w_field to t_fieldcat.
      w_field-col_pos = 12 .
      w_field-fieldname = 'MAKTX'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Description'(014).
      append w_field to t_fieldcat.
      w_field-col_pos = 13 .
      w_field-fieldname = 'SHIPTO_NAME'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Ship-to'(015).
      append w_field to t_fieldcat.
      w_field-col_pos = 14 .
      w_field-fieldname = 'BILLTO_NAME'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Bill-to'(016).
      append w_field to t_fieldcat.
      w_field-col_pos = 15 .
      w_field-fieldname = 'LOAD_NAME'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Load Contact'(017).
      append w_field to t_fieldcat.
      w_field-col_pos = 16 .
      w_field-fieldname = 'TRUCK_NAME'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Truck Comp.'(018).
      append w_field to t_fieldcat.
      w_field-col_pos = 17 .
      w_field-fieldname = 'BSTKD'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'P.O.'(019).
      append w_field to t_fieldcat.
      w_field-col_pos = 18 .
      w_field-fieldname = 'IHREZ'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'AFE Nbr'(020).
      append w_field to t_fieldcat.
      w_field-col_pos = 19 .
      w_field-fieldname = 'OID_EXTBOL'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Truck Ticket'(021).
      append w_field to t_fieldcat.
      w_field-col_pos = 20.
      w_field-fieldname = 'STATU'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Status'(022).
      append w_field to t_fieldcat.
      w_field-col_pos = 21.
      w_field-fieldname = 'AUGRU'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Ord.Reason'(024).
      append w_field to t_fieldcat.
      w_field-col_pos = 22.
      w_field-fieldname = 'TDLINE'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'cstmr.acct.ref.'(027).
      append w_field to t_fieldcat.
      w_field-col_pos = 23 .                                    "DEVK906678
      w_field-fieldname = 'VKBUR'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Sales Office'(037).
      append w_field to t_fieldcat.
      w_field-col_pos = 24.
      w_field-fieldname = 'KUNNR'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Sold-to Customer'(038).
      append w_field to t_fieldcat.
      w_field-col_pos = 25.
      w_field-fieldname = 'OID_SHIP'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Ship-to Customer'(039).
      append w_field to t_fieldcat.
      w_field-col_pos = 26.
      w_field-fieldname = 'BILLTO'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Bill-to Customer'(040).
      append w_field to t_fieldcat.
      w_field-col_pos = 27.
      w_field-fieldname = 'COUNT'.
      w_field-tabname = IT_EXTRACT2.
      w_field-seltext_l = 'Count of line items'(042).
      w_field-do_sum = 'X'.
      append w_field to t_fieldcat.
    endform.                    " SET_FIELDCAT
    *&      Form  CALL_ALV
    * Call the ALV Grid function.
    form call_alv .
      sort it_extract by lgort vbeln.
    * repid is necessary since the ALV F.M. does not work properly with
    * sy-repid.
      repid = sy-repid.
      alv_variant-variant  = pa_vari.
      alv_variant-report   = sy-repid.
      alv_variant-username = sy-uname.
      call function 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = t_fieldcat[]
          it_sort                 = gt_sort[]
          i_default               = 'X'
          i_save                  = 'A'
          is_variant              = alv_variant
          it_events               = gt_events[]
          is_print                = tp_print
        TABLES
          t_outtab                = IT_EXTRACT2
        EXCEPTIONS
          program_error           = 1
          others                  = 2.
      if sy-subrc ne 0.
        message w000 with text-004 ' ' ' ' ' '.
      endif.
    endform.                    " CALL_ALV
    *&      Form  build_top_of_page
    * Build heading for report.                                            *
    *      -->P_GT_LIST_TOP_OF_PAGE[]  Header stuff for report
    form build_top_of_page using   e04_lt_top_of_page type slis_t_listheader.
      data: ls_line type slis_listheader.  "Header table for top of page
    * construct 'top of page' info. to display. In this case, one line.
      data: w_selections(40) type c,
            w_date_from(10) type c,
            w_date_to(10) type c.
      write: s_vdatu-low to w_date_from dd/mm/yyyy.
      if s_vdatu-high is not initial.
        write: s_vdatu-high to w_date_to dd/mm/yyyy.
        clear w_selections.
        concatenate 'Del.Req.Date: ' w_date_from 'To' w_date_to
        into w_selections separated by space.
        clear ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        append ls_line to e04_lt_top_of_page.
        gs_list_top_of_page-typ = 'S'.
        gs_list_top_of_page-info = ' Total number of Sales Documents :'.
        append gs_list_top_of_page to gt_list_top_of_page.
        gs_list_top_of_page-typ  = 'S'.
        gs_list_top_of_page-info =  count1 .
        append gs_list_top_of_page to gt_list_top_of_page.
      else.
        clear w_date_to.
        concatenate 'Del.Req.Date: ' w_date_from
             into w_selections separated by space.
        clear ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        append ls_line to e04_lt_top_of_page.
      endif.
    endform.                    " build_top_of_page
    *&      Form  alv_eventtab_build
    *     Pass list of events to be triggered by the ALV function module
    form alv_eventtab_build using  u_name  type slis_alv_event-name
                                   u_form  type slis_alv_event-form
                                   alv_lt_events  type slis_t_event.
      data: ls_event type slis_alv_event.   " structure for event handling
      ls_event-name = u_name.
      ls_event-form = u_form.
      append ls_event to alv_lt_events.
    endform.                    " alv_eventtab_build
    *       FORM TOP_OF_PAGE                                              *
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          i_logo             = 'LOGO'
          it_list_commentary = gt_list_top_of_page.
    endform.                    " TOP_OF_PAGE
    *&      Form  process_deliveries
    * Process the delivery related records.
    form process_deliveries .
      data:
        ltp_date  type wadat_ist, " Goods movement date.
        ltp_vbtyp type vbtyp_n,
        ltp_mtart type mtart, " Material type.
        w_lfimg   type lfimg, " Actual quantity delivered (in sales units).
        w_vrkme   type vrkme. " Sales unit of measure.
    * Read delivery quantity and uom.
      select single lfimg vrkme into (w_lfimg, w_vrkme)
        from lips where
        vbeln = it_extract-delivery and
        posnr = it_extract-posnr_vl.
    * these fields have values from vbap. override with lips values
      if sy-subrc = 0.
        it_extract-kwmeng = w_lfimg.
        it_extract-vrkme  = w_vrkme.
    * translate unit of measure
        it_extract-mseh3 = it_extract-vrkme.
        select single mseh3 from t006a into it_extract-mseh3
         where spras = sy-langu
           and msehi = it_extract-vrkme.
      endif.
    * Determine STATUS by reading 'service confirmation', R (goods movemt)
    * it is possible to have multiple 'service confirmation' records for
    * one item. ie. delivery 80010390 in PRD.
    * As long as there is at least one 'service confirmation' record,
    * status is considered 'complete'.
    * Validate the created on date of the goods movement or service confirmation.
      ltp_mtart = zcl_material=>get_mtart( it_extract-matnr ).
    *  ltp_date = zcl_lips=>get_goods_movement_date( itp_vbeln = it_extract-delivery
    *                           itp_posnr = it_extract-posnr_vl itp_mtart = ltp_mtart ).
      call method zcl_lips=>get_goods_mvt_info
        EXPORTING
          itp_vbeln = it_extract-delivery
          itp_posnr = it_extract-posnr_vl
          itp_mtart = ltp_mtart
        IMPORTING
          rtp_date  = ltp_date
          rtp_vbtyp = ltp_vbtyp.
    * 'h' is cancel goods issue
      if ltp_vbtyp = 'h'.
        it_extract-statu = 'Incomplete'(025).
      else.
        if ltp_date is not initial.
          it_extract-statu = 'COMPLETE'(026).
        endif.
      endif.
    * Retrieve the invoice/billing document item.
      call method zcl_lips=>get_invoice
        EXPORTING
          itp_vbeln = it_extract-delivery
          itp_posnr = it_extract-posnr_vl
        IMPORTING
          rtp_vbeln = it_extract-bill_vbeln
          rtp_posnr = it_extract-bill_posnr.
      if it_extract-bill_vbeln is not initial.
    * retrieve net value from the invoice.
        clear it_extract-bill_netwr.
        select single netwr into it_extract-bill_netwr from vbrp
         where vbeln = it_extract-bill_vbeln
           and posnr = it_extract-bill_posnr.
      else.
        it_extract-bill_netwr = it_extract-netwr. " Use order net value.
      endif.
    endform.                    " process_deliveries
    *&      Form  user_command
    * Process the user command.
    *      -->R_UCOMM      User command
    *      -->RS_SELFIELD  Field selected
    form user_command using r_ucomm     like sy-ucomm
                            rs_selfield type slis_selfield.
      data: ltp_vbeln type vbeln.  " Sales document number.
      case  r_ucomm.
        when '&IC1'.
          if ( rs_selfield-fieldname = 'VBELN'
            or rs_selfield-fieldname = 'BILL_VBELN' )
           and rs_selfield-value is not initial.        " Display sales document.
            ltp_vbeln = rs_selfield-value.
            zcl_sales_doc=>display( ltp_vbeln ).
          endif.
      endcase.
    endform.                    "user_command
    *&      Form  invoice_process
    * Process for orders without deliveries.                               *
    form invoice_process .
    * Translate unit of measure.
      select single mseh3 from t006a into it_extract-mseh3
       where spras = sy-langu
         and msehi = it_extract-vrkme.
    * Retrieve the invoice/billing document item.
      call method zcl_vbap=>get_invoice
        EXPORTING
          itp_vbeln = it_extract-vbeln
          itp_posnr = it_extract-posnr
        IMPORTING
          rtp_vbeln = it_extract-bill_vbeln
          rtp_posnr = it_extract-bill_posnr.
      if it_extract-bill_vbeln is not initial.
    * retrieve net value from the invoice.
        clear it_extract-bill_netwr.
        select single netwr into it_extract-bill_netwr from vbrp
         where vbeln = it_extract-bill_vbeln
           and posnr = it_extract-bill_posnr.
      else. " If no Invoice, then status becomes 'incomplete'.
        it_extract-bill_netwr = it_extract-netwr. " Use order net value.
        it_extract-statu = 'Incomplete'(025).
      endif.
    endform.                    " invoice_process
    *&      Form  alv_variant_f4
    * Get the display variant.
    *      <--CTP_VARI  Variant name
    form alv_variant_f4 changing ctp_vari type slis_vari.
      alv_variant-report   = sy-repid.             " Report ID
      alv_variant-username = sy-uname.             " User ID
      call function 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = alv_variant
          i_save     = 'A'
        IMPORTING
          es_variant = alv_variant
        EXCEPTIONS
          others     = 1.
      if sy-subrc = 0.
        ctp_vari = alv_variant-variant.
      endif.
    endform.                    " alv_variant_f4

  • Getting Sum, Count and Distinct Count of a file

    Hi all this is a UNIX question.
    I have a large flat file with millions of records.
    col1|col2|col3
    1|a|b
    2|c|d
    3|e|f
    3|g|h
    footer****
    I am supposed to calculate the sum of col1 =9, count of col1 =4, and distinct count of col1 =c3
    I would like it if you avoid external commands like AWK. Also, can we do the same by creating a function?
    Please bear in mind that the file is huge
    Thanks in advance

    This sounds like homework for a shell class, but here goes. Save into a file, maybe "doit". Run it like this:
    $ ./doit < data
    <snip>
    #!/bin/sh
    got0=0
    got1=0
    got2=0
    got3=0
    got4=0
    got5=0
    got6=0
    got7=0
    got8=0
    got9=0
    sum=0
    cnt=0
    IFS='|'
    while read c1 c2 c3 junk; do
    # Sum and count
    echo "c1=${c1}"
    case "${c1}" in
    [0-9] )
         sum=$(expr ${sum} + ${c1})
         cnt=$(expr ${cnt} + 1)
    esac
    # Distinct
    case "${c1}" in
    0 )     got0=1;;
    1 )     got1=1;;
    2 )     got2=1;;
    3 )     got3=1;;
    4 )     got4=1;;
    5 )     got5=1;;
    6 )     got6=1;;
    7 )     got7=1;;
    8 )     got8=1;;
    9 )     got9=1;;
    esac
    done
    echo "cnt=${cnt}"
    echo "sum=${sum}"
    echo "distinct="$(expr $got0 + $got1 + $got2 + $got3 + $got4 + $got5 + $got6 + $got7 + $got8 + $got9)
    <snip>

  • Count of distinct Records

    Heres my situation:
    Table a has rows like this
    Col1 Col2 Col3
    1 1 feb-1999
    1 1 feb-1999
    2 1 feb-1999
    2 1 feb-1999
    3 2 mar-1999
    4 4 mar-1999
    What i need to return is a count of the distinct occurances of col1 and col2 grouped by month. So given thabove data my resulting set should be
    Count Month
    2 feb-1999
    2 mar-1999
    Thanks,
    Allen...

    I think it'd better adding a non-numeric character (e.g. space character) to separate the value strings of col1 and col2 . That is,
    select count(distinct to_char(col1)&#0124; &#0124;' '&#0124; &#0124;to_char(col2)),
    to_char(col3,'mon-yyyy')
    from test1
    group by to_char(col3,'mon-yyyy');
    Cheers/RS
    null

  • Extracting a count of distinct values between two date ranges over months

    Hi All,
    I am having a bit of difficulty in figuring out the query to build a list of active campaigns over a date range.
    i.e. I have a table with campaign IDs and their start and end date details like this
    Campaign_id     Start_date     End_date
            10001     1-Jun-09     31-May-11
            10002     1-Jun-09     23-Jun-11
            30041     21-Aug-09     31-Dec-09
            20005     3-Jun-10     31-May-11
            90021     21-Nov-09     30-Nov-10
            54000     1-Jun-11     1-Dec-12
            35600     1-Mar-10     31-Mar-12 What the above data means is, for eg. the campaign 10001 is active from 1-Jun-09 to 31-May-11 i.e. for 24 months (inclusive of the month Jun-09 and May-11)
    What I need to figure out is the counts of active campaigns between a date range and display that active count at a month level (for e.g. lets say we want to see all the campaigns that were active
    between the date range '01-JUN-2007' and '30-APR-2012' ). So the partial output would be as seen below. The list would continue till december-2012
    Month    Year    Count of active campaigns
    Jan    2009    0
    Feb    2009    0
    Mar    2009    0
    Apr    2009    0
    May    2009    0
    Jun    2009    2
    Jul    2009    2
    Aug    2009    3
    Sep    2009    3
    Oct    2009    3
    Nov    2009    4
    Dec    2009    4
    Jan    2010    3
    Feb    2010    3
    Mar    2010    4
    Apr    2010    4
    Dec    2012    1 Could anybody please help me with the right query for this.
    Thanks a lot for help
    Regards
    Goldi

    set pagesize 40
    with tab as
                    select 1 id, sysdate -100 start_date, sysdate end_date from dual
                    union
                    select 1 id, sysdate -200 start_date, sysdate -150 end_date from dual
                    union
                    select 1 id, sysdate -600 start_date, sysdate - 400 end_date from dual
                    union
                    select 1 id, sysdate -300 start_date, sysdate - 150 end_date from dual
                    union
                    select 2 id, sysdate -100 start_date, sysdate-50 end_date from dual
          year_tab as
                        select
                                 add_months(min_date, level -1) m
                        from
                                select min(trunc(start_date,'YYYY')) min_date, add_months(max(trunc(end_date,'YYYY')), 12) max_date
                                from tab
                        connect by level <= months_between(max_date, min_date)
    select to_char(m,'YYYY') year_,
             to_char(m,'Month') month_,
             nvl(act, 0) act
    from   year_tab,
                select m date_,count(*)  act
                from tab, year_tab
                where m between trunc(start_date,'MM') and trunc(end_date,'MM')
                group by m
                ) month_tab
    where m = date_(+)
    order by m;
    YEAR_ MONTH_           ACT
    2010  January            0
    2010  February           0
    2010  March              0
    2010  April              0
    2010  May                0
    2010  June               0
    2010  July               0
    2010  August             0
    2010  September          1
    2010  October            1
    2010  November           1
    2010  December           1
    2011  January            1
    2011  February           1
    2011  March              1
    2011  April              0
    2011  May                0
    2011  June               0
    2011  July               1
    2011  August             1
    2011  September          1
    2011  October            2
    2011  November           2
    2011  December           2
    2012  January            2
    2012  February           2
    2012  March              2
    2012  April              1
    2012  May                1
    2012  June               0
    2012  July               0
    2012  August             0
    2012  September          0
    2012  October            0
    2012  November           0
    2012  December           0
    36 rows selected.

  • Count for distinct values ...

    Dear Team,
    I have following situation at hand...
    COLUMN1      COLUMN2      COLUMN3     
    TECH111      A11111      MATERAL1  
    TECH111      A11112      MATERAL2
    TECH111      A11112      MATERAL3
    TECH111      A11113      MATERAL4
    TECH111      A11113      MATERAL5
    TECH111      A11114      MATERAL6
    TECH111      A11115      MATERAL7
    TECH111      A11116      MATERAL8
    The value in column1 is TECH111
    Now i want to count the number of values appearing in column2
    i.e.A11111 appears 1 time, A11112 and A11113 appears 2 time and so on..
    So the final output i need is shown below..
    COLUMN1      COLUMN2      COLUMN3   COLUMN4
    TECH111      A11111      MATERAL1     1    
    TECH111      A11112      MATERAL2   2    
    TECH111      A11112      MATERAL3   2    
    TECH111      A11113      MATERAL4   2    
    TECH111      A11113      MATERAL5   2    
    TECH111      A11114      MATERAL6   1    
    TECH111      A11115      MATERAL7   1    
    TECH111      A11116      MATERAL8   1     
    kindly give me some tips to achieve this
    Regards
    nic...

    Nic,
    Use the formula
    =CountAll(<col2>) In (<col1>,<col2>)
    Regards,
    Harry

  • Counter counts twice as many edges as it should, but correct frequency. Why?

    Hi everyone,
    I am using a PCI 6122 (S Series, DAQ-STC) and Labview 7.1 on a Windows XP.  There are only two counters on this card (Ctr 0 and Ctr 1) and I need to use both of them to count edges.  While testing the counters, I am inputing a TTL signal of 10kHz to the Gate of each counter, to be used as an external sample clock, and a 20Hz TTL signal into the Source of each counter, to be used as the input signal.  Ctr 0 counts 40 edges per second, i.e. twice as many as it should, while Ctr 1 is reading the correct number of edges, i.e. 20 edges per second.
    The strange thing is that when I switch the connections of Gate and Source for both counters to measure the frequency (or period), both counters read the correct frequency, i.e. 20Hz.  To the best of my knowledge, both counters were reading the
    correct number of edges a couple of weeks ago.  Also, I have reset the
    device several times but it does not make a difference.  I am trying to figure out why this is happening and how to fix it, but I am no closer to answering either question.  Does anyone have any suggestions?
    Thanks.
    Solved!
    Go to Solution.

    After many tests on my own and after speaking with a NI engineer and repeating some tests over the phone, it seems like there is something wrong with the (one) counter on the board.  I have sent it back for repairs (thankfully, it was still under warranty . 
    Message Edited by DanceWiz on 09-15-2009 09:58 AM

Maybe you are looking for