Solved

Sort Fiscal Months Desc by Name

Posted on 2008-09-29
5
600 Views
Last Modified: 2010-04-21
Hi -

I am trying to sort a report by fiscal month desc. Since our fiscal year begins in July and ends in June, the latest month for a year would be June sorted through July:

June
May
April
March

Or for the current date/year
September
August
July

I have found a way to do this whenever I have a fiscal month number or week number to work with, but for this particular table all I have is a fiscal month name, so sorting results in an alphabetical sort which I do not want. Is there a way to select the fiscal month as is by name, but select again to convert to a number so that I can sort it by the latest to the earliest? Or do I just have to add something behind the scenes (I prefer not to change the table) and like a case statement, and sort by a number assigned?

Thanks -
SD
0
Comment
Question by:savetheday
  • 3
5 Comments
 
LVL 5

Expert Comment

by:NutrientMS
ID: 22600390
As far as I am aware sorting on a Month name will only do it alphabetically.  What I would do if you are able to modify the table is to add a colum for month number.  Where Month Date = January, month number = 1 etc... Then order it by Month Number.

I'm not sure if there is a way to incorporate something similar into your query.
0
 
LVL 5

Accepted Solution

by:
adlink_la earned 50 total points
ID: 22600539
Create a Date Dimension table.  Take a look at the table structure in the following article.  Im not saying you need a table with all of that stuff in it.  But if you use the same concept and create a table that has a row for every date and columns like FiscalMonthNumber, FiscalMonthName, FiscalQuarter, FiscalYear, etc., then you can increment the FiscalYear in July and set all of the other columns appropriately.  (One thing regarding the table structure in the article  I wouldnt use Date as a column name because it is a reserved word, maybe CalendarDate or whatever).

http://it.toolbox.com/wiki/index.php/Create_a_Time_Dimension_/_Date_Table


Using this table, you could sort dates for the year by doing something like:

SELECT CalendarDate
FROM Dates
WHERE FiscalYear = 2008
ORDER BY CalendarDate

Or you could join to your table with month names like:

SELECT d.CalendarDate, &
FROM Dates d
JOIN myTable a ON a.FiscalMonthName = d.FiscalMonthName
ORDER BY d.CalendarDate
0
 
LVL 5

Expert Comment

by:adlink_la
ID: 22600632
BTW, FiscalMonthName may not necessarily be the same as CalendarMonthName if the fiscal month does not start on the first of the month.  For example if the month always starts on the first Thursday or if there is some other obscure business rule, that is very easy to handle in a table.
0
 

Author Closing Comment

by:savetheday
ID: 31501341
Yes - joined the table on the other table to get the fiscal month number. Query runs slower but it works! Thanks!
SD
0
 
LVL 5

Expert Comment

by:adlink_la
ID: 22602084
You can probably speed it up by putting an index on the column you are joining on.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Hello, In my precious Article  (http://www.experts-exchange.com/Database/Reporting/A_15280-Create-Project-in-Microstrategy-Part-I.html)we saw the Configuration part for Microstrategy which included Metadata Creation and DataSource Preparation as …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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

11 Experts available now in Live!

Get 1:1 Help Now