Keeping a static number of fields

MisterCrash

Active Member
Joined
Jan 27, 2003
Messages
279
I have a database of people, and I run a query that groups people by age and counts the number of people that are at a particular age. The results of this are then pasted into an Excel spreadsheet, which performs various calculations based on the age.

However, some age groups are not represented in the database (for example, there are no 61-year-olds), and the output from Access has no entry for these ages. I would greatly prefer it if Age 61 did show up in the query result, but would have a value of zero (otherwise, I have to reconfigure the Excel sheet every time the last person leaves an age group or the first person goes into a previously vacant age group).

The solution I have been using is to create a dummy table (with the field [TableAge]) that lists the range of ages I'm interested in, then calculates the number of people of that age by:

=IIF([Age]=[TableAge], [CountOfMemberID], 0)

However, this seems computationally cumbersome, and I wondered if Access had a simpler means of accomplishing this feat. Thank you!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this: Before you get to the Counting query, write a query which will capture all the ages record by record and set up your iif criteria there: iif([yourtable].[age]>youragecriteria,0,[yourtable].[age])

So what you're saying here is "If the age is greater than a certain criteria, then return a 0, else return the original number". Then, Count off of this query in your second query. Of course, the more criteria that you have, the heavier your iif statement will be, but either way it should accomplish your task.
 
Upvote 0

Forum statistics

Threads
1,221,527
Messages
6,160,342
Members
451,638
Latest member
MyFlower

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