Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Tricky sum
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Title:
Miscellaneous
Thread ID:
00220928
Message ID:
00221192
Views:
14
>I can't figure out how to do this in report designer, or even if it's possible.
>
>Each of the line items in an invoice has a sales code attached to it. I need to take the first 5 sales codes and print them at the bottom along with the sum of the cost of the items with that sales code.
>
>Because of the screwy way SBT does reports, I need to do this in the report designer itself, rather than just doing a select into an array in the calling program like I had planned.
>
>I figured I'd have to use report variables somehow, but I don't know how. I won't know which codes will be summed, or their sums ahead of time. The records aren't and can't be grouped by sales code, so there may be an item of one sc, then one of another, then another of the first sc. I need to somehow pick out the first 5 sc's used, and add up the values, then print them at the bottom.
>
>Any ideas?
>
>Thanks,
>
>Michelle

Hi Michelle,

Although its been a while, I've done some extremely complex changes to some of the SBT reports for previous clients. Although others are talking of putting a UDF() in the report header, I actually put a hook in the printing mechanism of SBTs "SBTPROC.PRG". Immediately before it is ready to actually print the report, I would call the UDF(), then based on which gcReportForm (or whatever it's called), and knowledge of the tables in use, I would apply any extras.

As far printing invoices, I believe that it is a cursor that is used for the report, not the entire table... Even if you print invoice 100-120, it will cycle through an outer loop for each invoice and extract details, then print.

Do you want specifically the first 5 codes, or the top 5 most $$$ codes.

A SQL that could get the first 5 codes

select acntcode, sum( sales ), min( recno()) as lowestcode;
from InvoiceCursor;
group by acntcode;
order by lowestcode;
into array laInvTotals

This way, the min recno() per account will be used as the order and push only these to the top, then in the report footer/summary band, you would be able to reference laInvTotals(1,1) and laInvTotals(1,2) provided the type( "laInvTotals(1,1)" ) = "C" (I believe the code is char for what you are referencing).

If you need just the top 5
select acntcode, sum( sales ) as totsales
from InvoiceCursor
group by acntcode
order by totsales
into array laInvTotals

HTH, and I will see if I can find where I put my global report hook to accommodate other report customization on the fly...
Previous
Reply
Map
View

Click here to load this message in the networking platform