Click to See Complete Forum and Search --> : Summary question


almerkaasschieter
July 4th, 2006, 06:01 AM
Hi,

I have a problem with the summary functions; I can't seem to figure out how to calculate certain averages. Here is my test case:

I have departments and employees. Each employee is in a department. An employee has a field called 'haircolor' which is either 'red', 'black', 'brown'. (not to discriminate blonds, but for the sake of example ;-))

I need, in a report, given a certain department_id, the following data:

- The number of people with brown hair in this department
- The average number of people with brown hair in all departments
- The maximum number of people with brown hair in a single department
- The minimum number of people with brown hair in a single department.

All of this in percentages. The main report query retrieves all employees from all departments, so the main query returns things like:


department_id employee_id haircolor
--------------------------------------------------
1 1 brown
1 2 brown
1 3 black
2 4 red
2 5 red


The summary in this case for department 1 would be:


brownhaired blackhaired redhaired
-------------------------------------------------------------------------------
department 1: 66% 33% 0%
average 40% 20% 40%
max 66% 33% 100%
min 0% 0% 0%


In other words, max redhaired is 100% because the maximum number of reds on any department is 100% (department 2). Minimum is 0 because there are departments where none of the colors occur.

As you may see from the example, the goal of this report is to compare the numbers of a department with other departments.

I managed to get the first line working, and the second too, using running totals. This prevents me from adding the max and min however. I have the feeling that I should use the Average, Maximum and Minimum summary functions, however, I can only find examples that use these methods on numerical values, while in this case I need averages on 'if color = red' kinda constructs.

Does anybody have an idea how to built such a report?

almerkaasschieter
July 11th, 2006, 03:39 AM
Isn't there anyone who can help me with this problem ? I know the description is quite long, but i'm just being thorough with the explanation of my test-case

wapper
July 13th, 2006, 11:22 AM
Aarggghhhh that was a nice exercise. Spent almost an hour to recall basics for manual running totals.

You don't need RT-s to get values for department rows and for average row. But for Min and Max rows, the only way is manual running totals. Why? Crystal does not allow to create summaries that are based on another summaries. It doesn't matter if you try to create an ordinary summary or a Crystal running total, it just can't summarize other summaries. But this is what you need to get max/min values of a department, because department % is actually a summary.

Take a look into attachment. In real life, I hate such reports, they are messy and hard to debug.

almerkaasschieter
July 18th, 2006, 04:26 AM
Thank you for your time, wapper! I'm going to try it out right away.