Daily average of count grouped by month - crystal-reports

I am trying to figure out the best way to display the daily average of a count by month.
Here is what the data looks like
Date(date),Location(string),UnitID(string)
2011-12-1,A,123
2011-12-1,A,456
2011-12-1,B,789
2011-12-1,B,246
2011-12-2,A,135
2011-12-2,A,123
2011-12-2,B,789
2011-12-2,B,468
...
We would like a report showing the following:
(location) 12/2011 1/2012 2/2012 (by month)
A 12.5 10.3 14.0
B 22.1 20.9 25.6
The summary fields should be calculated following this general idea for each month/location combination:
Avg(Count(UnitID))/(days in month) *see below for clarification, this formula doesn't really make much sense.
The Avg(Count(UnitID)) is the tough part. A cross tab would work best, but anything at this point will work.
Any help is greatly appreciated.
Edit for clarity: The data is a listing of all units that had a failure. Several Units per day fail, spread out over several locations. In English what I want is the average daily number of failures of units per month, grouped by location.

I recommend doing this in a crosstab.
First, add a formula (called something like perMonthCount) like the following to the report:
1 / DatePart ("d",
DateAdd ("d",
-1,
DateAdd ("m",
1,
DateAdd ("d",
1-DatePart ("d", {failures.fail_date}),
{failures.fail_date}) ) ) )
Next, select Insert > Cross-Tab... from the menu and specify the following values in the Cross-Tab tab of the Cross-Tab Expert dailog:
Rows: your location field
Columns: your failure date field (use the Group Options button to specify that the column should be printed for each month, instead of the default for each day.)
Summarized Fields: the #perMonthCount formula field (the summary operation should default to Sum of.)
In the Customize Style tab of the Cross-Tab Expert dailog, check the Suppress Row Grand Totals tick-box. (You may also want to check the Suppress Column Grand Totals tick-box, if you don't want to see totals for all locations at the end of the report.)
Click on OK at the bottom of the Cross-Tab expert dialog and drop the Cross-Tab into the report footer.
You will also probably want to suppress the details section of your report.
At this stage, you should now be able to preview your results.

Related

Filtering a Cross Tab by a Date Range in Crystal Reporting

I've got a cross tab that sums the number of records for each month across my data set, however I don't want all of the data set. I only want the cross tab to sum the data for each of the months for records that are related to the dates between 01/01/2022 to 31/12/2022.
Normally I would set a filter on the report to say this, but I am adding another section to the report which would not work if I had that filter set. I only want the filter to apply to the actual cross tab information.
Thanks in advance!

Crystal Reports formula based on group footer summary field

New to Crystal Reports -
I have a report with 3 columns - Estimated Hours, Actual Hours, Remaining Hours.
In the Group Footer it summarizes the hours by job. The remaining hours formula is {job.esthours}-{job.actualhours}. I want it to be blank if there is no estimated hours. I know that I can't use the sum of estimated hours in my formula but not sure what formulas to use.
Sample Report
You need to add a condition to suppress your formula in case the first cfield value is null. You can do it in two ways:
1) Add the condition in your Remaining Hours formula. Try this if you want blank also in your detail sections. Right-Click -> Suppress -> add there the next condition:
if(isnull({job.esthours}))
2) Add the condition in your Remaining Hours Summary. This is better if you wish to show negative values of Remaining Values in your Details Section for some reason. Right-Click -> Suppress -> add there the next condition:
if(isnull(sum({job.esthours})))
And yes, you can use the estimated hours summary, , you can find it in your Formula workshop, in the Report Fields tree

Create a chart using the records of certain type grouped by month, with a moving balance

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
Only records for the last 12 months grouped in month
Only invoice types of payment, invoice and interest
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?
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:
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.
Filter the data in the command, NOT in the Select Expert in the report.
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.
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

Crystal Reports, and running totals

I am designing a report in which a Running Balance column adds itself to Debit and subtracts the answer from Credit column on every row. Here in this example I have started calculating from 1st of January. In this case, my Running Balance column will have zero.
Now my client wants to have a look at records from 17 January to the end. In that case, my cumulative balance will NOT be zero at first but instead it will calculate cumulative balance for all the dates before 17 January, and present it as the starting balance for 17th of January. I am stuck at this point. How to add all the record before 17th of January and show their Total in a single row.
There are lots of different ways to achieve this, but here's one idea you might like to try.
Set the report selection criteria to include all records from 01/01.
Create 2 report detail sections.
In the first detail section just place the running total and maybe a label: "Starting Balance".
In the second detail section place your normal fields.
In the section expert use a formula to suppress the first detail section: {table.date} <> {?date parameter}
In the section expert use a formula to suppress the second detail section: {table.date} < {?date parameter}
Hope that helps.

Crystal Reports Xi - Sorting a CrossTab Report by a Summary Field

So I have a simple crosstab report that calculates number of sales in the columns, and the rows are each office. The last column on the right is a total column, which contains a summary field (via a count of the identity field) that adds up the total number of sales per office.
How can I sort the crosstab data so the office with the most sales is the top row, and the rest in order under it?
Try this: Right-click on the crosstab. Go into the Group Sort Expert menu. There you will see options to display the top N rows, Sort All by the aggregate of a field of your choice, etc.
(I'm using Crystal XI. If your version is different, this may not work exactly)