Report totals depending on value in field

T

Thel

I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 
K

KARL DEWEY

Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];
 
T

Thel

I copied your code and tried to run, got this message>
You tried to execute a query that does not include the specified expression
<name> as part of an aggregate function. (Error 3122)
I am trying to make these totals on a report in Access.
Thanks,
Thel

KARL DEWEY said:
Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];

--
Build a little, test a little.


Thel said:
I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 
K

KARL DEWEY

Post back how you modified the SQL.
--
Build a little, test a little.


Thel said:
I copied your code and tried to run, got this message>
You tried to execute a query that does not include the specified expression
<name> as part of an aggregate function. (Error 3122)
I am trying to make these totals on a report in Access.
Thanks,
Thel

KARL DEWEY said:
Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];

--
Build a little, test a little.


Thel said:
I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 
T

Thel

I went into query builder and typed the code there.

KARL DEWEY said:
Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];

--
Build a little, test a little.


Thel said:
I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 
K

KARL DEWEY

Did you solve your problem?

If not, post the SQL that gave you the error.

--
Build a little, test a little.


Thel said:
I went into query builder and typed the code there.

KARL DEWEY said:
Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];

--
Build a little, test a little.


Thel said:
I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 
T

Thel

SELECT [Dept#], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [queryeeoc]
GROUP BY [Dept#]
UNION ALL SELECT"All Departments" AS [Dept#], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [queryeeoc]
GROUP BY [Dept#];


KARL DEWEY said:
Did you solve your problem?

If not, post the SQL that gave you the error.

--
Build a little, test a little.


Thel said:
I went into query builder and typed the code there.

KARL DEWEY said:
Use these two queries --
qryMale_Female --
SELECT [Department], IIF([Gender] = "Male", 1, 0) AS [M], IIF([Gender] =
"Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department]
UNION ALL "All Departments" AS [Department], IIF([Gender] = "Male", 1, 0)
AS [M], IIF([Gender] = "Female", 1, 0) AS [F]
FROM [YourTable]
GROUP BY [Department];

SELECT [Department], Sum([M]) AS [Males], Sum([F]) AS [Females]
FROM [qryMale_Female]
GROUP BY [Department];

--
Build a little, test a little.


:

I want to add the number of "males" number of females, break by department
and also have a grand total for each. Does anyone have any sample code to do
this.
Thanks,
Thel
 

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