Results 1 to 11 of 11
  1. #1
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46

    In crosstable combine "column heading" when argument is X

    I have a crosstable created to display some information by "error category" (in row heading") and then "error grade" as column heading.
    the "error grade" that are between 11-15 are all "correct", where as the one comprised between 41-45 are "incorrect" for each "error category" (A, B, C, D, E)

    Right now heres what my crosstable query looks like :

    Click image for larger version. 

Name:	access.png 
Views:	42 
Size:	8.8 KB 
ID:	36480

    the problem I have is that I would like to gather the columns 11-12-13-14-15 in a single one marked "correct" and same for 41-42-43-44-45 marked "incorrect".

    Here's how it looks like in design view:


    Click image for larger version. 

Name:	access2.png 
Views:	42 
Size:	9.6 KB 
ID:	36481
    and here's the SQL query :
    Code:
    [PARAMETERS [Start date dd/mm/yyyy] DateTime, [End date dd/mm/yyyy] DateTime;
    TRANSFORM Count(MONTHPermanentTable.APP) AS CountOfAPP
    SELECT MONTHPermanentTable.[ERROR CATEGORY], Count(MONTHPermanentTable.APP) AS [Total Of APP]
    FROM MONTHPermanentTable
    WHERE (((MONTHPermanentTable.GRADE)="11") AND ((MONTHPermanentTable.Date) Between [Start date dd/mm/yyyy] And [End date dd/mm/yyyy])) OR (((MONTHPermanentTable.GRADE)="12")) OR (((MONTHPermanentTable.GRADE)="13")) OR (((MONTHPermanentTable.GRADE)="14")) OR (((MONTHPermanentTable.GRADE)="15")) OR (((MONTHPermanentTable.GRADE)="41")) OR (((MONTHPermanentTable.GRADE)="42")) OR (((MONTHPermanentTable.GRADE)="43")) OR (((MONTHPermanentTable.GRADE)="44")) OR (((MONTHPermanentTable.GRADE)="45"))
    GROUP BY MONTHPermanentTable.[ERROR CATEGORY]
    PIVOT MONTHPermanentTable.GRADE;
    Obviously this doesn't work proprely but is the only way I found to arrange the information. Any ideas on how to achieve what i'm looking for? Here's how I want the information to display:
    Click image for larger version. 

Name:	results.png 
Views:	42 
Size:	5.4 KB 
ID:	36482
    Last edited by veejay; 12-10-2018 at 07:14 AM. Reason: error in code

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Maybe you could shine some light on what you are trying to achieve. I dont understand it, its possible someone else will.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    How about a simple totals query grouping on category and summing calculated fields like

    IIf(Grade < 16, 1, 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    Well I don't think this would work.

    What i'm trying to achieve is to have the grades as columns (correct, incorrect, etc.) and the error type (A, B, C, D, E) as rows.

    Afterwards I would have the number of "correct files" for category A, B, C, D, E and then the number of incorrect files for category A, B, C, D, E.

    The idea is to be able to generate a report with a chart breakdown by category (category A had 256 files correct, while 17 were incorrect).

    Obviously I have more than "correct" and "incorrect" grades, but this is to get an idea.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The suggested query would give you exactly that. Here's the fish:

    SELECT [ERROR CATEGORY], Count(*) As Total, Sum(IIf(Grade < 16, 1, 0)) As Correct, Sum(IIf(Grade > 15, 1, 0)) As InCorrect
    FROM
    MONTHPermanentTable
    GROUP BY [ERROR CATEGORY]

    I'll let you add the criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    Hmm I'm getting an error with this code.

    But my understanding is that this would calculate the sum of grade, but what i'm trying to achieve is to calculate the number of "APP" that have a grade between 10-15 (correct) and the number of APP that have between 40-45 (incorrect).

    This is what I tried:
    Code:
    PARAMETERS [Start date dd/mm/yyyy] DateTime, [End date dd/mm/yyyy] DateTime;
    SELECT MONTHPermanentTable.[ERROR CATEGORY], Count(IIF(MONTHPermanentTable.GRADE< 16, 1, 0)) AS Correct
    FROM MONTHPermanentTable
    WHERE (((MONTHPermanentTable.Date) Between [Start date dd/mm/yyyy] And [End date dd/mm/yyyy]))
    GROUP BY MONTHPermanentTable.[ERROR CATEGORY]
    If I try this way:
    Code:
    [PARAMETERS [Start date dd/mm/yyyy] DateTime, [End date dd/mm/yyyy] DateTime;
    SELECT MONTHPermanentTable.[ERROR CATEGORY], Count(MONTHPermanentTable.GRADE) AS Correct
    FROM MONTHPermanentTable
    WHERE (((MONTHPermanentTable.Date) Between [Start date dd/mm/yyyy] And [End date dd/mm/yyyy]))
    GROUP BY MONTHPermanentTable.[ERROR CATEGORY]
    I get a total that doesn't make sense.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Did you try what I posted?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    I did exactly as you posted and got the following error:

    "Data type mismatch in criteria expression"

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If grades are text try:

    SELECT [ERROR CATEGORY], Count(*) As Total, Sum(IIf(Grade < "16", 1, 0)) As Correct, Sum(IIf(Grade > "15", 1, 0)) As InCorrect
    FROM
    MONTHPermanentTable
    GROUP BY [ERROR CATEGORY]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    It (almost) works!
    The only problem I have is that I need "correct" to be values between 10-16 and incorrect between 40-46. Is there a way to do this?

    Otherwise: amazing thank you i'm finally getting my head around this!

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Text values can be tricky, but try

    Sum(IIf(Grade >= "10" AND Grade <= "16", 1, 0))

    With text values, 1000 falls within that range. If you have those kinds of values and the field needs to stay text you'll need to have a test for each value:

    Grade = "10" OR Grade = "11" OR ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 07-19-2014, 01:15 PM
  2. Replies: 5
    Last Post: 06-26-2013, 02:29 PM
  3. Replies: 4
    Last Post: 06-24-2013, 07:12 AM
  4. table field name "Year" causing Argument Not Optional
    By JosmithTwo in forum Programming
    Replies: 2
    Last Post: 09-26-2012, 08:01 PM
  5. How to change the column heading in a "split form"
    By robertrobert905 in forum Forms
    Replies: 1
    Last Post: 09-21-2010, 02:42 PM

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