Results 1 to 15 of 15

Thread: count per all entry divide / total count

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    count per all entry divide / total count

    hi someone please help me..

    i want to count records found in database as per customer status

    ex.
    Code:
    Custstatus          Count                 Percentage  (Count / total)
    Active                  5                     0.5%  how could i do this at crystal report
    Not active             4                      0.4%  how could i do this at crystal report
    Please help
    Last edited by edgarbenilde; Aug 24th, 2009 at 03:03 AM.

  2. #2
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: count per all entry divide / total count

    you can use GROUP BY
    something like this
    vb Code:
    1. SELECT COUNT(Custstatus) FROM <YourTableName>
    2. GROUP BY Custstatus
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    yes i'm done with with... my problem is to get the result of count / total
    ex.
    how many is active / total count of all entries (active, inactive, etc.)
    and how many is inactive / total count of all entries (active, inactive, etc.)
    and etc if there other entries specefied depend on the user entry

  4. #4
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: count per all entry divide / total count

    ok,
    i think about something and i wish this can help.
    vb Code:
    1. SELECT COUNT(Custstatus),dbo.TotalCount() as TotalRows FROM <TableName>
    2. GROUP By Custstatus

    where dbo.TotalCount() is Scalar Valued Function
    and here is its Definision
    vb Code:
    1. USE [<your Database>]
    2. GO
    3. /****** Object:  UserDefinedFunction [dbo].[TotalCount]    Script Date: 08/24/2009 10:47:02 ******/
    4. SET ANSI_NULLS ON
    5. GO
    6. SET QUOTED_IDENTIFIER ON
    7. GO
    8. CREATE Function [dbo].[TotalCount]()
    9. RETURNS int
    10.  
    11. AS
    12. BEGIN
    13.     DECLARE @Return int
    14.     SET @Return = (SELECT COUNT(*) FROM dbo.<yourTableName>)
    15.     return @Return
    16. END
    Last edited by avrail; Aug 24th, 2009 at 03:50 AM. Reason: there was something missing
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    i found help codes in crystal report formula fields
    like this
    Code:
    If {Customer.Region} In ["WA","ID","OR"] Then
        "Northwest"
    Else If {Customer.Region} In ["CA","TX","NV","AZ","NM"] Then
        "Southwest"
    Else If {Customer.Region} In ["AL","AR","LA","MS","TN","VA","WV","FL","NC","SC","GA"] Then
        "Southeast"
    Else If {Customer.Region} In ["CT","DC","DE","MD","NJ","ME","NH","NY","MA","PA","RI","VT"] Then
        "Northeast"
    Else If {Customer.Region} In ["UT","CO","WY","NE","MT"] Then
        "Rocky Mountain"
    Else
        "Midwest"
    in my case i want to count all entries which mymonth field value is 1.
    can someone know to do it in crystal report formula fields?

    please help

  6. #6
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: count per all entry divide / total count

    why you insist to do this in your crystal report,
    you can do it inside your database

    i don't know crystal report well,
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    thanks avrail as posted above
    Code:
    Custstatus          Count                 Percentage  (Count / total)
    Active                  5                     0.5&#37;  how could i do this at crystal report
    Not active             4                      0.4%  how could i do this at crystal report
    i want to this format
    Code:
    SELECT COUNT(Custstatus) FROM <YourTableName> GROUP BY Custstatus
    based on your reply in post # 2 this is possible but lock of one row Value not found.

    this is how to get the result but i don't know how..
    Code:
    count(cuscode) as mycountresult
    count (*) as myallentries
    mycountresult / myallentries
    Group by Custstatus
    thats it's but how to make a code for that...
    it can be in Access querry or Formula field fo crystal report depends on what is easy to do..

    please help me here...

  8. #8
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: count per all entry divide / total count

    what is your Database Engine ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    access database 2003

  10. #10
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: count per all entry divide / total count

    amm,
    i didn't use access i use SQL Server
    try to use your Query Designer to create 2 views
    the first will be your one that you said you can done.
    vb Code:
    1. SELECT COUNT(Custstatus) FROM <YourTableName> GROUP BY Custstatus

    and the other is for
    vb Code:
    1. SELECT COUNT(Custstatus) FROM <YourTableName>
    with out any Group

    and inside your crystal Report i believe that you can use the two Views.

    and then you can do
    CountActive/CountRows
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  11. #11
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: count per all entry divide / total count

    This is very easy to do in Crystal. Assume you have a sample report that is based on the Customer table in the Northwind database. To get a Count and Percentage of Customers by Country

    1) Create a Group using the Country field.
    2) Insert the CompanyName field in the Details section
    3) Right click the CompanyName field and select Insert Summary
    4) Select Count from the dropdown list.
    5) Check the options "Insert Summary fields for all Groups" and "Insert Grand Total fields"
    Two new fields should be created. One in the Group footer the other in the Report Footer
    6) Copy and paste each summary field into the same section.
    7) Right click on each pasted summary field and select Change Summary
    8) Set the option "Show as a Percentage of"
    9) Format the report as desired.


    You can accomplish the same thing using formulas.

    CountByCountry = Count ({Customers.CompanyName},{Customers.Country} )
    PercentByCountry = PercentOfCount ({Customers.CompanyName},{Customers.Country} )
    TotalCount = Count ({Customers.CompanyName})
    Attached Images Attached Images  
    Last edited by brucevde; Aug 24th, 2009 at 01:48 PM.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    this is helpfull brucevde, but i don't Grand totals (92 and 100&#37 summary.
    i only have the bycountry with the count and percentage equevalent...

    another issue i found i want to count how many of those records are belong to month of January, Febuary, March, April, May ........ up to December, in my database i have field called mymonth.. how could i do it?
    this result would be look like this
    Code:
                         January         February          March           April          May ...........
    Total Records      8                 6                     5                8             10...........
    the mymonth field data type is number so data inside it is (1 to 12 as equevalent to jan - dec.)
    Last edited by edgarbenilde; Aug 25th, 2009 at 10:17 PM.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    this is helpful it's but i didn't get a grand total of 92 and percentage 100%

    another things how can i count how many of this records are belong to each month
    in my database i have field called myMonth
    this is going to be in this format
    Code:
                  January         February           March        April        May ........... upto  Dec
    Total           8                   11                 7               9          11                                     92
    the mymonth field data type is number so data inside it is (1 to 12 as equevalent to jan - dec.)

    this code is the nearest code the result i want.. but this is general i want to put a filter on this, how could i put here if mymonth=1 then Count ({Customers.CompanyName}) and this will be my result for January, then count again mymonth=2 for february..
    please help me here...
    Code:
    TotalCount = Count ({Customers.CompanyName})
    Last edited by edgarbenilde; Aug 25th, 2009 at 10:20 PM.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    somebody please help in post # 13...

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: count per all entry divide / total count

    what wrong with this code?
    i put this code under AveCountOverWorkdays
    Code:
    {byCustStatus} / {SUMworkDAYS}
    in formula field it gives me error "the field is not known"
    but that is the name of the field that i have in the formula field..

    anybody help me how to divide under formula field...
    the denaminator and divisor are both from formula

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width