Query to sort by season + year (1 Viewer)

Bean Machine

Member
Local time
Today, 14:36
Joined
Feb 6, 2020
Messages
102
Hi All.

I am building a database that houses my grades with the intention of displaying my average grade per semester. The problem is that my field "fld_Smst". The data stored in this field goes by season first, then year, so "Fall 2018" or "Winter 2019" for example. What I would like to do is build a field in a query that essentially sorts the "fld_Smst" field to make sense, i.e., "Fall 2019" should come before "Winter 2019" and "Winter 2019" should come before "Spring 2019". I have attached an image showing how it currently sorts without a sorting field built into a query. Any help would be greatly appreciated as my brain is running on fumes after exams.
Screenshot 2023-05-02 150755.png
 

XPS35

Active member
Local time
Today, 20:36
Joined
Jul 19, 2022
Messages
159
There is a neat way and a less neat way. To start with the latter, sort by:
Code:
Right([fld_Smst],4), IIf(Left([fld_Smst],1)="S",1,IIf(Left([fld_Smst],1)="F",2,3))

A neater way requires a bit more work. Split the field into two: year and semester. Create a table in which you store the permitted values for semester (spring, autumn, winter). Also add a sort order field to that table to be able to sort the semesters correctly.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:36
Joined
May 21, 2018
Messages
8,529
Make table
tblSemesters
--SemesterName (primary key)
--SemesterYear
--Season
--Sort

example
Fall 20018 2018 Fall 1
Spring 2019 2019 Spring 2

Now join by SemesterName to fld_Smst
(my assumption is you have many records with the same Smst value)

With that now you can sort correctly on sort. Filter by year, filter by season, etc.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:36
Joined
Feb 19, 2002
Messages
43,277
I would not include school year in the lookup table. My table would be
tblSemesters
SemesterID (1,2,3, or 4)
SemesterName (Fall, Winter, Spring, Summer)

In your table, you would have the school year plus the SemesterID. Since there are only four values, as long as they are assigned as I indicated, your data will appear in logical order by school year.
 

Users who are viewing this thread

Top Bottom