Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Formula for Summary Across Hierarchy

Posted on 2004-08-16
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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