Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Sum a shared variable Post Reply Post New Topic
Page  of 2 Next >>
Author Message
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Topic: Sum a shared variable
    Posted: 24 Apr 2014 at 5:28am
hi folks

I'm writing a report where Im listing all jobs completed within a certain time frame, and calculating profit by evaluating costs v invoiced values. (sounds simple)

I have to use a subreport to get a value of what is invoiced (long story, I can explain if helpful)I'm then taking that value and passing it into the main report by use of shared variables.

In my main report now I have values for actual costs, invoiced values and a few others I'm intersted in, all listed by job. The idea then is that I can group and total the jobs by our sales person or by each customer so that I can evaluate profitability in each grouping.

When I try to sum the variable that I'm pulling through from the subreport I get a message saying that this field cannot be totaled. I've googled but found two or three suggestions to resolve problems that didnt look quiet the same as mine.

Is there some way to total this variable?


My report looks something like this
Job P&L Report

Group1 header - by sales person
Group2 header- by Customer
Group3 header- by job > group3 header has subreport calculating total invoiced by job
Details - lists all invoices by job
Group3 footer has all of my job details, part num, est costs , act costs, Variable calling in the value from the subreport in the header section.
Group 2 footer - totals by customer
Group 1 footer - totals by salesperson.


Any suggestions welcome !

thanks
IP IP Logged
otto
Groupie
Groupie


Joined: 17 Mar 2014
Online Status: Offline
Posts: 53
Quote otto Replybullet Posted: 24 Apr 2014 at 8:14am
did you try using running totals? the other way is creating others variables to summarize your subreport variable per group.

example shared numbervar sample := sample + you variable.
you should have to create one per group if you desire a total for each one and place them in the same section that your subreport variable is on your report.
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 24 Apr 2014 at 10:56pm
hi
thanks for your help

I tried using a running total but the forumale field calling in that variable does not appear as fields available for summarising. its just not there.

I tried creating another variable then along the lines you suggested.

shared currencyvar CustGrpInvTotVar:= CustGrpInvTotVar + {@TotalInvVar}

TotalInvVar is the forulmae field being used to call in the variable from the subreport.

The above code just adds the value of the last invoiced job was, it doesnt seem to be totalling all of them.

GH Customer X
job1 invoiced amnt 100
job2 invoiced amnt 120
job2 invoiced amnt 130
GF total invoiced this customer 350

GH Customer Y
job4 invoiced amnt 200
job5 invoiced amnt 220
job6 invoiced amnt 230
GF total invoiced this customer 580

the total invoied for customer y is returned as the invoice total for job 6 plus total amount for customer X

obviously theres something wrong with my syntax. As a newbie I just dont know enough anuout it to know what the problem is.

Edited by marco007 - 25 Apr 2014 at 1:33am
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 27 Apr 2014 at 2:51am
Hi
 
Create following formulas and place it in appropirate sections :
 
Whileprintingrecords;  // place this formula in Group header 2
Numbervar Cust:=0;
 
 
Whileprintingrecords; // place this formula in Group footer 3
Numbervar Cust:=Cust+ {@TotalInvVar};
 
 
Whileprintingrecords; // place this formula in Group footer 2
Numbervar Cust;
 
Now you will see totals for your Customer, follow the same procedure to print totals for salesperson.
 
-Sastry


Edited by Sastry - 27 Apr 2014 at 2:52am
Thanks,
Sastry
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 28 Apr 2014 at 4:28am
fantastic!
that works a treat.

(the only think I had to change was my variables were currencyvar rather than numbervar)

thanks for the help
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 30 Apr 2014 at 2:10am
hi

rather than opening a new thread I though I might ask here as its slightly related.

Is there any way to sort a report by one of my variables i.e. if I used one of my variables to calculate gross profit, how can I sort the report then to list the top ten most profitable jobs?

edit
When reporting the top ten most profitable jobs in a given period, I dont want to group by sales person or customer so I removed all my groupings and just have my subreport in the details section. The output looks fine, its reporting how much is invoiced against each job. I just need to order this in such a way that it sorts by the most profitable up top.



thanks
marc


Edited by marco007 - 30 Apr 2014 at 5:26am
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 30 Apr 2014 at 7:21pm
Hi
Do you have any other data available in main report ?  If so, what kind of data is available ?  How you are linking your sub report to main report.
 
If possible give a sample report output here.
 
-Sastry
Thanks,
Sastry
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 01 May 2014 at 4:30am
I'm back to the drawing board on this I think (as you probably suspected) The calculated invoiced amount is not right. I think it needs to be grouped by job at least to get the variables to fire in the right order.

If I group by job however it applies a sort at that point though does it not, so I probably cannot sort by my variable after that then..?

I'll outline this a little clearer after the weekend when I have some time.
thanks for your help so far
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 01 May 2014 at 4:43am
as you found out, you cannot group or sort by variables...the calculation is too late to be used for sorting.

CR makes several passes through the data before it starts printing. Sorting is done on one of these passes, so if you use a formula for sorting or grouping, the data has to be something intrinsic in the datarow...so say that the you wanted gross sales, I think (and I have been wrong before) that you might be able to sort/group on a formula like sum({table.field}, {groupTable.field}). If you have conditionals in the formula that would exclude some values, then you cannot group on the formula...for the reasons above.

If you were using a stored proc, one way around this would be to put the results of your calculations in a column of the data, CR is very happy to sort or group by this value.

HTH
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 26 May 2014 at 9:31pm
hi folks

still at this one

lockwelle - thanks for your reply. I gave up on sorting the report by the variable values. It would be nice to be able to do it but not critical for me in this instance so I didnt persevere.

I do have another problem to solve which Im hoping you folks may be able to help me with. My report works fine now but I'm being asked to nest this whole report as a subreport in a larger monthly end report that I have built. The idea is that management just want to see the bottom line on this profitability report i.e. just the totals.

I can do this by hiding each of the group headers and group footers below except for group 1 footer which has the salesperson totals which I am interested in.

Group1 header - by sales person
Group2 header- by Customer
Group3 header- by job > group3 header has subreport calculating total invoiced by job
Details - lists all invoices by job
Group3 footer has all of my job details, part num, est costs , act costs, Variable calling in the value from the subreport in the header section.
Group 2 footer - totals by customer
Group 1 footer - totals by salesperson.

THe problem I'm finding is, when I hide the output of group3 header, my total invoiced value is not calculated correctly (just outputs 0) this seems to be because my subreport for totalling what is invoiced is placed in the group 3 header.

The subreport does not seem to run if I hide or suppress this section. I tried to work around this by making it very small and colouring the font white but this is not ideal because I need to summarise this report down to one line and if this group header is visibile it has the same efffect as adding blank lines into the report.

Is this normal behavior that once the header is hidden that it would result in the subreport not running at all? I would have thought that the hide attribute would just affect the visibility of the section, that it should not stop it from running?

Is there some other trick I can use to hide this section?

thanks
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.030 seconds.