Results 1 to 3 of 3
  1. #1
    uaguy3005 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2010
    Posts
    45

    Crosstab Column Headers

    I have a crosstab query I'm using to display sort results for the last 30 days. Row has part/defect information and column has date information. How do I show all the dates in the column header for the last 30 days, including the ones with no data. I've seen several articles on locking the headers down to the month, but cant seem to find anything that would tell how to keep the last 30 days. This would be a rolling 30 days so if I ran the query today it would show 11/16/15 - 12/17/15, if I ran it tomorrow it would show 11/17/15 - 12/18/15.



    TRANSFORM Sum(Nz([QtyRejected],0)) AS RejectAmount
    SELECT [PartNum] & " - " & [DefectDescription] AS Finding
    FROM (tblParts INNER JOIN tblSortData ON tblParts.PartID = tblSortData.PartsID) INNER JOIN (tblDefectCodes INNER JOIN tblRejects ON tblDefectCodes.DefectID = tblRejects.DefectCode) ON tblSortData.SortDataID = tblRejects.SortDataID
    WHERE (((DateValue([InspectDateTime]))>=Date()-30))
    GROUP BY [PartNum] & " - " & [DefectDescription]
    PIVOT DateValue([InspectDateTime]);

  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,771
    Producing a field for date when there are no records requires a dataset of all possible date values to be included in the query by joining to the data table.

    Or put dummy records in the data table.

    Or specify column headings http://allenbrowne.com/ser-67.html#ColHead - not practical for your requirement unless you write VBA code to build the SQL along with QueryDefs to modify the query object
    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
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Quote Originally Posted by June7 View Post
    Or put dummy records in the data table.
    I keep a table of dates handy for this reason. Any database that needs to output dates where there may or may not be data gets this table added to it.

    Table: tblDates
    Column(s): 1
    Column Names: dtValue
    Value description: Date values between 1/1/1970 - 1/1/2050

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

Similar Threads

  1. Replies: 2
    Last Post: 12-15-2015, 03:25 AM
  2. Exporting to Excel - Column Headers
    By Xarkath in forum Access
    Replies: 2
    Last Post: 01-10-2014, 01:04 PM
  3. Replies: 10
    Last Post: 01-07-2014, 04:03 PM
  4. column report with headers along the side
    By ssalem in forum Reports
    Replies: 2
    Last Post: 06-20-2013, 02:22 PM
  5. Dynamic Column Headers but NOT CROSSTAB
    By jtkjames in forum Queries
    Replies: 1
    Last Post: 07-26-2010, 05:16 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