Question

I am trying to create a chart (bar or line) in crystal from one table in my database (Sage CRM).

The records are as follows

CustomerId      Date            Invoice              Amount

1234           3/4/2013        Cust Invoice           3322.00   
1234           3/4/2013        Payment                2445.00  
1234           4/5/2013        A/c transaction         322.00  
1234           5/6/2013        interest                 32.00 
1234           6/6/2013        payment                 643.00 

So I would like to have a report that meets the following criteria

  1. Only records for the last 12 months grouped in month
  2. Only invoice types of payment, invoice and interest
  3. A moving balance that calculates all the invoice amounts ie

(when displaying the information for July 2012, the moving balance will be the total of all invoices prior to this date. Without this field I can create the chart no problem using select expert but I am not sure now what to do)

Should I use a cross tab? if so how will I do the selection to only show the invoices I want and the the date range I want?

Was it helpful?

Solution

After spending almost a week on this problem, with a lot of help from an expert I have finally got a solution.

In order to create a amount that is the sum of all records for a company, month and invoice type since the beginning of time, while only displaying records for the last year, I have created a SQL command

Select 
  //All of the fields for the report,
  movingBalance.Amount
from myInvoiceTable as mit
  <join to any other tables for the report>
  left join (
    select customerID, sum(amount) as Amount
    from myInvoiceTable
    where Record_Type in ('Payment', 'Invoice','Interest')
      and Date < {?Report Start Date}
    group by customerID) movingBalance
   on mit.customerID = movingBalance.customerID
where mit.RecordType in ('Payment', 'Invoice','Interest')
  and mit.Date >= {?Report Start Date}
  and mit.Date <= {?Report End Date}

There are a couple of tricks to using commands:

  1. For performance reasons you generally want to include ALL of the data for the report in a single command. Avoid joining multiple commands or joining one or more tables to a command.
  2. Filter the data in the command, NOT in the Select Expert in the report.
  3. Create any parameters in the Command Editor, not in the main report. Parameters created in the report won't work in the Command Editor.

This has done the trick.

OTHER TIPS

Create Date Parameters in the report to filter out the records at the time of fetching now when you run the report you have left with the data you need.

Now you can manuplate the data inside report using formula fields.

Accoding to me writing stored procedures is a bit hectic task as you can manuplate the data inside the report. I don't have any intentions to disrespect anyone opinions but frankly its my opinion.

In that case Rachsherry I would recommend the following.

For criteria parts 1 & 2 I think instead of using stored procs, it may be easier for you to use a formula.

For invoices right click the invoice field, then "Format Field" in the common tab next to the Suppress option there is a formula button, enter the following...

 IF {YourInvoiceField} IN ["Payment", "Invoice", "Interest] THEN FALSE ELSE TRUE

For your date requirement you need to use a selection formula... The code for that should look something like this

 {YourDateHere} > DateAdd ("yyyy", -1, CurrentDate) AND {YourDateHere} < CurrentDate

The above code basically looks at dates between the day the report is run, and exactly a year before.

For your moving balance, you should be able to achive that with the guide here

Edit - An alternative to this is to use parameter fields (Which I don't personally like) it just means having to input the parameters every time the report is refreshed, they are self explanatory but you can find a guide here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top