Solved

Months won't sort properly in Access Graph

Posted on 2014-12-05
6
199 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
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…

821 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