Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Months won't sort properly in Access Graph

Posted on 2014-12-05
6
Medium Priority
?
216 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 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

824 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