Setting up the following expression in a query

K

kellik105

Hello,
I am new to this forum and I have this question to start me off:

I am attempting to find the percentage of Males Hired and Females Hired in
the past year. I have 1 table I will be working from.

New Hire1 - This table includes Names, colleges, sex, start date etc.

What I want to do is enter the following expressions into a query to use them
to find the values I need.

Field 1: Total_Hires =count(*) or =count([sex])

Field 2: Female_Hires =sum(iif([sex] = "F", 1, 0))/[Total_Hires]

Field 3: Male_Hires =sum(iif([sex] = "M", 1, 0))/[Total_Hires]

Format fields 2 and 3 to be percentages

Everytime I try to enter Total Hires:Count([Sex]) into the field in the query
design view I get an error message that reads "You tried to execute a query
that does not include the specified expression ‘Sex’ as part of an aggregate
function"

If someone could give the steps to get this code to work I would be greatly
appreciative.
Thank you
Erik
 
R

RonaldoOneNil

Not sure how you are entering it in the query but your 3 columns should look
like this

Total_Hires: Count([Sex])
Female_Hires: Sum(iif([sex] = "F", 1, 0))/[Total_Hires]
Male_Hires: Sum(iif([sex] = "M", 1, 0))/[Total_Hires]

You can then right click on columns 2 and 3, select properties and change
the format to percent.
 
J

John Spencer

You MIGHT need to change that slightly to

Total_Hires: Count([Sex])
Female_Hires: Sum(iif([sex] = "F", 1, 0))/Count([Sex])
Male_Hires: Sum(iif([sex] = "M", 1, 0))/Count([Sex])

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Not sure how you are entering it in the query but your 3 columns should look
like this

Total_Hires: Count([Sex])
Female_Hires: Sum(iif([sex] = "F", 1, 0))/[Total_Hires]
Male_Hires: Sum(iif([sex] = "M", 1, 0))/[Total_Hires]

You can then right click on columns 2 and 3, select properties and change
the format to percent.

kellik105 said:
Hello,
I am new to this forum and I have this question to start me off:

I am attempting to find the percentage of Males Hired and Females Hired in
the past year. I have 1 table I will be working from.

New Hire1 - This table includes Names, colleges, sex, start date etc.

What I want to do is enter the following expressions into a query to use them
to find the values I need.

Field 1: Total_Hires =count(*) or =count([sex])

Field 2: Female_Hires =sum(iif([sex] = "F", 1, 0))/[Total_Hires]

Field 3: Male_Hires =sum(iif([sex] = "M", 1, 0))/[Total_Hires]

Format fields 2 and 3 to be percentages

Everytime I try to enter Total Hires:Count([Sex]) into the field in the query
design view I get an error message that reads "You tried to execute a query
that does not include the specified expression ‘Sex’ as part of an aggregate
function"

If someone could give the steps to get this code to work I would be greatly
appreciative.
Thank you
Erik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top