Count() function with selective criteria?

I'm struggling with what I would expect to be a fundamental reporting concept in CR.
Suppose I have the following EMPLOYEE table:
u2022 EMPLOYEE.ID
u2022 EMPLOYEE.GENDER_CODE
u2022 EMPLOYEE.MANAGER_FLAG
I need to generate a statistical summary report containing the following:
u2022 Total number of Employees
u2022 Number of Male Employees
u2022 Number of Management Employees
This would be easy if I could just use a Count() function in the Function Workshop which
contained selective criteria.  For example:  Count ({EMPLOYEE.GENDER_CODE} = 'M')
But I can't figure out how to do this without getting a CR error message.
Record Selection doesn't work, because I need the whole data set.
Group Selection with Summaries doesn't work, because the gender and management
attributes are not mutually exclusive.
One solution that seems awkward to me is to create additional SQL commands in the
Database Expert using COUNT(*) and WHERE criteria to get the number of Males
and number of Managers.  But I have to believe that there is a better way.  Plus this
approach causes problems elsewhere in my report.
Am I missing something?
Thanks,
Bill

Thanks Raghavendra!
The good news is that I was able to create a "1 or 0" formula and then sum the resulting values.
The bad news is that I'm only able to get this to work for part of my report.
I am joining two tables.  As an example COMPANY and EMPLOYEE.
I can use "1 or 0" formulas on all of the employee statistics.
But I cannot do the same for company statistics, because the number of company records being assigned a 1 is being inflated by the join between the two tables.
I have achieved a successful result by using Running Total Fields at the end of the report.
But I want to place these summary statistics at the begining of my report.  (Such as Total Companies in the Western Region.)
I tried to use "COMPANY.NAME = previous(COMPANY.NAME)" logic in my function, but then I was not allowed to summarize it.
Any ideas?
Thanks,
Bill

