Group by date and calculate - crystal-reports

For each account I need to subtract the earliest amount from the most recent amount.
Input
- ACCOUNT DATE AMOUNT
- 123 7/18/2017 500
- 456 7/18/2017 450
- 123 7/17/2017 300
- 456 7/17/2017 200
Desired output:
- 123 7/17/2017 7/18/2017 200
- 456 7/17/2017 7/18/2017 250
I've tried grouping by max and min dates, but it wasn't helpful. And I don't have much flexibility in regards to the sort of the input. How can I arrange the data properly?

Here's how I would do it:
Group by Account in ascending order.
Inside that group, Group by Date in ascending order.
Suppress all Group Headers/Footers and Details Section except for Account Group's Footer. This is where you will place all the fields you want to display.
Use 2 Shared Variables, FirstDate and FirstAmount. Set these up to store the first Date and Amount values that appear in each Account Group. (Use a Running Total that resets when this group changes. When it equals 1, fill the variables.)
In Account's Group Footer, make two formula fields:
Displays FirstDate & " " & Date
Displays Amount - FirstAmount

Related

Crystal Reports SUM formula help. Don't SUM values with specific IDs

I have a table with rows of Invoice data and I want to SUM the values of all line items where the Item ID is not equal to 0000 or 9999.
The Item IDs I want to exlcude 0000 and 9999 never change.
ITEM ID
NAME
WORK VALUE
TOTAL COMPLETED
0000
HOLD 1
0.00
1,234
1234
MATERIAL A
333.00
76.00
1235
MATERIAL B
567.00
7043.00
1236
MATERIAL C
981.00
321.00
1237
MATERIAL 4
430.00
5445.00
1238
MATERIAL 5
10.00
897.00
1239
MATERIAL 6
18.00
654.00
1240
MATERIAL 7
882.00
3.00
1241
MATERIAL 8
777.00
65.00
9999
ZY HOLD
0.00
111.00
So the value returned in the report from the example above should = 18,502.00 not 20,847.00
I have tried:
IF NOT((TONUMBER({Invoices.InvoiceItems~ItemNumber}) = 9999))
THEN
(SUM({Invoices.InvoiceItems~InvoiceValue})+SUM({Invoices.InvoiceItems~TotalCompleted}
but this doesn't work, it still sums the value from the 9999 line item
I would create a Running Total Field to accomplish this.
A Running Total Field works very similar to the Summary Field, but allows a lot more control over which records are evaluated when summarizing the data. To setup a Running Total Field for your needs try the following steps.
Create a new Running Total Field.
Set the "Field to summarize" to use the Total Completed column from your database. Set the "Type of summary" to SUM.
Set the radio button in the "Evaluate" section to "Use a formula", then click the X-2 button to create the formula that will determine if a row of data should be included in the sum or not. Whatever formula you enter here will need to return a boolean value. When this value is TRUE, the row's data is included, and when it's FALSE the row's data will be excluded. I would use the following formula here: TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999 AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0000
The last thing to do is the setup the Reset conditions for the Running Total Field. This would be used if you were grouping data in some fashion such as by Customer and would allow you to sum the data for a single customer, then reset to zero for the next customer. If you are not using any grouping you can probably just leave this set to "Never".
Click OK to finish. :)
At this point all you need to do is drop the Running Total Field you just created into your report. Be mindful about which sections you place this field within though. If you place it in a header section, you will likely find it doesn't add in the last record in your dataset because the report hasn't printed it to the details section yet. I recommend placing Running Total Fields in Footer sections to avoid this nuance.
I hope this helps! And if you do have some grouping levels that you need help with setting the reset conditions just let me know what the grouping levels are for your report and I can update this answer for you.
You can create a new formula similar to yours:
IF TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999
AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0
THEN {Invoices.InvoiceItems~TOTALCOMPLETED}
ELSE 0
and then just sum this formula field up.

Distinct count not giving expected result

I have fields for customer names, customer account numbers, date of previous orders, and order values. I want an alert to show which customers have ordered at least three times over the reporting period. We can have more than one invoice for a given delivery. The main report looks like:
Account Number Acct Name Order Date Order Total
1001 Fred Smith 1/2/2016 £1.06
1001 Fred Smith 1/2/2016 £2.34
1001 Fred Smith 8/2/2016 £5.42
2001 Aled Jones 1/2/2016 £2.90
2001 Aled Jones 8/2/2016 £3.45
I've tried concatenating the account number and order date in a column via function and running an alert based on its distinct count. (After converting the date to a string.) But it still doesn't generate a list of distinct items.
What I currently have in the final column is a function that concatenates the date and account number to give a unique field with {ORDR.CardCode} + Cstr({ORDR.DocDate}) - Which returns:
1001 1/2/2016
1001 1/2/2016
1001 8/2/2016
2001 1/2/2016
2001 8/2/2016
I want to generate alert based on this field via the distinct count function and a report of any customer who ordered at least twice in the report period.
DistinctCount ({#Concat code and date}) >2
Even after this I still don't get what I need. How can I get a list of every customer who has ordered in the report period for at least two times?
You have travelled half way... to achive continue from here.
USe the created formula {ORDR.CardCode} + Cstr({ORDR.DocDate}) to create a group.
place same formula in details and take count of the records in group footer
Now create a alert on group footer summation to get the desired result
Edit........
Since you need customer then add customer in concat fornula and then create group.
acctnamr+{ORDR.CardCode} + Cstr({ORDR.DocDate})
Now place the customer name in group header and follow process as explained above

Crystal Reports Dynamically Grouping by Date

I'm relatively new to Crystal Reports and it seems like this should be easy, but I haven't been able to figure it out after a lot of googling. I'm working on a report in Crystal Reports XI that will show total hours logged by support staff for a date range and show sub totals by week, month, or both depending on the user input. My report is currently arranged as follows:
Group 1 Header - Support Staff Member
Group 2 Header - Ticket Closed Date with section printed monthly
Group 3 Header - Ticket Closed Date with section printed weekly
Group 4 Header - Ticket Category
Group 4 Footer - Sum of time logged in each category for the week
Group 3 Footer - Sum of time logged in all categories for the week
Group 2 Footer - Sum of time logged in all categories for the month
Group 1 Footer - Sum of all time logged
My original idea was just to suppress the header and footer for groups 2 and 3 when they weren't needed, but if I manually do that it still prints the records by week and month. Is there a way to not have the grouping at all unless the parameter says to show those totals? Or if that isn't an option, how would I use the parameter to change whether the group prints records weekly or monthly?
Thank you
Best option would be create a string parameter 'option' with values weekly and monthly.
Now create a formula grouping.
If ?parameter='weekly'
Then //your weekly code here
Else if ?parameter='monthly'
Then //your monthly code
Now use this formula in grouping instead of multiple groups.
Now when user selects option your grouping will change dynamically.
Hope this helps

Crystal reports - how to handle null while using group

I would like to know which is the best way to include null values in the report while using the below groups. My below report uses two groups one below other, Month group is under the field group. I have given the formula for the Field Group A; and for for the month I have used options to fetch the months from the specific date field [source is excel file] in ascending order. Since there are no data for group A - 1 records for October month I don't see any data whereas I would want to show the month with NA as result.
Report looks like below currently
Field GROUP -A - 1
Month Result
11-2012 xxx
12-2012 xxx
Field Group A- 0
Month Result
10-2012 xxx
11-2012 XXX
12-2012 xxx
But I would like the report to be as below:
Field GROUP -A - 1
Month Result
10-2012 NA
11-2012 xxx
12-2012 xxx
Field Group A- 0
Month Result
10-2012 xxx
11-2012 XXX
12-2012 xxx
Any suggestions will be helpful
Crystal Reports can't show the data, because there isn't any data to show.
There's only one instance I'm aware of where Crystal Reports will auto-fill NULL data, and that's when using a crosstab, which really doesn't appear to fit your needs or desired output.
You'll have to supply the "N/A" value for 10-2012, Group 1 in your query, possibly by using some table of dates to outer join against.

Crystal Reports - Formula to count groups/How to create an average based on sums

I am working on a report that shows Part Numbers with multiple Purchase Order numbers, Order Quantity and Shipped Quantity. First I grouped Part Numbers.
Part # 21104-2F PO # S7CEO Order Qty: 10 Shipped Qty: 0
PO # S7CEO Order Qty: 10 Shipped Qty: 0
PO # S8LVU Order Qty: 5 Shipped Qty: 0
Sometimes we split jobs within a purchase order. For example: (look above at PO # S7CEO) you order 20 of part # 21004-2F. We separate it into two lines (or jobs) of 10 parts per job. In this report I only want to see that you ordered 20. To achieve this, I created a second group for Purchase Order numbers and inserted a sum so that way I only see that you order 20 parts.
Part # 21104-2F PO # S7CEO Order Qty: 20 Shipped Qty: 0
PO # S8LVU Order Qty: 5 Shipped Qty: 0
My dilemma: I need to show an average based on how many parts you ordered (so average of the 20 parts, not the 10) but CR is giving me an average based on the 10 parts.
How do I create an average based on sums?
I tried using a formula to calculate the sum then divide by line count. There are 3 “lines” but once I grouped and inserted a summary, there are 2 different purchase orders. The line count formula is counting "3" lines. I want it to count how many groups I have so it will come up with "2". Then I will be able to divide "groupcount" (2) by total order qty and that will give me an average. Is there a formula that will help me achieve this?
Thank you in advance!
Yup, Count counts all the records. Use DistinctCount, which counts the values instead:
Sum({OrderQty})/DistinctCount({PO})
That should give you 2 instead of 3 in the denominator.
As long as you're outputting the data into the group footer, you can use a SUM(shipped quantity)/COUNT(PO #) to get the average parts/shipment.
e.g.
Two level grouping on Part # (group #1) and PO # (group #2). You'd output the actual data in the Group Footer #2 field. To do your average, you'd add two summary values in that footer: SUM(shipped quantity) and COUNT(PO #). Then a simple formula field to do SUM/COUNT of those two values, and you've got your average parts per shipment value.