Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Months won't sort properly in Access Graph

Posted on 2014-12-05
6
Medium Priority
?
214 Views
Last Modified: 2014-12-05
Hello,

I am trying to create a Access stack column graph based on a query that uses the horizontal axis to display the months.  However, the month won't display in sequence.  Running the query, shows that the month are displayed in order.  Below is the query. Owing to how the data is stored in the tables, I had to make use of aUnion query
SELECT DISTINCT 1 As SortOrder, Savings.Yr, MonthName(1, true) AS [Month], Sum(SavingAmounts.SourcingSavings_01) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_01) AS CostAvoidance, Sum(Planning.Month_01) AS PlanningAmt, Sum([SourcingSavings_01]+[CostAvoidance_01]+[Month_01]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 2 As SortOrder, Savings.Yr, MonthName(2, true) AS [Month], Sum(SavingAmounts.SourcingSavings_02) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_02) AS CostAvoidance, Sum(Planning.Month_02) AS PlanningAmt, Sum([SourcingSavings_02]+[CostAvoidance_02]+[Month_02]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 3 As SortOrder, Savings.Yr, MonthName(3, true) AS [Month], Sum(SavingAmounts.SourcingSavings_03) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_03) AS CostAvoidance, Sum(Planning.Month_03) AS PlanningAmt, Sum([SourcingSavings_03]+[CostAvoidance_03]+[Month_03]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 4 As SortOrder, Savings.Yr, MonthName(4, true) AS [Month], Sum(SavingAmounts.SourcingSavings_04) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_04) AS CostAvoidance, Sum(Planning.Month_04) AS PlanningAmt, Sum([SourcingSavings_04]+[CostAvoidance_04]+[Month_04]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 5 As SortOrder, Savings.Yr, MonthName(5, true) AS [Month], Sum(SavingAmounts.SourcingSavings_05) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_05) AS CostAvoidance, Sum(Planning.Month_05) AS PlanningAmt, Sum([SourcingSavings_05]+[CostAvoidance_05]+[Month_05]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 6 As SortOrder, Savings.Yr, MonthName(6, true) AS [Month], Sum(SavingAmounts.SourcingSavings_06) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_06) AS CostAvoidance, Sum(Planning.Month_06) AS PlanningAmt, Sum([SourcingSavings_06]+[CostAvoidance_06]+[Month_06]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 7 As SortOrder, Savings.Yr, MonthName(7, true) AS [Month], Sum(SavingAmounts.SourcingSavings_07) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_07) AS CostAvoidance, Sum(Planning.Month_07) AS PlanningAmt, Sum([SourcingSavings_07]+[CostAvoidance_07]+[Month_07]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 8 As SortOrder, Savings.Yr, MonthName(8, true) AS [Month], Sum(SavingAmounts.SourcingSavings_08) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_08) AS CostAvoidance, Sum(Planning.Month_08) AS PlanningAmt,Sum([SourcingSavings_08]+[CostAvoidance_08]+[Month_08]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 9 As SortOrder, Savings.Yr, MonthName(9, true) AS [Month], Sum(SavingAmounts.SourcingSavings_09) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_09) AS CostAvoidance, Sum(Planning.Month_09) AS PlanningAmt, Sum([SourcingSavings_09]+[CostAvoidance_09]+[Month_09]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 10 As SortOrder, Savings.Yr, MonthName(10, true) AS [Month], Sum(SavingAmounts.SourcingSavings_10) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_10) AS CostAvoidance, Sum(Planning.Month_10) AS PlanningAmt, Sum([SourcingSavings_10]+[CostAvoidance_10]+[Month_10]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 11 As SortOrder, Savings.Yr, MonthName(11, true) AS [Month], Sum(SavingAmounts.SourcingSavings_11) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_11) AS CostAvoidance, Sum(Planning.Month_11) AS PlanningAmt, Sum([SourcingSavings_11]+[CostAvoidance_11]+[Month_11]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION SELECT DISTINCT 12 As SortOrder, Savings.Yr, MonthName(12, true) AS [Month], Sum(SavingAmounts.SourcingSavings_12) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_12) AS CostAvoidance, Sum(Planning.Month_12) AS PlanningAmt, Sum([SourcingSavings_12]+[CostAvoidance_12]+[Month_12]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr
ORDER BY Savings.Yr, sortorder;

Open in new window

0
Comment
Question by:chtullu135
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40483482
the month are sorted correctly based on their names, Apr comes first

if you need to sort them in sequence, create another formatted date field,  i.e., Format(Datefield, "yyyy mm")  and use this field for your sorting
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 40483582
Try this "Order By" clause:

ORDER BY 2, 1;
0
 

Author Comment

by:chtullu135
ID: 40483757
Hello Rey,

Still no luck. Below is the modified code
SELECT DISTINCT 1 As SortOrder, Savings.Yr, MonthName(1, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_01) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_01) AS CostAvoidance, Sum(Planning.Month_01) AS PlanningAmt, Sum([SourcingSavings_01]+[CostAvoidance_01]+[Month_01]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr
 
UNION

SELECT DISTINCT 2 As SortOrder, Savings.Yr, MonthName(2, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_02) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_02) AS CostAvoidance, Sum(Planning.Month_02) AS PlanningAmt, Sum([SourcingSavings_02]+[CostAvoidance_02]+[Month_02]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 3 As SortOrder, Savings.Yr, MonthName(3, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_03) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_03) AS CostAvoidance, Sum(Planning.Month_03) AS PlanningAmt, Sum([SourcingSavings_03]+[CostAvoidance_03]+[Month_03]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 4 As SortOrder, Savings.Yr, MonthName(4, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_04) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_04) AS CostAvoidance, Sum(Planning.Month_04) AS PlanningAmt, Sum([SourcingSavings_04]+[CostAvoidance_04]+[Month_04]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 5 As SortOrder, Savings.Yr, MonthName(5, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_05) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_05) AS CostAvoidance, Sum(Planning.Month_05) AS PlanningAmt, Sum([SourcingSavings_05]+[CostAvoidance_05]+[Month_05]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 6 As SortOrder, Savings.Yr, MonthName(6, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_06) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_06) AS CostAvoidance, Sum(Planning.Month_06) AS PlanningAmt, Sum([SourcingSavings_06]+[CostAvoidance_06]+[Month_06]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 7 As SortOrder, Savings.Yr, MonthName(7, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_07) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_07) AS CostAvoidance, Sum(Planning.Month_07) AS PlanningAmt, Sum([SourcingSavings_07]+[CostAvoidance_07]+[Month_07]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 8 As SortOrder, Savings.Yr, MonthName(8, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_08) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_08) AS CostAvoidance, Sum(Planning.Month_08) AS PlanningAmt,Sum([SourcingSavings_08]+[CostAvoidance_08]+[Month_08]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 9 As SortOrder, Savings.Yr, MonthName(9, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_09) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_09) AS CostAvoidance, Sum(Planning.Month_09) AS PlanningAmt, Sum([SourcingSavings_09]+[CostAvoidance_09]+[Month_09]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 10 As SortOrder, Savings.Yr, MonthName(10, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_10) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_10) AS CostAvoidance, Sum(Planning.Month_10) AS PlanningAmt, Sum([SourcingSavings_10]+[CostAvoidance_10]+[Month_10]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 11 As SortOrder, Savings.Yr, MonthName(11, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_11) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_11) AS CostAvoidance, Sum(Planning.Month_11) AS PlanningAmt, Sum([SourcingSavings_11]+[CostAvoidance_11]+[Month_11]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION SELECT DISTINCT 12 As SortOrder, Savings.Yr, MonthName(12, true) AS [Month], Format([Month], "yyyy mm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_12) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_12) AS CostAvoidance, Sum(Planning.Month_12) AS PlanningAmt, Sum([SourcingSavings_12]+[CostAvoidance_12]+[Month_12]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr
ORDER BY Saving.Yr, SortMonth;

Open in new window

0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40483773
what is the content of the  [Month]  field, is this a DateTime field?
you have to use a Date Field not  [Month]

better if you can upload a copy of the db
0
 

Author Comment

by:chtullu135
ID: 40484019
Hello Rey,
I found the problem.  As you intimated, the month field was a text field, and not a date field. I used the cdate function to convert it and it is now displaying properly.  Below is the code.  I'll be getting rid of some of the fields that are no longer necessary.

SELECT DISTINCT 1 AS SortOrder, Savings.Yr,  CDATE(Cstr( "1/1/" & Savings.yr)) AS [Month], Format([Month],"mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_01) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_01) AS CostAvoidance, Sum(Planning.Month_01) AS PlanningAmt, Sum([SourcingSavings_01]+[CostAvoidance_01]+[Month_01]) AS TotalAmt
FROM Tiers RIGHT JOIN (((Projects LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID) LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org
GROUP BY Savings.Yr;

UNION

SELECT DISTINCT 2 As SortOrder, Savings.Yr, CDATE(Cstr( "2/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_02) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_02) AS CostAvoidance, Sum(Planning.Month_02) AS PlanningAmt, Sum([SourcingSavings_02]+[CostAvoidance_02]+[Month_02]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 3 As SortOrder, Savings.Yr, CDATE(Cstr( "3/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_03) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_03) AS CostAvoidance, Sum(Planning.Month_03) AS PlanningAmt, Sum([SourcingSavings_03]+[CostAvoidance_03]+[Month_03]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 4 As SortOrder, Savings.Yr, CDATE(Cstr( "4/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_04) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_04) AS CostAvoidance, Sum(Planning.Month_04) AS PlanningAmt, Sum([SourcingSavings_04]+[CostAvoidance_04]+[Month_04]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 5 As SortOrder, Savings.Yr, CDATE(Cstr( "5/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_05) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_05) AS CostAvoidance, Sum(Planning.Month_05) AS PlanningAmt, Sum([SourcingSavings_05]+[CostAvoidance_05]+[Month_05]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 6 As SortOrder,Savings.Yr, CDATE(Cstr( "6/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_06) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_06) AS CostAvoidance, Sum(Planning.Month_06) AS PlanningAmt, Sum([SourcingSavings_06]+[CostAvoidance_06]+[Month_06]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 7 As SortOrder, Savings.Yr, CDATE(Cstr( "7/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_07) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_07) AS CostAvoidance, Sum(Planning.Month_07) AS PlanningAmt, Sum([SourcingSavings_07]+[CostAvoidance_07]+[Month_07]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 8 As SortOrder, Savings.Yr, CDATE(Cstr( "8/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_08) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_08) AS CostAvoidance, Sum(Planning.Month_08) AS PlanningAmt,Sum([SourcingSavings_08]+[CostAvoidance_08]+[Month_08]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 9 As SortOrder, Savings.Yr, CDATE(Cstr( "9/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_09) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_09) AS CostAvoidance, Sum(Planning.Month_09) AS PlanningAmt, Sum([SourcingSavings_09]+[CostAvoidance_09]+[Month_09]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 10 As SortOrder, Savings.Yr, CDATE(Cstr( "10/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_10) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_10) AS CostAvoidance, Sum(Planning.Month_10) AS PlanningAmt, Sum([SourcingSavings_10]+[CostAvoidance_10]+[Month_10]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION

SELECT DISTINCT 11 As SortOrder, Savings.Yr, CDATE(Cstr( "11/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_11) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_11) AS CostAvoidance, Sum(Planning.Month_11) AS PlanningAmt, Sum([SourcingSavings_11]+[CostAvoidance_11]+[Month_11]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr

UNION SELECT DISTINCT 12 As SortOrder, Savings.Yr, CDATE(Cstr( "12/1/" & Savings.yr)) AS [Month], Format([Month], "mmm") AS SortMonth, Sum(SavingAmounts.SourcingSavings_12) AS SourceSavings, Sum(SavingAmounts.CostAvoidance_12) AS CostAvoidance, Sum(Planning.Month_12) AS PlanningAmt, Sum([SourcingSavings_12]+[CostAvoidance_12]+[Month_12]) AS TotalAmt
FROM (Tiers RIGHT JOIN ((Projects LEFT JOIN SavingAmounts ON Projects.Proj_ID = SavingAmounts.Project_ID) RIGHT JOIN (Employee INNER JOIN (Commodity RIGHT JOIN Savings ON Commodity.CommodityID = Savings.CommodityID) ON Employee.CUID = Savings.CUID) ON Projects.Proj_ID = Savings.Proj_ID) ON Tiers.Org = Savings.Tier_Org) LEFT JOIN Planning ON Projects.Proj_ID = Planning.Proj_ID
GROUP BY Savings.Yr
ORDER BY Savings.Yr, Month;

Open in new window

0
 

Author Closing Comment

by:chtullu135
ID: 40484152
Thanks again for the tip on checking that the field I wanted to sort on was actually a date field.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question