How to Sum Conditional Data in Crystal Report - crystal-reports

I have a table called tbl_sale and there are seven columns in this table
I want to sum those quantity which is returned to the shop which is in negative
so that I show how many quantity has been returned

Create these formula fields:
// {#fields}
{table.amount_0}+{table.amount_1}
// {#negative}
If {#fields}<0 Then
{#fields}
Insert a summarized field on the {#negative} formula.

Related

How to implement a conditional fomula in Crystal Report

I have a table named tblRecovery with 4 column. ID, LStatus, Amount and RecoveredBy I created a formula to sum Amount Column where LStatus Column value is "WCL". I use following code.
It sum all value of Amount column without condition. I want to sum amount column if Lstatus Column value is "WCL". How can I do that?
if {tblRecovery.LStatus}='WCL' then sum({tblRecovery.Amount})
Crystal Reports formulas work on a per-record basis.
Your current formula shows the sum of tblRecovery.Amount on every single row where LStatus='WCL'.
To get the desired result, create a formula-field with following formula and the create a sum of it:
if {tblRecovery.LStatus}='WCL' then
{tblRecovery.Amount}
else
0

Crystal- Reports: Exclude a field value from running total

In crystal reports is how can one exclude a field value from running total. This field is not suppressed however we donot want to add its value to the sum total.
I would suggest you to create one more column for the calculation purpose and then place after the last column and write below formula:
if column="NonDelivery"
then value
else 0
Now take the sum of this column and then place the sum below your mail value column and supress the newly created column.

Hide rows with no values in hierarchial grouping in crystal reports

I have a crystal report - showing some financial data. As normal with financial data we have several general ledger accounts - which are grouped hierarchically. We are using grouping in Crystal report with some totals on hierarchical groups.
There are some rows where the values are zero. The groups also have total of zero as a result of this. We need to hide these rows. If we try to check the sum of the field - on the group level - it hides all the parent rows (since they themselves do not have any value - only values are derived from the child rows).
Need some way to do this in crystal?
You can suppress rows base on a condition.
In the menu go to Report->Suppress Expert...
Select the details line then select the formula button next to Suppress
You only need to put the condition that will be true to suppress the line
{[Your value field]} = 0
For groups, you will need to find the sum of your total for that particular group
SUM({[Your value field]}, {[field you are using to grouped by]}) = 0

Formula to Sum "amount" column in Crystal report

I have a column name as "Amount" in CR. I need to sum that column.
I created a new formula and tried sum( { MycolumnName} ) and it says
"A number field or currency amount field is required here"
Is there any way to apply conversion in formula itself.
Why create a formula when you can just create a summary field by selecting your column and going to the menu and selecting Insert Summary, Insert Subtotal or Insert Grand Total depending on your needs? You can place the summary field in a group section as a subtotal, or in the report footer as a grand total.
If you need to apply a conversion in the formula, you can use CCur like this:
sum( CCur({ MycolumnName}) )
More information on converting types in Crystal Reports can be found here.
Change the type xs:string to xs:decimal of the column MycolumnName in xs:element in .xsd page

How to detect if a table has rows in crystal 2008

Is there a built in crystal method to detect whether the a table in a crystal report has any rows?
I have created a sub report which has some Title text in the header and a detail line with the table info.
I want to be able to supress the title text from printing if there is nothing to print.
Also, is there any way to pass this to the "master" report so that I can suppress printing the sub report completely if there is nothing to print?
Regards
Use Count() function.
Use it with one of your data source fields.
from Crystal Reports 2008 Help:
Overloads
Count (fld)
Count (fld, condFld)
Count (fld, condFld, cond)
Count (x)
Arguments
fld is any valid database or formula field that can be evaluated by the function.
condFld is a field used to group the values in fld by.
cond is a String indicating the type of grouping for condFld. You only specify this argument when condFld is a Date, Time, DateTime or Boolean field. For more information on the valid strings for this argument, see Conditions for summary functions .
x is an array of values that can be evaluated by the function being used.
Returns
Number
Action
Enables you to count the values that appear in your report (for a specified field). For example:
If a sales report includes all orders made and the amount of each order, you can compute the total number of orders that appear on the report (a grand total count).
If you break orders into groups (for example, orders grouped by the state that they come from), you can compute the number of orders per group (in this case, per state).
If you break orders into date or Boolean groups (for example, orders grouped by the month in which they were placed), you can compute the number of orders per group based on a particular change in the date or Boolean field (in this case, per month).
If you specify a set of individual values, you can compute the number of values in the set. For information on this kind of counting, see Array summary functions .
Examples
The following examples are applicable to both Basic and Crystal syntax:
Count({orders.AMOUNT}, {orders.CUSTOMER ID})
This formula counts the number of orders in each group of orders in the Amount field (the total orders for each customer). The orders are separated into groups whenever the value in the Customer ID field changes.
Count({orders.ORDER AMOUNT}, {orders.ORDER DATE}, "monthly")
Counts the number of orders in each group of orders in the Amount field (the total orders for each month). The orders are separated into groups whenever the value in the Date field changes to a new month.
The following examples are applicable to Crystal syntax:
If Count({orders.ORDER ID}) >= 100 Then
"Congratulations on meeting your quota!"
Else
""
Prints the congratulatory message if the number of orders is 100 or more, and prints nothing if the number of orders is less than 100.
Count([1,2,3,4,5])
Returns 5. Counts the total number of values in the array.
Note: Using this function in a formula forces the formula to be evaluated at print time.
For more information on evaluation time considerations, see Evaluation Time.