Results 1 to 10 of 10
  1. #1
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10

    Cross tab query by week

    Hello, I want to create a cross tab query. Based on column customer, collection $, transaction date.
    How I would set up cross tab to show collection data by week. Week starts Thursday. And end Friday

    Cross tab should always show columns header for all weeks fall in a month

    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    Format() function can calculate a week number for the month or the year.

    Format(Date(), "w", vbThursday)

    Format(Date(), "ww", vbThursday)

    So for a yr-mo-wk value: Format(Date(), "yyyy-mm-w", vbThursday)

    Use PARAMETERS to restrict the output to a single year or year-month.
    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
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10
    I get a message, access2007 does not recognize vb Thursday,

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    Right, I was testing in VBA immediate window. Use 5 in query instead.
    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
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10
    Trandate: Format(Date(),"yyyy-mm-w",5)

    is this right? result comes only for Oct 4

  6. #6
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10
    Customer Total Of Collection 2017-10-4
    aaa 25 25
    ABC 100 100
    efg 250 250
    fff 150 150
    ggf 150 150
    ggg 50 50

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    I was only giving an example. Use your date field in place of Date().

    Trandate: Format([transaction date], "yyyy-mm-w", 5)

    BTW, advise no spaces nor punctuation/special characters (underscore only exception) in naming convention. Better would be TransDate or Trans_Date or TxnDate, Collection_Dollars or CollDollars, etc.
    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.

  8. #8
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10
    Very much grateful for your help,

    I get following result, may be I am doing some step error, Because the cross tab result is by date ,not by week.

    So Much for your help

    Customer 10/3/2017 10/12/2017 10/17/2017 10/18/2017 10/21/2017
    aaa



    25
    ABC 100



    efg 250



    fff
    150


    ggf

    150

    ggg


    50

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    Then you are not using the calculated field as the ColumnHeader in the CROSSTAB.

    Start with a normal SELECT to pull in the fields and create the calculated field. Then switch to CROSSTAB and make the CROSSTAB assignments.

    I seldom use the query wizards.
    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.

  10. #10
    Mabid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2017
    Posts
    10
    I used following and this worked.I really appreciate your help to take me there.

    Regards

    TRANSFORM Sum(Table1.Collection) AS SumOfCollection
    SELECT Table1.Customer
    FROM Table1
    GROUP BY Table1.Customer, Table1.Trandate
    PIVOT [TranDate]-DatePart("w",[TranDate])+2;

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

Similar Threads

  1. Replies: 4
    Last Post: 08-15-2017, 08:44 AM
  2. Replies: 2
    Last Post: 04-14-2016, 06:30 PM
  3. Replies: 26
    Last Post: 11-05-2015, 01:58 PM
  4. Replies: 9
    Last Post: 06-19-2015, 03:37 PM
  5. Replies: 1
    Last Post: 01-28-2015, 12:19 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