Similar Messages

  • SQ01 query on LDB BRF with selection criteria on BSEG

    Dear all,
    we built an inofset on LDB BRF (BKPF - BSEG) and a query with selection criteria based on both BKPF and BSEG tables.
    My proble : when the query select a posting fullfilling header data selection criteria but not line item criteria, it still displayed the header data in the layout.
    We set up a filter on the account to hide results where account is blank but we loss the filter exporting the result on access. So if anyome has a better idea, we'll be very thankfull.
    Br,

    Hi Rick,
    What Edan proposed will work as logical AND (both filters on dates will be checked simultaneously).
    Here is a solution.
    You’ll have a user entry variable on 0CALDAY.
    - Create a new variable on 0CALDAY, customer exit, mandatory, not ready for input. This variable should return the date entered in user entry variable.
    - Create a structure in columns.
    - New selection (let’s name it chg). Put there your KF and your Change date char. Restrict it by the user entry var. Hide it.
    - New selection (let’s name it crt). Put there your KF and your Created on date char. Restrict it by the customer exit var. Hide it.
    New formula (let’s name it FilteredAmount):
    ( 'chg' <> 0 ) * 'chg' + ( 'crt' <> 0 ) * 'crt'
    Create a condition:
    FilteredAmount <> 0.
    Best regards,
    Eugene

  • Problem with Selection Criteria with 2 or statements.

    I have a report with 2 or statements in the selection criteria:
    like "US IT GFS INFOSYS*" or
    like "US IT GFS INFOSYS*" or
    like "US IT GFS INFOSYS*"
    I am just trying to do do a count of records. The details has the record # and am doing a distinct count. If I rearrange this or statement, then I get a different count. The above statement gives me a count of 1136. If I rearrange the statement to:
    like "US IT GFS INFOSYS*" or
    like "US IT GFS INFOSYS*" or
    like "US IT GFS INFOSYS*"
    I only get 192 records. I don't understand why?  Please help.

    Cara,
    When Crystal evaluates an or statement it will stop evaluating after one of the clauses is true. Since the first or clause is returning data, true, it is not evaluating the other 2 clauses. When you change the order I am assuming that the first clause is returning data though different from the original record selection.
    You may want to consider using a command object or stored procedure to generate the filter as SQL should evaluate all the or clauses.

  • Portal Activity Report with Selection criteria

    Hi All,
    I have created an iview using 'Portal Activity Report' template, added the iview to page and page is added to the role which is created for this report. Also, users were assigned to the new role. When users go to portal and see this report, they are seeing the final output of this report along with the 'Download Report' option.
    My requirement is to give selection screen option (Type of report and Reporting period) to users. So that users will change the selection criteria and run the report as per their need. Please advice me on how to do this.
    Thanks in advance.
    Swapna.

    swapna,
    you can do this by creating a webdynpro application for accessing the database tables, the list of data base tables is in this [help |http://help.sap.com/saphelp_nw04/helpdata/en/48/6aa9429b930b31e10000000a1550b0/frameset.htm]document and use web dynpro application to connect to that tables. Check this thread  for[ dynpro and database tables  |dynpro and database tables;
    regards
    Mahesh

  • Counting rows with multiple criteria

    I know this is a silly beginner question, but is there an easy way to count the number of rows in a table which match criteria based on different columns (sort of a countif with multiple criteria). For example, if Column A in a table has "All, Some, None" responses and Column B has "Main, Off" responses, is there an easy way to count the number of rows in which Column A has All and Column B has Off?

    Neondiet wrote:
    From an intellectual and philosophical view I agree with you. But from a practical view what I really want to do is just use one application for my spreadsheet tasks, not jump back and forth because one sheet I share with MS Windows users, and another with Numbers users, and another with OS X users who don't have Numbers or Excel but do have NeoOffice. Maybe I have to settle for that though.
    Yeah... this kind of situation stinks. Its like needing to writing software that will run on both Macs and PCs.
    Anyway, I've followed the advise in this forum and resorted to using a hidden column with concatenated values to solve my own problem, though it does seem like a bit of a hack compared to managing a single formula in a single cell. Horses for courses I suppose.
    jaxjason has posted a very elegant pivot table like solution that utilizes this technique. See http://www.numberstemplates.com/forums/showthread.php?t=36
    Btw, from what I've read on the net to date, SUM (in Excel) with an array formula answers the original authors problem of counting occurrences of values, not SUMPRODUCT; which I believe sums up the contents of cells in a range, if cells in other ranges match specific criteria.
    Yes, if you use the '*' (as indicated above) then SUM() is sufficient though SUMPRODUCT() will work as it degenerates to SUM when there is only one argument. If you use two arrays as arguments (like: = SUMPRODUCT((A1:A4="All"), (B1:B4="Off")), then SUMPRODUCT() is necessary. Here's my understanding of how it works (I hope your able to follow my abuse of algebraic techniques):
    =SUM((A1:A4="All") * (B1:B4="Off"))
    expanding the array expressions...
    =SUM((A1="All", A2="All", A3="All", A4="All") * (B1="Off", B2="Off", B3="Off", B4="Off"))
    at this point Excel computes the equality expressions, for example...
    =SUM((TRUE, FALSE, TRUE, FALSE) * (TRUE, TRUE, FALSE, FALSE))
    expanding the array multiplication...
    =SUM((TRUE * TRUE, FALSE * TRUE, TRUE * FALSE, FALSE * FALSE))
    Excel, apparently, then, when forced to multiply Boolean values, maps TRUE -> 1 and FALSE -> 0...
    =SUM((1 * 1, 0 * 1, 1 * 0, 0 * 0))
    performing the multiplications...
    =SUM((1, 0, 0, 0))
    summing...
    =1 + 0 + 0 + 0
    resulting...
    =1
    I'm afraid, now, if I continue any further, Yvan will chastise me.

  • Issue calling program from transaction with selection criteria

    Hi Guys,
        I ve a issue regarding calling a program from transaction.
    There is a standard transaction calling a program  using selection criteria no (say for eq 10 fields, just look at the eg below)
    Submit  <table-proname> and return using selection-set <table-varia>
    With rbukrs  = i_bkorm-burks    “Comp Code
    with  Revent = i_bkorm-event  “ event
    with rbelnr  = ibkorm-belnr     “Doc no
    with rgjahr = ibkorm-gjahr   “fiscal year
    with ruzeit = ibkorm-ruzeit  “time
    with rusnam = ibkorm-rusnam “user name
    And so on
    Now, In my program selection screen  i  ve only three fields, (not all mentioned above)
    Parameter:
    Rbukrs  type bukrs, “comp code
    Rbelnr type belnr, “doc no
    Rghar type gjahr.  “fiscal year
    Now, i configure this transaction with this program i can able to run this program  from transaction.
    Is every thing go right, Pls give your sugg
    Points & help awarded.
    Thanks in advance.

    Hi,
    you can call the program using 3 selection screen fields even though it is having 10 fileds, but before calling make sure that there is no mandatory fields (in rest of the 7 fields), then it will runs you report.
    reward if needful.
    Thanks,
    Sreeram.

  • Call function with select arguments

    Hi Gurus,
    I have problem to call function inside select statements as follow:
    select a.ID_ELE2, a.ID_ELE3, a.DT_FIS_YR, c.NU_FIS_PER, c.dt,
    (case
    when c.ld is null then
    GET_LD_CHECK (a.DT_FIS_YR,c.NU_FIS_PER, a.ID_ELE3, a.ID_ELE2) -- 1
    -- GET_LD_CHECK ('2009',7, '8010', '7493') --- 2
    else
    c.ld
    end ) description
    from ACCOUNT a, TRANSACTION c
    where a.DT_FIS_YR ='2009'
    and a.ID_ELE3 <> '0000'
    and c.TY_SRC not in ('CL', 'CN')
    and a.DT_FIS_YR = c.nu_fis_yr
    and a.AK = c.AK_FGCHAR
    and trim(a.ID_ELE3) ='8010'
    and c.NU_FIS_PER <> 14
    order by 1,4,5,6
    the 1 doesn't output result but the 2 it does! How can pass the select result to the function?
    Thanks in advance for your help.
    Ben

    The statement / function call seems to be ok. So there are not much chances left for your call to return different (=non) values.
    1) It could be that you have different values in the column then during your test call.
    2) Maybe your function raises an error and that error is supressed in some ugly WHEN OTHERS EXCEPTION => Solution: Get rid of the error handler.
    3) datatype conversion. For example if a.dt_fis_yr is a number value, then you should test with number values and not with strings. GET_LD_CHECK (2009,7, '8010', '7493'). Same logic goes for the other paramters, make sure the datatype is correct and matches the function parameter.

  • Function with select if statement query

    Hi,
    I want to use if condition in select statement in function.
    But i implemented in case too ,its taking more time to return the value while using case statement.
    My function is like this
    create or replace FUNCTION GET_CODE
    (pv_type IN table1.type%TYPE,
    pv_desc1 IN table2.type%TYPE,
    pv_desc2 IN table3.type%TYPE)
    RETURN varchar2(35 byte)
    IS
    V_ret_string varchar2(35 byte);
    BEGIN
    SELECT case when(table2.xxx like 'fff%') then 1
    when (table3.yyy like 'fff%') then 2
    when (table4.zzz like 'fff%') then 3
    else table1.aaa
    INTO V_ret_string
    FROM
    table1 a,table2 b,table3 c table4 d
    WHERE
    table1.column1=table2.column1
    and (table1.column2=table3.column1 or table1.column2=table4.column1) and
    UPPER(b.type) = UPPER(pv_type) and
    (UPPER(c.desc) = UPPER(pv_desc1) or UPPER(d.desc1) = UPPER(pv_desc2)) ;
    RETURN V_ret_string;
    END GET_TRANSACTION_CODE;
    Pls help me how to use if condition.
    Regards,
    Punitha

    936698 wrote:
    Hi,
    I want to use if condition in select statement in function.Oracle SQL SELECT statement does not support IF condition syntax. But what it does is CASE and DECODE. And CASE statement is sufficient to achieve what ever you want to do with IF condition.
    But i implemented in case too ,its taking more time to return the value while using case statement.So the issue is not with CASE its with the SELECT Statement. What you have to do is Isolate your SELECT statement and try to tune it for performance.
    To do that i would suggest you to read the folloing threads which could be of good use.
    {thread:id=501834} and {thread:id=863295}.
    >
    >
    My function is like this
    create or replace FUNCTION GET_CODE
    (pv_type IN table1.type%TYPE,
    pv_desc1 IN table2.type%TYPE,
    pv_desc2 IN table3.type%TYPE)
    RETURN varchar2(35 byte)
    IS
    V_ret_string varchar2(35 byte);
    BEGIN
    SELECT case when(table2.xxx like 'fff%') then 1
    when (table3.yyy like 'fff%') then 2
    when (table4.zzz like 'fff%') then 3
    else table1.aaa
    INTO V_ret_string
    FROM
    table1 a,table2 b,table3 c table4 d
    WHERE
    table1.column1=table2.column1
    and (table1.column2=table3.column1 or table1.column2=table4.column1) and
    UPPER(b.type) = UPPER(pv_type) and
    (UPPER(c.desc) = UPPER(pv_desc1) or UPPER(d.desc1) = UPPER(pv_desc2)) ;
    RETURN V_ret_string;
    END GET_TRANSACTION_CODE;When ever posting code please make sure the code is well formatted and you use the {noformat}{noformat} tag to preserve the format. An unformatted code is very hard to read.
    The usage of the tag is like this.
    <place your code here>\                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Count(*) function in select statement having group by condition

    Hi
    I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
    the sql stement is grouped by state and it is joined with 5 more tables.
    Thanks
    ps: ignore the previous post

    Assuming there is one record per city per state, then
    SELECT state,count(*)
    FROM state_tbl
    GROUP BY stateWill get one record per state with the number of cities in each state. If you want to join that result set to other tables you need to either create a view with that statement or use an in-line view viz.
    SELECT c.cust_name,c.state,s.num_cities
    FROM customers c,
         (SELECT state,count(*) num_cities
          FROM state_tbl
          GROUP BY state) s
    WHERE c.state = s.stateTTFN
    John

  • Ago Function with Select Table--HELP!

    When my physical layer was setup using all 'Physical Table' types, my time series functions were working.
    I had to modify my fact table to be of a 'Select' type (using SQL). When I remap my data, my time series functions fail with the following message:
    "[nQSError: 22038] Function AGO requires at least one measure attribute in its first argument."
    We have to be able to use select tables with time serious functions--what am I missing!?
    Thanks!!

    does your new 'select table' contain the same number of columns with same datatypes?
    did you restart the services (if developing in online mode- which is not recommended)
    Lastly, if all fails,can you create those views on the database rather than in the physical layer?

  • Want to load data with selection criteria

    Hi Everyone,
    I want to load data from X ODS to Y ODS , X ods is a datasource to Y ods.
    On Y ods i don't have any data loaded.
    But on X ods i am having 10 requests with 200000 records.
    In X ods i am having a request with 2 records.
    I want to load the 2 records request to Y ODS.to check data on Y ods
    Can anyone help me in solving these, b'cos i am new to BW, It's urgent Please.
    Can you tell me step by  step navigation.

    Hi,
    Just select Full upload; it will bring the InfoPackage and then in the Selection tab give the range value. If this is required only one time then this method is fine or full load is fine, otherwise you will have to write a code to pick the records. If you frequently want to load data from one ODS to another ODS then better go for init and then from next time onwards do the delta load. If you don't want to provide selection in the InfoPackage then the other way is to load all the data from X to Y and do selective deletion on Y ODS.
    Hope this helps.
    PB

  • [WebIntelligence Reporting] How to use count function with condition !?

    Post Author: xuanthuyit
    CA Forum: WebIntelligence Reporting
    Hi everyone,
    I want to make a report like this  with WebIntelligence reporting.
    I want to show the number of Outlet of each chanel (Horeca, Grocery, Convenience) at the end of report !
    But I don't know how to do that with WebIntelligence Reporting.
    Please help asap. . .
    Thank you verry much,

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    xuanthuyit:
    Apparently =count() &#91;and use of a where&#93; was permissible in previous versions of BusObjects, however, things in XI are different (as other users tell me, being XI is my first experience w/ BusObj...), so anyhow, here is the solution to your question.
    You will have have to create two variables for each condition you have.  One variable will be the "helper" and the other variable will be the "worker".  For instance, create a variable called channel_x and the formula:  =if(channel="haney";<metric>;0)  (where "haney" is the name of your organization and <metric> is the metric you are using to count or sum things in your report).  Once channel_x is saved create another variable called channel_x_count and the formula:  =sum(&#91;channel_x&#93;).  Once channel_x_count is saved, then on your report towards the bottom you can use the Template bar to drag in a new table (perhaps you want to use the Horizontal Table type), and then you can drag channel_x_count into your new table.  You will have to repeat the creations of more channel_x type variables (maybe call it channel_y and channel_y_count) or something more descriptive, but in any case substitute the "haney" constant for the next store you want to track, etc, etc.

  • Using count function with grouped records

    Hi all,
    This seems like it should be real easy but I have yet to figure out a simple way to do this.
    Suppose I want to count Opportunities that are grouped by Sales Rep. At run-time I am filtering this list with a parameter for Sales Stage and created date.
    I've simplified this greatly, but here's what my setup looks like now:
    Sales Rep* ---------Count*_
    <?for-each-group:Opportunity[SalesStage=param1 and Created>param2];./salesrep?>
    <?salesrep?>-------<?count(current-group()/Id)?>
    <?end for-each-group?>
    Total_
    The only solution I have so far to get my grand total is to create a variable and keep a running total which I'll then display in the Total column. While it works, it seems like there should be an easier way, like doing a simple count(Id) to get the grand total. But since the Total appears after the end for-each-group, I lose the filter that was applied to the group so that count is invalid.
    Any thoughts from the experts?
    Thanks!

    To get grand total
    use
    <?count(/Oppurtunity[SalesStage=param1 and Created>param2]/Id)?>since you did not mention the complete xml, i assumed, Opportunity as the Root.
    if not, put the full path from the root.
    if you give some xml sample, and explain the output you wanted, we can fix it immediately.
    go thru these too..some thing can be pulled from here .
    http://winrichman.blogspot.com/search/label/Summation%20In%20BIP
    http://winrichman.blogspot.com/search/label/BIP%20Vertical%20sum

  • Call function with select options problem

    Hi there dear SDN community members.
    I have got an strange ABAP problem wich function call.
    Code1
    CLEAR ls_selec .
    ls_selec-iobjnm = '9AMATNR' .
    ls_selec-sign   = 'I' .                                    
    ls_selec-option = 'EQ' .
    ls_selec-low    = '0000000000000000000000000000000000017714' .
    APPEND ls_selec TO lt_selec .
    CLEAR ls_selec .
    ls_selec-iobjnm = '9AMATNR' .
    ls_selec-sign   = 'I' .
    ls_selec-option = 'EQ' .
    ls_selec-low    = '0000000000000000000000000000000010079409' .
    APPEND ls_selec TO lt_selec .
    CALL FUNCTION '/SAPAPO/TS_PLOB_LIST_GET'
      EXPORTING
        iv_bas_plobid  = 'Z_DP_POS'
        it_selection   = lt_selec
        it_group_by    = lt_group
      IMPORTING
        et_plob_values = lt_plobs .
    Function returns data in lt_plobs itab only for the last product which was appended to the selection table lt_selec.
    Whilst
    Code2
    CLEAR ls_selec .
    ls_selec-iobjnm = '9AMATNR' .
    ls_selec-sign   = 'I' .
    ls_selec-option = 'BT' .
    ls_selec-low    = '0000000000000000000000000000000000017714' .
    ls_selec-high   = '0000000000000000000000000000000010079409' .
    APPEND ls_selec TO lt_selec .
    Returns data in lt_plobs for all products included in selection tab lt_selec.
    What am I doing wrong in case of Code1? Why function does not return data for both products included in selection tab lt_selec?
    Will be thankful for help. Regards. P.

    I am very sorry to take your time unnecessarily.
    The problem was caused by data inconsistency in our sandbox system I was developing in.
    Be understanding, please.
    Kind regards. P.
    Ps. 
    Vinod Nair
    The 'Loop' solution has slowed the performance down very much.

  • SUBMIT RFGLBALANCE WITH selection criteria, then How to get resulted itab?

    Hi Experts,
    Am looking to develop a similar report which is doing by SAP at detail/item level, but am looking to develop a SUMMARY level.
    SAP report is = FS10N (bhind prog. is RFGLBALANCE / RFGLITEMS )
    my_alv = shuld show only TOTALS / SUMMARY line
    Almost the selection screen is same in both cases.
    So, I wanna to use the same prog. by using SUBMIT from my_alv_report.
    So, when I use
    SUBMIT RFGLBALANCE
      WITH ..........................
      WITH ........................
    AND RETURN.
    then, my_alv_report control goes to RFGLBALANCE prog. there my input is processed and the output internal table is populating in RFGLBALANCE.............so, now, I wanna to get / fetch / pull this populated internal table into my_alv_repor and there by using the same for my alv display.
    ( I know that, if both r Z prog.s/ Z_BAPIs, then, I can use EXPORT & IMPORT )
    So, pls. let me know that,
    Is it possible ?
    If so, How to get it done?
    SUBMIT Syntax pls.
    thanq

    thanq.
    so, then, Can I use like, *INCLUDE RFGLBALANCE*(Standard Prog.) in my_alv_report, I mean, like
    report my_alv_report message-id Z1.
    INCLUDE RFGLBALANCE.
    own_Logic.
    thanq

Maybe you are looking for