Solved

Months won't sort properly in Access Graph

Posted on 2014-12-05
6
192 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
  • 3
  • 2
6 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Try this "Order By" clause:

ORDER BY 2, 1;
0
 

Author Comment

by:chtullu135
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks again for the tip on checking that the field I wanted to sort on was actually a date field.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now