Sorting access query data

outlook

Board Regular
Joined
Jun 16, 2010
Messages
93
PLEASE HELP!!!

I want to sort data in order by date, but it only sorts in alaphabetical order.

Does anyone know if I'm doing something wrong? Or how I can correct it?

Thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If you have a date field (eg, real dates not text), make sure that the Sort row says Ascending (or Descending if you want last date first).

If the date sorting needs to be the highest priority, put the field first in the grid; Access prioritises sorting in left to right order across the grid.

Denis
 
Upvote 0
It's a group query, so it takes real dates in the origial query, and then totals them by month in the group query.

Thus the month first is Dec, then Feb, Then Jan.

Any ideas?
 
Upvote 0
Create a field with the month number, and sort on that. There is no need to display it in the query result; just use it for sorting.

Also, if you build a crosstab using the wizard and group dates, you will find that they generally sort by date rather than alphabetically. Check out the expression that Access uses for the date formatting.

Denis
 
Upvote 0
I'm sorry to be a pain, but when you say "Create a field with the month number", what exactly do you mean by this?

Thank you, AGAIN!
 
Upvote 0
Assuming that you have a real date field in the data set, you can use that.

If you only have the text items "Apr", "Aug", "Feb", etc they will sort alphabetically.

However, you can use the CHOOSE function to turn those descriptions into month numbers. Something like this, in the query --

Code:
MonthNumber:CHOOSE([your date heading field],"Jan","Feb","Mar",...,"Dec")

Change the name of the heading field to suit. Add the full list of months to the CHOOSE function. I got lazy, and only typed enough to demonstrate the concept.

Denis
 
Upvote 0
Thank you for your help so far, but I am still having problems ...

Table has an actual date field called DEPOSIT DATE, so data would be 01/01/2011 for example.

Initial query then counts the number of deposits on each date, and shows them by the BRANCH field.

The total query then uses the intial query, by grouping the data by into months, and shows them in full month and year format, ie December 2010.

At the moment the total query is sorting the month by alphabetical order, which I do not want, so as you suggested I added a CHOOSE field. However it doesn't change the sort order, and when I show it, it's blank.

Somehow I've missed something in what your instructions. Shall I post my choose code? Or maybe you have some other ideas?

Thank you.
 
Upvote 0
Paste what you have, but another option would be to have an extra expression in the query. eg,

DepositMonth:Month([DEPOSIT DATE])

You can group on that as well, and you should be able to sort the months correctly.

Denis
 
Upvote 0
This is the field that groups the actual dates together:
DEPOSIT DATE By Month: Format$([Deposit Query].[DEPOSIT DATE],'mmmm yyyy')

Then, there's the field you suggested to sort the month by number:
MonthNumber: Choose([DEPOSIT
DATE],"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

My first thought is that maybe the choose function should be full months and years, ie. "January 2011"?

Also, what happens when you have Jan 2011 & Jan 2012 for example if you just use "Jan"?

Thanks.
 
Upvote 0
Try creating another field in the query:

DepositMonth:Month([Deposit Query].[DEPOSIT DATE])

Denis
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top