K
Kay Harvey via AccessMonster.com
Count select records depending on date value
I am a newbie with queries and haven?t been able to get this right. I have
the following table:
Region SaleYr InitYr
A 2005 2004
A 2003 2003
A 2003 2001
A 2002 2003
B 2004 2004
B NULL 2000
B 2002 2002
B 2004 2000
I need a query that will group by Region and SaleYr, and for each SaleYr
entry, generates a column, labeled ?InitCt? that counts the number of
InitYr entries (for that Region) that are less than or equal to that year?s
SaleYr entry. The resulting Query should show:
Region SaleYr InitCt
A 2002 1
A 2003 3
A 2005 4
B 2002 3
B 2004 4
I have tried using DCount a number of ways but can?t get it to count only
the records that meet the criteria while also not producing an error
because of the null value. Some explanation would be helpful. In general,
how do you write a query to compare all values in a field to one value of
that field or another field, and then do the same for the next record entry?
In my case, I need to compare each SaleYr entry to all InitYr entries for a
Region and Count only those that are a lesser value.
Thanks in advance.
I am a newbie with queries and haven?t been able to get this right. I have
the following table:
Region SaleYr InitYr
A 2005 2004
A 2003 2003
A 2003 2001
A 2002 2003
B 2004 2004
B NULL 2000
B 2002 2002
B 2004 2000
I need a query that will group by Region and SaleYr, and for each SaleYr
entry, generates a column, labeled ?InitCt? that counts the number of
InitYr entries (for that Region) that are less than or equal to that year?s
SaleYr entry. The resulting Query should show:
Region SaleYr InitCt
A 2002 1
A 2003 3
A 2005 4
B 2002 3
B 2004 4
I have tried using DCount a number of ways but can?t get it to count only
the records that meet the criteria while also not producing an error
because of the null value. Some explanation would be helpful. In general,
how do you write a query to compare all values in a field to one value of
that field or another field, and then do the same for the next record entry?
In my case, I need to compare each SaleYr entry to all InitYr entries for a
Region and Count only those that are a lesser value.
Thanks in advance.