Formula for Summary Across Hierarchy

Posted on 2004-08-16
Last Modified: 2008-02-01
I am working on a report that uses group by hierarchy feature. I can get summaries for two columns at different levels by ticking 'summary across hierarchy' box. But I can't do calculations over the summarized fields.(summary across hierarchy) using formula.

In fact, if I don't tick 'summary across hierarchy' box, the summary value will not show up in preview as well.  Also I notice, when I was editing
the formula, I click on the summary field available( this was generated by inserting summary and tick 'summary across hierarchy') , it shows
the following:
  Sum ({Tablename.ColumnA},{Talbename.Employee_ID})
If I just use this as content of the formula, it will also not show anything when previewing it.

This doesn't happen to normal grouping. I guess Crystal is doing something special to  'summary across hierarchy'

 I would like to know how to use formula or function to get these values so that I could do further calculations.

Thanks in advance for your help.
Question by:nancen
  • 4
  • 3
LVL 10

Expert Comment

ID: 11825677
what kind of calculations do you want  to do. If you explain your report and what you need to accomplish, maybe I can help you .


Author Comment

ID: 11836848
Thanks Emre, my report  is like this:

              office  ID         num of shift            task scheduled      %  shift per task
                                    formula1                formula2                formula3

Here I use hierarchygroup ,  group by office_ID, parent_id is parent_office_id,  hopefully will get the look as follows:
              Corp               98

Author Comment

ID: 11836984
Sorry Emre,  please forget preious comment,  I just press the space bar, it appeared like this :(

my report  is like this:

              office  ID         num of shift            task scheduled      %  shift per task
                                    formula1                formula2                formula3

Here I use hierarchygroup ,  group by office_ID, parent_id is parent_office_id,  hopefully will get the look as follows:
              Corp               98                          100                       98%
                     Dep1        50                          50                         100%
                          off1    30                           40                         75%
                          off2    20                           10                         200%
                     Dep2        48                           50                        96%
                           off3    48                           50                        96%
Notice, an office could have possible sub_office. Database table only provide office level Data, not Department and Corporate level. These
have to be calculated.

I can get the Department level and corporate level summary for  shift and task. as following:

    office  ID         num of shift            task scheduled      %  shift per task
                          shift sum                    task    sum                    

Here sum means summary across Hierarchy.

But I got problem to calculate this field  "%  shift per task"  using a formula like:
Sum({shift}, {office_id}) % Sum({task},{office_id})

It doesn't complain, but just doesn't show up in the preview.

I know I could calculate these values in sql using sql command  "start with, connect by" kind of thing. I think that is not efficient, and can't coupe with complex situtation. Anyway, I just want to do a simple calculation which two numbers already showed up in the report.

Thanks again for your help and best regards.

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

LVL 10

Expert Comment

ID: 11840925
Do the same thing but where you inserted
Sum({shift}, {office_id}) % Sum({task},{office_id})
insert  a new section, and put this  formula there. I think crystal has a problem witht he evaluation time and cant display your formula. Your summary calculations have to be done for your formula to be evaluated.
You can also use

Evaluate after(summary) function. That will make sure that your formula gets evaluated afer the summary function takes place

Author Comment

ID: 11848750
Thanks a lot ebolek.  

I have tried the solution you proposed, unforunately both are not work.

I think the main problem is how to  use a formula to do summary across hierarchy. Simple illustration is how do I say:
Evaluate after(summary across hierarchy)  ?

If I just put Sum({shift}, {office_id}) in the report, it will not show up. Although this is generated by "Insert--> Summary", then choose
field to summary, as well as the group. Then I  tick the 'summary across hierarchy' box.

Note, If I not using formula, it will show the summary across hierarchy correctly if I tick the  'summary across hierarchy' box'. However,
if I don't tick the magic box, it will also not show up.

That's why I assume crystal doing special thing with 'summary across hierarchy'. Because there is no difference in terms of formula. But
the result is different.

I probably have to use function. That is write a special summary function. However, I even don't have a single clue to write a function to
do same thing as crystal  summary function does, for I don't know which construct holds database values, as well as group information,

Thanks and Best Regards.

LVL 10

Expert Comment

ID: 11850960
where are you going to write that function

Author Comment

ID: 11858107
Hi ebolek,

I couldn't remember exactly where, for I didn't have crystal at home. But I am sure
you can add a user defined function in the Crystal Report, and I did tried once. Once the function is written, I could then use the function in the formula.

I already got an idea to solve the problem. Unfortunately I couldn't test it out now,  Basically it will be like this:

NumberVar sum;
IF OnFirstRecord then
    sum :=0
ELSE IF Previous({Office_type}) = {Office_type} then
    sum := sum + {shift}

I have to initialize  sum in the report header. I also have to add a column in the
table to specify office type.

Thanks  again for all the help.


Accepted Solution

Computer101 earned 0 total points
ID: 12108402
PAQed, with points refunded (100)

E-E Admin

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group Header Repeating on every page 4 45
New and Previous Value in Crystal Report 8 59
Business Object Server 2 29
Selection between two dates and time range. 21 31
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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