Solved

Months won't sort properly in Access Graph

Posted on 2014-12-05
6
195 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
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 119

Expert Comment

by:Rey Obrero
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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.

910 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

22 Experts available now in Live!

Get 1:1 Help Now