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

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.

Related

Displaying only the last of a sequence in Crystal Reports

I have a report that will occasionally have more than one detail record in a group. In such a case I only want to display the last in the sequence. I have a sequence number associated with each record so I need to suppress all detail rows in the group other than the one with the maximum sequence number.
I've tried using a global variable to recalculate the max value as of each detail record but I haven't been able to write a formula that, while printing, can use this maximum sequence number to suppress the row if it does not contain a value equal to the max sequence number.
From what i understand you have data organized by this:
Data1 Data2 SeQuencenumber
1 a 1
2 b 1
2 c 2
2 d 3
And from what i understand your want your output look like (group by Data1):
Data1 Data2 SeQuencenumber
1 a 1
2 d 3
To do so you need to write formula in detail section which compares your current detail sequence number and count of all for that group (Data1). Right-click your detail section and write formula here
Formula looks like :
if {SequenceNumber} = count ({SequenceNumber},{Data1}) then true
else false
Hope it helps, if you have any further questions feel free to ask.
try like this:
Shared Stringvar array concatenate;
concatenate:=concatenate+CStr(Sequencenumber);
now in suppress condition of details:
Shared Stringvar array concatenate;
if Maximum(concatenate)=Sequencenumber
Then false
else true
I had tried a solution similar to the one from KuKeC but with the maximum function instead of count. But while reviewing the KuKeC solution I finally saw that I was already suppressing the detail band when a date in the detail did not match a parameter date, yet the maximum function was giving the max of all data whether displayed or not.
So I first needed to add a formula field that would return the sequence number only if the data date matched the parameter date
if {PSLRegister.PSLRPPStartDate} = {?PP_Start_Date} then
{PSLRegister.PSLRSeqNo}
else
0
then I used this formula field in the equation to suppress the detail record
Maximum({#SeqIfDateMatch}, {TrnsltEmployee.TSEmployeeID}) <> {PSLRegister.PSLRSeqNo}
Thanks to all

how to use one formula field in another formula field in crystals report

my table as below
account_name debit_balance credit_balance
abc 100 50
pqr 80 100
xyz 150 90
I create one formula as below
Amount=(debit_balance-credit_balance)
now i want sum of all amount that is
Sum(#amount)
I try As below
Sum(debit_balance-credit_balance) but it not work
I find solution on net but not get
Reply if u have any solution
When you make one formula, you can't do any more summarizes of that calculated field (formula). That's why your first solution didn't work Sum(#amount)
Other solution Amount=(debit_balance-credit_balance)didn't work because you can make sum only for 1 field and you trying to make sum of 2 fields.
So solution for your problem is that just do a new formula Amount = sum(debit_balance) - sum(credit_balance) where you make 2 summarizes of each fields and subtract them.
Hope it helps

Return 0 value if Details duplicated

I need your help in creating crystal report.
I have a formula in details section that computes working time.
How do I make the value return 0 if it is duplicated?
Here's the scenario
Name Time (Hours:Minutes)
John 1:20
........ 3:30
........ 3:30
Total Hours -> ?
My problem is I dont want to use the duplicated values (3:30) like shown above. I want a total hours for 4:50.
you have two options:
check the option in Database tab.. Select Distinct Records so that duplicate records will be eliminated.
If you don't want to use the first option then to calculate use Running Total so that you sum only those that are distinct...
Create running total something like Do sum only after change of time value
You can use the function "previous" to compare the current value with the previous value, but it works only with fields.
But i am not sure if i understood, you may be more precise about your question.
1) make a formula called "hours" or some other name
if not isnull(previous({Result.Time}) and {Result.Time} = previous({Result.Time}
then 0
else {Result.Time} /* you have to assure the same return type */
2) let the "total hours" be a sum of the formula "hours"
Note that it will work only if the rows are ordered by hours.
The result is the same of using a running total fields as purposed by Siva.

Getting the values of the maximum record

I am facing some difficulties while developing a report. The problem is that I am getting a number of values in the Details section and I want only to display the record which it is having the maximum event number for each group (one record to be shown for each group).
My report structure is:
GH1:{Deal_NO} 1 -- Suppressed
Details:{Deal_NO} {Amount} {Event_no} {Comments}
1 1000 222 Rate
1 2345 655 Principal
1 444 111 Sell
GF1: {Deal_NO} -- Suppressed
So, my result should be:
1 2345 655 Principal
So, please instruct me on how to do that.
I tried to define in the Group Selection under Select Expert:
{Event.Event_no}=maximum({Event.Event_no},{Deal_No}), but some deals were disappeared.
You can't use that logic with record or group selection. Instead, use the logic you have but use it to suppress the Details Section. So,
//Suppress Details if the current record is not the record with the
// maximum amount for the group
{Event.Event_no}<>maximum({Event.Event_no},{Deal_NO})
Now, when you run the report every record will be suppressed except for the one with the maximum amount per group.

Summarizing each subgroup in Group Footer - Crystal Reports

I'm trying to work on a report for a client. Basically I need something like such
Group 1: Customer ID
Group 2: Truck ID
CustID Vehicle ID Detention Time
------ ---------- --------------
ABX 100 60
35
20
TOTAL: 115
200 80
15
TOTAL: 95
300 10
TOTAL: 10
TOTALS FOR CUSTOMER ABX
100 115
200 95
300 10
Is there anyway to accomplish this without a subreport? I was hoping for a "summary field" that I could summarize more than just a single value.
Thanks!
(FYI using Crystal Reports 2008)
Use a crosstab; place it in the report-footer section.
There might be a better way to do this, but the one that comes to mind is to use two arrays: One to store the truck ID and another to store the corresponding total. In each inner grouping (TruckID), just tack on another array element and store its total time. To display, you could cast the values to strings, attach a newline character after each entry, and set the field to "Can Grow". So altogether, you'd need three formulas: one to initialize the arrays (in GH1), one to update the arrays with sum({truck.time},{truck.ID}) (in GF2), and one to display each entry (in GF1).
With that being said, CR has terrible support for containers... You're limited to 1-dimensional, non-dynamic arrays that are gimped at 1000 items max. It doesn't sound like these would be big problems for what you're trying to do, but you will need to redim preserve the arrays unless you know ahead of time how many trucks you'll have per customer.