Results 1 to 10 of 10
  1. #1
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211

    Chart

    I have been trying for hours to add ALL MONTHS (January - December) to the x-axis (red box) and not just the months with entries. Any ideas.



    Click image for larger version. 

Name:	Picture1.png 
Views:	19 
Size:	40.2 KB 
ID:	31876
    Last edited by SierraJuliet; 01-02-2018 at 05:32 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Really need to know your data and the query you use. I analyze chart issues best when I can work with data. If you want to provide db 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
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    This is what the current SQL statement is for the chart, which was auto generated:

    TRANSFORM Count([CaseNum]) AS [CountOfCaseNum] SELECT (Format([DateCreated],"MMM 'YY")) FROM [tblCase] GROUP BY (Year([DateCreated])*12 + Month([DateCreated])-1),(Format([DateCreated],"MMM 'YY")) PIVOT (Year([DateCreated]));

    The only things changed above are bolded in the statement and this was the defaulted value:

    I changed this "Count(*) As [Count]"

    I removed this "-1"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Perhaps specify column headings in the CROSSTAB. Review http://allenbrowne.com/ser-67.html#ColHead
    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
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    I will take a look at your reference and get back to you, thank you.

    In the meantime I modified the SQL statement as follows:

    TRANSFORM Count(CaseNum) AS [CaseCount]
    SELECT (Format(tblCase.[DateCreated],"MMM")) AS Months
    FROM tblCase
    GROUP BY (Month([DateCreated])),(Format([DateCreated],"MMM"))
    PIVOT (Year([DateCreated]));

    This is what the design view, datasheet view, and form view chart looks like now:
    Click image for larger version. 

Name:	snapshot 4.PNG 
Views:	20 
Size:	6.7 KB 
ID:	31875
    Click image for larger version. 

Name:	snapshot 1.PNG 
Views:	22 
Size:	3.6 KB 
ID:	31872
    Click image for larger version. 

Name:	snapshot 2.PNG 
Views:	22 
Size:	6.6 KB 
ID:	31873

    At least now I have the months appearing in order and without the redundant "YY" appended to each month.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Nope, specifying column headings won't help provide a datapoint for every month.

    Will need at least one record for each month. Use a table of months.
    Mon MonNum
    Jan 1
    Feb 2
    Mar 3
    Apr 4
    May 5
    Jun 6
    Jul 7
    Aug 8
    Sep 9
    Oct 10
    Nov 11
    Dec 12

    UNION the original data table to Months and use that as the source for CROSSTAB. Example of all-in-one query:

    TRANSFORM Count(Query1.CaseNum) AS CountOfCaseNum
    SELECT Query1.Mon
    FROM (SELECT Month([DateCreated]) AS MonNum, Format([DateCreated], "mmm") AS Mon, Year([DateCreated]) AS Yr, CaseNum FROM tblCase
    UNION SELECT MonNum, Mon, Null, Null FROM Months) AS Query1
    GROUP BY Query1.MonNum, Query1.Mon
    PIVOT Query1.Yr;

    The legend will show an item with no year number unless you assign a year like 2000 to the dummy month records. Can do that in the UNION. Instead of the Null under Yr, use 2000. In this case the legend will show 2000.

    Unfortunately, the lines for each Yr series cannot be continuous because of missing data. Would need a dummy record for every month/year combination. A Cartesian query can accomplish that, assumes at least one record for each desired year in the data table:

    SELECT Mon, MonNum, Year([DateCreated]) AS Yr FROM Months, tblCase;

    The revised all-in-one query:

    TRANSFORM Count(Query1.CaseNum) AS CountOfCaseNum
    SELECT Query1.Mon
    FROM (SELECT Month([DateCreated]) AS MonNum, Format([DateCreated], "mmm") AS Mon, Year([DateCreated]) AS Yr, CaseNum FROM tblCase
    UNION SELECT MonNum, Mon, Year([DateCreated]) AS Yr, Null FROM Months, tblCase) AS Query1
    GROUP BY Query1.MonNum, Query1.Mon
    PIVOT Query1.Yr;

    If certain there is at least one record for every month as well as year, the Months table would not be needed and the nested inner query could be:

    SELECT Month([DateCreated]) AS MonNum, Format([DateCreated], "mmm") AS Mon, Year([DateCreated]) AS Yr, CaseNum FROM tblCase
    UNION SELECT Month([DateCreated]) AS MonNum, Format([DateCreated],"mmm") AS Mon, Year([DateCreated]) AS Yr, Null FROM tblCase

    Consider column chart.
    Last edited by June7; 01-02-2018 at 03:18 PM.
    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
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    You read my mind . I created a month table that both spells out each month (a just in case later option), the three letter abbreviation, and instead of MonOrder I simply used ID field which is 1 to 12 based on order of entry. I typically use the ID field to ORDER BY to keep my desired entries in order when performing a lookup query to populate a drop down list of options and it is just a good idea in my opinion to include an "ID" field to avoid certain issues even though it may not be my tables primary key, which is a separate serial number for each table's records.

    I agree if I could guarantee at least one record for each month regardless of year then the whole month lookup table is extra and what I already have would suffice but, since I cannot as the examples show then I want to ensure each month is present because it looks cleaner in my opinion. I will post my results when successful or if there is something important to share with everyone.

    Thanks a lot for your help!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Here's another way to generate the Months dataset:

    SELECT DISTINCT Abs([id] Mod 12)+1 AS N, Choose([N], "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","S ep","Oct","Nov","Dec") AS Mon FROM MsysObjects;
    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
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    I modified the TRANSFORM UNION PIVOT you provided to work with what I have and made the query more descriptive for the given chart.

    The following is the modified version of your awesome query:

    TRANSFORM Count(CaseTrend.CaseNum) AS CountOfCaseNum
    SELECT CaseTrend.MonthAbbr
    FROM
    (SELECT Month([DateCreated]) AS ID, Format([DateCreated], "mmm") AS MonthAbbr, Year([DateCreated]) AS Yr, CaseNum
    FROM tblCase
    UNION SELECT DISTINCT tblLookupMonth.ID, MonthAbbr, Year([DateCreated]) AS Yr, Null
    FROM tblLookupMonth, tblCase) AS CaseTrend
    GROUP BY CaseTrend.ID, CaseTrend.MonthAbbr
    PIVOT CaseTrend.Yr;

    The following is the result:
    Click image for larger version. 

Name:	snapshot 5.PNG 
Views:	13 
Size:	11.8 KB 
ID:	31883

    I may do some rework to bypass the null values in the future, such as only plotting any value greater than 0. However, I believe we can mark this post as solved. Thank you for all your assistance.

  10. #10
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    I used the IN ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec") before but created the table instead as it may be used elsewhere later.

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

Similar Threads

  1. Replies: 11
    Last Post: 12-25-2015, 02:41 PM
  2. Limit chart to date range , Chart isnt updating .
    By fluffyvampirekitten in forum Access
    Replies: 5
    Last Post: 06-30-2015, 12:27 AM
  3. Replies: 4
    Last Post: 04-07-2015, 11:37 AM
  4. Replies: 9
    Last Post: 01-29-2013, 06:44 PM
  5. Replies: 2
    Last Post: 07-12-2010, 05:39 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