Results 1 to 9 of 9
  1. #1
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23

    Percentage in Totals Query

    Below is the SQL and the query results when I run my query:
    Code:
    SELECT DDRs_Table.PWC,
     Count([DDRs_Table]![PWC]) AS [NO DDRS LOADED],
     Count([DDRs_Table]![ERRORTYPE].[VALUE]) AS [TOTAL NO ERRORS]
    FROM DDRs_Table
    GROUP BY DDRs_Table.PWC
    ORDER BY DDRs_Table.PWC;
    Click image for larger version. 

Name:	Capture10.JPG 
Views:	10 
Size:	23.8 KB 
ID:	18520


    I would like to add an error rate so I add it here is the SQL:


    Code:
    SELECT DDRs_Table.PWC,
     Count([DDRs_Table]![PWC]) AS [NO DDRS LOADED],
     Count([DDRs_Table]![ERRORTYPE].[VALUE]) AS [TOTAL NO ERRORS],
     Count([DDRs_Table]![ERRORTYPE]![Value])/Count([DDRs_Table]![PWC]) AS [ERROR RATE]
    FROM DDRs_Table
    GROUP BY DDRs_Table.PWC
    ORDER BY DDRs_Table.PWC;
    But when I do that is gives me the error:
    Syntax error (missing operator) in query expression 'TOTAL NO ERRORS/NO DDRS LOADED'.

    Can someone school me on doing percentages or see what I am doing wrong. If you need to see the table let me know if that would help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Why using .[Value] and ![Value]?

    Remove them or change ! (bang) to . (dot).

    I never reference Value property in queries.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    I changed it to "." I don't know why it came out with "!" when I had been messing with it, but either way even if I remove the value, I get the same syntax error. I don't like using them but in this case the Error Type field is a multi-valued field so the .value counts all instances even if there are multiple selections in the field and not just counting the field once. I still don't know why it says missing operator. My "/" divide by sign should be the operator right?

    I also tried
    Code:
    Sum(Count([DDRs_Table]![ERRORTYPE].[Value])/Count([DDRs_Table]![PWC])) AS [ERROR RATE]
    And I get a different error with this again doesn't matter if I remove the .value or use a diffrent field all together to count.
    Cannot have aggregate function in WHERE clause (Count([DDRs_Table]![ERRORTYPE].[Value])).

    What I noticed though is if you use a completely separate query based off of the first one if will work just by using the field names TOTAL NO ERRORS/NO DDRS LOADED but it seems improper to have a totals query base off of another totals query there has to be a better way to do it in the same query. I have attache a small example of the table with about 6 records in.
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    I was afraid of that. I NEVER use multi-value field. The expression works for me with normal fields.

    Maybe build a report on the original query and do the percentage calc in textbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    let me try it with a normal field and see if it works for me I don't generally use them I need it in this case.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Your query does not show a WHERE clause.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    Yeah I guess your right It must be that multi valued field causing the issue cause I didn't have any issues with calculating these percentages which use a regular combo box. So I might just have to create a second query off of the first one because it seems like the multi-valued calculation has to be done prior to it being used like the new query need to be based off the old query with only one difference which is an added column to do the calculation. But how would I change my output format to 0.0% instead of the statndard percentage of 0.00% or would I be better off leaving the percentage as a decimal and changing the format in the report that is based off this query. What would be the formula I would need in the format block of the txt box like #.#%
    Code:
    SELECT DDRs_Table.PWC,
    Count([DDRs_Table]![PWC]) AS [NO DDRS LOADED],
    Count(IIf([DDRs_Table]![DDRSTATUS]="ERROR NOT CORRECTABLE",1,Null)) AS [NO UNCORRECTABLE ERRORS],
    [NO UNCORRECTABLE ERRORS]/[NO DDRS LOADED] AS [AFTER CORRECTION ERROR RATE],
     Count(IIf([DDRs_Table]![DDRSTATUS]="NOT REVIEWED",1,Null)) AS [NOT REVIEWED],
     ([NO DDRS LOADED]-[NOT REVIEWED])/[NO DDRS LOADED] AS [PARTICIPATION RATE]
    FROM DDRs_Table
    GROUP BY DDRs_Table.PWC
    ORDER BY DDRs_Table.PWC;

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    I don't do formatting in query if I can help it. Format() function results in a string value, not a true number, and can cause issues if used in other calcs.

    Set textbox Format to Percentage and DecimalPlaces to 1.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Swatskeb is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2014
    Posts
    23
    I just decided to do all the percentages in the Report that query is based off of and it calculates the multivalued field with no issue. A little better than having two underlying queries for the report.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-09-2012, 09:08 AM
  2. Query to perform percentage
    By mari_hitz in forum Queries
    Replies: 4
    Last Post: 04-10-2012, 10:56 AM
  3. Grouping query with percentage
    By msadiqrajani in forum Queries
    Replies: 1
    Last Post: 03-16-2012, 02:14 PM
  4. Percentage Calculation in a Query
    By Lynn in forum Queries
    Replies: 1
    Last Post: 07-16-2010, 11:23 PM
  5. percentage in a query
    By Peljo in forum Access
    Replies: 2
    Last Post: 02-27-2008, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums