Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Get Formula with sum for group below current group Post Reply Post New Topic
Author Message
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Topic: Get Formula with sum for group below current group
     Posted: 12 Aug 2015 at 3:03am
I have a report with several levels of groups:

1) ScopeOfWork
2) CostType (There could be several cost types per Scope of work)

I have a formula in the Cost Type group that will Sum the cost for the Cost Type and if there are multiple Cost Types you will see this value for each repeated cost type group. Here is the formula at the Cost Type group:

Sum ({vrptJCUnitCostCT;1.ActualUnitsDetail}, {vrptJCUnitCostCT;1.CostType})

I can also conditional color the value in the Cost Type Group Footer based on this value.

What I need however is to conditional color a value up in the ScopeOfWork Header if ANY of the values in the CostType group has a specific condition based on the above formula.

So if I have the following:

- ScopeOfWork Header (Some Text Colored IF any of the conditions are true below in CostType Footers)
- CostType 1 Footer (Summed Value: False condition)
- CostType 2 Footer (Summed Value: True condition)
- CostType 3 Footer (Summed Value: False condition)

I have tried simply accessing the formula from the ScopeOfWork Header, but the value it is seeing must be from the last CostType from previous ScopeOfWork grouping as the report hasn't gotten to it yet.

So how can I check a condition on those values in the CostType groups contained in the current ScopeOfWork group.

Thanks
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Aug 2015 at 4:30am
if I understand you correctly you should be able to use shared variables that evaluate at each child group footer and set your result. Once you hit a 'positive result' you would stop changing the value and run it all the way to the last group inside the group. Use the result to alter the display in the parent group footer. then reset the value on the start of the next parent group (gh).
IP IP Logged
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Posted: 12 Aug 2015 at 4:54am
Originally posted by DBlank

if I understand you correctly you should be able to use shared variables that evaluate at each child group footer and set your result. Once you hit a 'positive result' you would stop changing the value and run it all the way to the last group inside the group. Use the result to alter the display in the parent group footer. then reset the value on the start of the next parent group (gh).

I haven't had to use shared variables in the past. I'll take a quick look at help on that subject and give it a go.

Thanks for the reply. I'll post back the results.
IP IP Logged
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Posted: 12 Aug 2015 at 5:50am
I must be doing something wrong.

At the ScopeOfWork Group Header I place formula KPI_Fail_Reset:
whileprintingrecords;
Shared NumberVar KPI_Fail_Num;
KPI_Fail_Num = 0;

At the CostType Group Footer I put a formula with this:
whileprintingrecords;
Shared NumberVar KPI_Fail_Num;
if {@UC_JTD_CostType} > {@UC_CurrEst_CostType} then
    KPI_Fail_Num = 1;

For diagnostics purposes I altered the above to display the KPI_Fail_Num at the CostType Footer and it was 0. But if I changed the formula to simply do the calculation and display a 1 if the condition exists I get 1:
whileprintingrecords;
if {@UC_JTD_CostType} > {@UC_CurrEst_CostType} then
   1
else
   0

So at the CostType Group Footer level the formula (not using shared variable and just doing the if then 1 else 0 it displays a 1 where I would expect. But if I use the first formula using the shared variable and setting it to 1 if the condition hits will not display a 1.

I guess I am also wondering how this will work since I am trying to get the value at the ScopeOfWork group header when the shared value is not even set until each CostType group footer is processed.
IP IP Logged
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Posted: 12 Aug 2015 at 9:16am
Let me restate my issue as I am not sure I stated it clearly:

We have multiple levels of groups:

1) ScopeOfWork
2) CostType

Date could look like this:

-------------------------------------------------------------------
| ScopeOfWork A GH1 | Description             (FLAG AN ISSUE)     |
-------------------------------------------------------------------
-------------------------------------------------------------------
|    CostTYpe 1 GH2 | Description | Quantity | Cost | Unit Cost |
-------------------------------------------------------------------
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------
|    CostTYpe 1 GF2 |   Totals:   |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------

-------------------------------------------------------------------
|    CostTYpe 2 GH2 | Description | Quantity | Cost | Unit Cost |
-------------------------------------------------------------------
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------
|    CostTYpe 2 GF2 |   Totals:   |   nnn.nn | nnn.nn | nnn.nn* |
-------------------------------------------------------------------

-------------------------------------------------------------------
|    CostTYpe 3 GH2 | Description | Quantity | Cost | Unit Cost |
-------------------------------------------------------------------
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
|         Details     |             |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------
|    CostTYpe 3 GF2 |   Totals:   |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------

-------------------------------------------------------------------
| ScopeOfWork A GF1 |   Totals:   |   nnn.nn | nnn.nn | nnn.nn   |
-------------------------------------------------------------------

The Unit Cost values above are calculated at each Group Footer level for the level it is at using (Sum of Cost / Sum of Quantity)
In the above at the CostType GF2 (Group Footer 2) level I compare Actual Unit Cost against Budgeted Unit Cost and I can flag the Unit Cost in the GF2 Totals secion RED if there is an issue.

BUT... I need to know at the ScopeOfWork GH1 (Group Header 1) level that any one of the Cost Types has an issue.

So if CostType 2 has an issue I would highlight the calculated Unit Cost at the GF2 level of Cost Type 2 and I would also want to flag this at the ScopeOfWork (GH1) level.

Not only for coloring, but we will want this report to have a paramter called "Show ONLY Errors (Y/N)" and if the flag is "Y" then only the phases with an issue will display (along with all of it's cost types). Hence the reason for needing to know of an issue at the Cost Type level of the current ScopeOfWork.

Just in case this wasn't clear initially hopefully it is better described.

So the question is how to know at the GH1 group that any one of the GF2 group of the current GH1 group has an issue?

What I am not certain about is what has to be used to have visibility into the lower groups. I tried the Shared variable and either I am doing it wrong or that is not the solution. Everything I have read about shared variables seem to relate to sub reports and this isn't a sub report.

Thanks again!

Edited by gsaunders - 12 Aug 2015 at 9:52am
IP IP Logged
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Posted: 12 Aug 2015 at 10:29am
Oh... and I caught where I was using = where I should have been using := when doing assignment to variable. Just typo in posts above.
IP IP Logged
gsaunders
Newbie
Newbie


Joined: 09 Apr 2012
Online Status: Offline
Posts: 20
Quote gsaunders Replybullet Posted: 13 Aug 2015 at 8:45am
What I ended up doing is completely enhancing my query so all of the KPI's at the CostType level come in as either 1 or 0 and then I can use the simple Sum function and check to see if it is greater than 0 at the ScopeOfWork level and this does what I want.

Part of the issue is how calculations had to be done on certain KPI's within Crystal. You couldn't simply sum those up due to how Unit Cost had to be calculated and where it had to get quantity from.

So in the end it simply couldn't be done without either converting to sub reports for the Cost Type or altering the stored procedure to handle it all... which is what I did.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum