Solved

Percentage in Crosstab

Posted on 2004-09-28
4
785 Views
Last Modified: 2010-08-05
Hi, Experts

We are using CR 8.5 and MS SQL Server 2000

I have a crosstab in the report.
It looks like this

--------------------------------------------------------------------
|                              |    Cat1     |    Cat2      |Total        |
--------------------------------------------------------------------
|Group 1|SubGroup1 |Sum(FLD1)|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|Sum(FLD2)|Sum(FLD2)|
|           |--------------------------------------------------------|
|           |SubGroup2 |Sum(FLD1)|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|Sum(FLD2)|Sum(FLD2)|
--------------------------------------------------------------------
|Group 2| ..... and so on


FLD1 - is number of total attempts to do smth.
FLD2 - is number of fails

I need instead of those fields show the Percentage of success so if FLD1= 100 and Fld2=3 I need to Display 97%

But I can't use totals in formula in Crosstab. Is there is a way to do it?

Thanks in advance.
0
Comment
Question by:Michael_D
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 500 total points
ID: 12172207
In order to accomplish your goal in CR 8.5, you need to create a manual crosstab.  You can't use the wizard.

1)  Create groups as you have
2)  Create Column Labels
3)  Create formulas that will be placed in the detail section of the report.  These formulas will be something like:

@Cat1_Fld1
If
  Category = Cat1
Then
  FLD1
Else
  0

Based on your example, you'll need to create 4 formulas:  Cat1_Fld1, Cat2_Fld1, Cat1_Fld2 and Cat2_Fld2.  Each formula will be similar to the one shown above.

4)  Right-click on each of these formulas--once they're in the detail section--and Insert Summary.  You're going to Sum the values (assuming FLD2 and FLD2 have numeric values) both the subgroup and the primary group.

5)  Hide or suppress the detail section.

6)  Create two formulas at the subgroup level, each of which will calculate the percentage for its respective column.  Each formula will look something like this:

@Cat1_subgroup_percentage
If
  Sum(@Cat1_Fld1,subgroupfield) <> 0
Then
  ((Sum(@Cat1_Fld1,subgroupfield) - Sum(@Cat1_Fld2,subgroupfield)) / Sum(@Cat1_Fld1,subgroupfield)) * 100
Else
  0

7)  Next you'll create formulas for the Row totals at the subgroup level.  The row totals formulas will look like this (alternate, you can just right-click on the Fld1 and Fld2 fields and Insert summary in the appropriate group footers):

@Subgroup_fld1_row_total
//Assuming that there are only two categories
//you can simply take a sum of FLD1, which will contain values
//for each category
Sum(FLD1,subgroupfield)

@Subgroup_fld2_row_total
//Assuming that there are only two categories
//you can simply take a sum of FLD2, which will contain values
//for each category
Sum(FLD2,subgroupfield)

8)  Next, you'll create a row percentage similar to the following:

@Subgroup_row_percentage
If
  Sum(Fld1,subgroupfield) <> 0
Then
  ((Sum(Fld1,subgroupfield) - Sum(Fld2,subgroupfield)) / Sum(Fld1,subgroupfield)) * 100
Else
  0

9)  You'll need to repeat these steps to create summaries at the primary group level and at the Grand Total Level

~Kurt

0
 
LVL 13

Author Comment

by:Michael_D
ID: 12172669
Thank you very much, Kurt.
I know how to do it If I only have fixed number of columns. The only advantage of crosstab  is being dynamic. I can't use your method because I want to be able to enlarge  my crosstab dynamicly based on data in the table.
You told that this is impossible in CR 8.5. Can I Do it with CR9 or 10?
0
 
LVL 13

Author Comment

by:Michael_D
ID: 12172695
So my "picture" should be like this

----------------------------------------~~~----------------------------
|                              |    Cat1     |~~~|    CatN      |Total        |
----------------------------------------~~~----------------------------
|Group 1|SubGroup1 |Sum(FLD1)|~~~|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|~~~|Sum(FLD2)|Sum(FLD2)|
|           |-----------------------------~~~---------------------------|
|           |SubGroup2 |Sum(FLD1)|~~~|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|~~~|Sum(FLD2)|Sum(FLD2)|
----------------------------------------~~~----------------------------
|Group 2| ..... and so on
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 12175063
Actually, there is something you can use formulas in crosstabs in 8.5.  In your scenario, you want to calculate the percent of successful attempts, correct?  I don't know how your data is structure, so I'm going to make some assumptions for the sake of the example.

FLD1 identifies an attempt and is Counted in the Crosstab
FLD2 identifies a failure and is a boolean of some sort (yes/no, 1/0, etc..)

In the Format Cross-Tab dialogue box, click the <New Formula> button.  You will create a formula that will help you calculate the successful attempts.  It may look something like this:

@Successful_Attempts
If
  {table.field2} = No//indicating that the 'Failed attempt' flag is no, therefore a 'Success'
Then
  1
Else
  0

Next, insert this new formula field (@Successful_Attempts) into the Summarized fields twice - once to be summed as the number of successful attempts and once to be averaged.  Your report will look something like this (@Successful_Attempts is referred to as FLD3):

----------------------------------------~~~----------------------------
|                              |    Cat1     |~~~|    CatN      |Total        |
----------------------------------------~~~----------------------------
|Group 1|SubGroup1 |Sum(FLD1)|~~~|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|~~~|Sum(FLD2)|Sum(FLD2)|
|           |                 |Sum(FLD3)|~~~|Sum(FLD3)|Sum(FLD3)|
|           |                 |Avg (FLD3)|~~~|Avg (FLD3)|Avg  (FLD3)|
|           |-----------------------------~~~---------------------------|
|           |SubGroup2 |Sum(FLD1)|~~~|Sum(FLD1)|Sum(FLD1)|
|           |                 |Sum(FLD2)|~~~|Sum(FLD2)|Sum(FLD2)|
|           |                 |Sum(FLD3)|~~~|Sum(FLD3)|Sum(FLD3)|
|           |                 |Avg (FLD3)|~~~|Avg (FLD3)|Avg  (FLD3)|
----------------------------------------~~~----------------------------

The downside is that you can't really format the average to look like a true percentage.  It will come out looking like .97 instead of 97%.  The upside is that you can basically calculate percentages at the column level.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now