Link to home
Start Free TrialLog in
Avatar of NDSgroup
NDSgroup

asked on

Do math between a report and subreport

Can I do math on values in a report added to values in a subreport?

Heres an example of what I have now:

                                          (sub Rpt column)

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)
Jeff Smith,        250.00,           (10.00)
Jane Doe,         500.00             (       )

Totals              850.00                              <<main report footer

How can i put the (demo) total at the bottom of the main report, and add commissions to (Demo) and display as a column.

E.G.
                                         (sub Rpt column)

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00

Totals              850.00              30.00      880.00

Any help would be greatly appreciated, thanks.

Avatar of SimonLarsen
SimonLarsen

putting a field in the footer with Sum([Demo]) doesn't work?

If you look at the properties of the existing sum of commissions and modify it accordingly you ought to be fine.
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If what they have suggested doesn't work, consider reworking your report layout. If there is basically a 1-to-1 relationship between the two recordsets (i.e. if for each client record there is only one demo record), then you should be able to create a single query which contains all of the data that you need. Then you can redo your report so that there are no sub-reports to complicate matters.

If there are more than one demo record per client record, you can still probably set things up in this way, but it gets a little more tricky. You would have to design a query which first sums up the Demo values for each client, then create a second query which combines the rest of the fields with the summed Demo data.  Queries like these are not my forte (yet), however, I have designed many reports with subreports and so on, and am slowly discovering that report design is a whole lot easier if you can possibly set up the queries to provide you with a single recordset.

 
> report design is a whole lot easier if you can possibly set up the queries to provide you with a single recordset
Very true.

This works with nested information. For example (pseudo report-printing code)

for each order
   print order header
   for each order detail
      print row
   next
next

or

for each department
   for each month
      for each salesperson
         for each sale
            print row
         next
      next
   next
next

But if you have more than one internal loow, you will need subqueries, as in:

for each employee
   print employee sheet
   for each employee property
      print property
   next
   for each job change
      print job title
   next
   for each year
      print salary overview
   next
next

The question here is rather: does the subform's report footer information really need to be printed on the main report? It seems more logical and it is easier to place total fields in the same report as the data...

Cheers :)
Avatar of NDSgroup

ASKER

the reason I need to do it the way i described is as follows:


SalesReps make sales, and earn a commission on the sale.

Canvassers make demos, and earn a dollar amount if the demo becomes a sale for the SalesRep.

marketing managers can make demos, and they get a commission on any sale that he or his canvassers make a demo for.

so the marketing manager can make a commission and a demo amount if he makes the demo that becomes a sale, otherwise he just makes a commission if one of his canvassers made the demo.

the problem is that my design dosent allow for a query that will show the marketing manager, the canvasser, weather or not the marketing manager gets a demo amount, how much the sale was for, and any commissions made all on the same one.

what i did was make a report that shows all the marketing mamagers commissions on sales that he or his canvassers demoed, and then made subreports that show the demo amounts the marketing manager should get(demos(appointments) are connected to clients, not sales).  Then i placed the subreport in the detail of the main report. Then i used a text box and some code to add the demo amount to the commission amount to get a total commission on the sale using
 =[ComContract]+IIf(IsError([Demos].Report!Demo),"0",[Demos].Report!Demo)
I used the IIf(IsError part because the marketing manager wont get a demo on every client that he gets sale commissions on, so sometimes that "row" on the report wont contain anything in the subreport and the math woulld generate an #Error on the report, now if there is no info it places a 0 there instead so I can add it.

then i was able to use a copy of the above text box and make it not visible and make it keep a running sum so that i can place an =Sum in the main report footer to get a grand total.

it's a convoluted process, but it gets the job done, and the client wants the layout to be very clean:

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00

Totals              850.00              30.00      880.00

NOT

Client,             Commissions,   (Demo)

Frank Stevens,  100.00 ,          (20.00)     120.00
Jeff Smith,        250.00,           (10.00)     260.00
Jane Doe          500.00            (        )     500.00
                                               30.00
Totals              850.00                            880.00

the latter of the two examples is what would happen if i placed the demo total in the footer of the subreport and was just not acceptable.

So thanks for the input, I always learn something new every time I come here.

I think i have to give it to harfang because
 "Not really, but the main report has access to all controls of the subform, containing the last usage of each section."
was what sent me on the path to figuring out the math i needed.

Well, glad you could make it work.

As for your very  last example of layout, it just seems strange not to put *all* totals in the subreports footer. They could all be computed there, at least it looks that way. This would also work if the columns were actually in different subreports, all having the same number of rows...

Anyway, good luck!