Results 1 to 6 of 6
  1. #1
    elena is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    3

    CrossTab query Count() doesn't match.

    Hi All,
    I really need help to figure out why Crosstab query results doesn't match another regular query result with the same parameters.
    I am using date range for example 1/1/2011 - 4/30/2014 and the return result looks like following (reports, database was created in Access 2003 and now I am open it in 2010), but if I change date range to
    just 4/1/14 - 5/1/14 then I still see the difference:

    Badge Valid Void Total Ticks Total Amount
    100 29 0 29 $345.00
    105 5 0 5 $75.00

    crosstab SQL statement;

    PARAMETERS [Enter Start Date] DateTime, [Enter End Date] DateTime;
    TRANSFORM Nz(COUNT(Master.TickNo),0) AS CountofTicks
    SELECT [Shield] AS Badge, Sum(Master.AmtVl) AS SumOfAmount, Nz(COUNT(Master.TickNo),0) AS TotalTicks
    FROM Master
    WHERE Master.IssDate Between [Enter Start Date] AND [Enter End Date]
    GROUP BY [Shield]
    PIVOT IIf([DisposCode]="VD","Void","Valid") IN ("Void","Valid");


    another query SQL statement the return result below I am using the same date range and Badge "105" and the totals are completely different;

    Viol/Code Violation Description Fine Tickets Total Amount
    101 Meter Violation $100.00 117 $11,500.00


    .... ................. ....... .... .......

    Totals: 12538 $206,365.00

    SELECT Master.Viol, Violat.Description, Violat.Fine, COUNT(Master.TickNo) AS TotalTickets, Sum(Master.AmtVl) AS SumOfAmount
    FROM Master INNER JOIN Violat ON Master.Viol=Violat.Viol
    WHERE (((Master.IssDate) Between [Enter start Date] And [Enter end Date]))
    GROUP BY Master.Viol, Violat.Description, Violat.Fine
    ORDER BY Master.Viol, Violat.Description, Violat.Fine;

    There is 2 tables "Master" and "Violat" in the database.
    Can somebody help?
    thank you,

  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,770
    The SELECT results are correct?

    Want to provide db for analysis? Follow instructions at bottom of my post.
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The extra table in the second query could potentially change the result. With the join you've specified, only records existing in both tables would be returned. The first would pull everything from the master table that meets the criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    elena is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    3
    Hi pbaldy,
    That is the problem that the crosstab which is source is only one table "Master" returns only 5 tickets and the second query (has INNER JOIN) returns 12538 tickets as total. This is crazy to compare 5 and 12538 for the same date range.

  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,652
    Are there that many records in the second table? Is there a date field in that table that should have criteria on it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    elena is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    3
    Hi pbaldy,
    I am comparing reports or return result directly on the query (by double clicking on the query and entering date range parameters).
    "Master" table has a lot of records 127131 that is the base for the crosstab. Table "Violat" has only 11 records and it is look up table where Violation code, description and Fine (currency).
    Second query has INNER JOIN on both tables and this specific query returns most accurate result. I am using INNER JOIN in the query only for the report will look nice.

    SELECT Master.Viol, Violat.Description, Violat.Fine, COUNT(Master.TickNo) AS TotalTickets, Sum(Master.AmtVl) AS SumOfAmount
    FROM Master INNER JOIN Violat ON Master.Viol=Violat.Viol
    WHERE (((Master.IssDate) Between [Enter start Date] And [Enter end Date]))
    GROUP BY Master.Viol, Violat.Description, Violat.Fine
    ORDER BY Master.Viol, Violat.Description, Violat.Fine

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

Similar Threads

  1. Replies: 2
    Last Post: 04-30-2014, 03:01 PM
  2. Replies: 7
    Last Post: 04-28-2014, 07:09 AM
  3. count blank colums in crosstab query
    By survivo01 in forum Queries
    Replies: 6
    Last Post: 04-13-2012, 01:37 PM
  4. Replies: 1
    Last Post: 01-24-2011, 03:03 PM
  5. Finding data that doesn't match
    By dlhayes in forum Queries
    Replies: 1
    Last Post: 11-11-2006, 08:14 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