Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Percentages per group

Status
Not open for further replies.

waldopepper

Programmer
Nov 21, 2003
124
GB
Hi!

Not sure if I'm doing something stupid here (likely) but I have a variable that contains either blank value or 'Yes'.

What I've done is create a Formula from this

if {vw_Crystal_All.bkp_marketing_Posters} <> '' then 1 else 0

Then created a summary (sum) per group so I have a count of the number of records that have answered 'Yes' in each group.
What I now need to do is also show a percentage of 'Yes' per group. Copying the summary I've already created and changing it to a percentage of that variable brings back a percentage that is not right.

First group:
35 'Yes'
1,026 total records
So the percentage should be about 3% but it's displayed as 13%.

Is this the wrong approach and do I need to create a new Formula to calculate this?

Crystal Reports v10
SQL 2000
 
Rather than writing formulas, it's easier to use Crystals automatic totals - see FAQ767-6524 if you're not already familiar with them.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thanks - I'm already using a Summary for the count per group, but I can't seem to get percentages to work using this method. Just wondering what I might be doing wrong!
 
You could try a running total using a formula to make the selection.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
If you want the percentage per group, try:

sum({@yourformula},{table.groupfield})%count({table.groupfield},{table.groupfield})

-LB
 
Thanks LB, I assume the variable name goes in the groupfield bit, not the actual groupname?

Like this?

sum({@marketing_posters},{@Airport_UK_full})%count({@Airport_UK_full},{@Airport_UK_full})

The report is grouped by {@Airport_UK_full}

The formula for @marketing_posters is:
if {vw_Crystal_All.bkp_marketing_Posters} <> '' then 1 else 0

When I drag the result of this into the group and run it, I get this error: "A summary has been specified on a non-reccuring field."

anyone know what this means?

ta
 
Probably means your field can be null. Change your conditional formula to:

if isnull({vw_Crystal_All.bkp_marketing_Posters}) or
{vw_Crystal_All.bkp_marketing_Posters} = '' then
0 else 1

-LB
 
Thanks - I've changed the formula as you've suggested but ther error message is the same.

?
 
Oh my bad - it was another test variable I had left in there that was returning this error.

Your code works great - thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top