Crystal Reports, calculate sum field - crystal-reports

I need your help, how can I know the total(sum) in a field that is itself the joining of two formulas:
Main formula:
sum(#weight)
Formula 1:
#open = if ({OrderRel.OurReqQty}
- (Sum ({ShipDtl.OurInventoryShipQty}, {OrderRel.OrderRelNum}))
- (Sum({ShipDtl.OurJobShipQty}, {OrderRel.OrderRelNum}))) < 0 then 0
else
{OrderRel.OurReqQty}
- (Sum ({ShipDtl.OurInventoryShipQty}, {OrderRel.OrderRelNum}))
- (Sum({ShipDtl.OurJobShipQty}, {OrderRel.OrderRelNum}))
Formula 2:
#weight = {#open}*{Part.NetWeight}
I can't calculate the sum field by referring the #open and #weight formulas.

You can't calculate the sum by just using sum function, Instead you may use running total or write a formula to calculate sum of the weight function like sum one by one for each group and then reset it at start of the group

Make a third formula that uses the logic {#open} + {#weight}. This will get the sum of the two values per record.
If you're looking for a grand total of every instance of Open and Weight on the report, use the new formula as the field to summarize a Running Total. Set the Type of Summary to sum, evaluate for each record, and reset never.

Related

SAP Crystal Report refer to sum but not calculate

I have a sum I want to basically copy the text but not calculate the formula.
Sum formula:
if next ({field}) > 0 then next ({field}) - {field2}
Formula works fine, I need to duplicate/copy the Sum ##, but I don't want the formula.
I've tried Totext, CSTR, true/false etc... everything copies the sum formula.
I just need something like "sum" and no formula.
I figured it out
abs (if next ({field}) > 0 then next ({field}) - {field2})

How to sum in Crystal Report?

Im new to Crystal report. Would appreciate for your help and advice.
I have applied the 1st formula add into the crystal report and trying to sum it if the value is only 1. Attempted to create 2nd formula but having the error.
Formula: test3
if(Count ({CUSTINVOICEJOUR.INVOICEID}, {CUSTINVOICEJOUR.INVOICEID})) = 2 then 1 else 0
sum ({#Test3})
error - this field cannot be summarized
Crystal cannot total formulas that depend on totals.
You can define a numeric variable and increment it in a GF formula using the same conditional logic. Then, display the resulting total in a formula below the "action".
You didn't describe what level of aggregation you are after (grand total across level 1 subtotals? Level 1 total across level-2 subtotals?) so it's difficult to refer to appropriate level of "action" in more concrete terms.

Sum of Formula field

I have two values: Value and Percentage. To calculate the total, I just need to create a formula like this one:
({table.value} / 100.00) * {table.percentage}
My report shows the amount of sales grouping by product:
Value----------Percent-----------Total
Sum of Value---???---Sum of the formula above
The problem starts when I need to show the percent value grouped by products, I can't simply show a Sum of Percent and showing the Medium displays wrong value.
*Correct total based on the percentual.
For example, the second line of the table shows values grouped by product, as you can see, simply calculating the Medium shows 6,34 when it should be showing 8,32.
So, I was thinking about creating another formula, just to calculate the Percent value when grouped, like this:
Sum ({#Calculated}, {product.product_id}) / Sum ({table.value}, {product.product_id}) * 100
When previewing, it shows the correct values, but when running, it throws an exception telling me that I can't Sum the {#Calculated} because it needs to be bound to a grouping.
Is there any way to recalculate the percentual value based on a formula?

Can't Sum Formula in Crystal Reports

I am trying to sum two different formula fields in Crystal. It will not let me select them from the Sum. The first formula is
if Sum ({tblPostedLine.pli_QUANTITY_SHIPPED}) >= 1
then {tblPostedLine.pli_NET_PRICE}
else ({tblPostedLine.pli_NET_PRICE} * -1)
I am trying to take a price and make it a negative value if the quantity is a negative value. I then want to sum the amounts to get a net amount that was shipped.
The other formula is
If PreviousIsNull({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
or ({RodsvwCatalogAnalysis.pro_PROMOTION_CODE}) <>
Previous({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
then {RodsvwCatalogAnalysis.pit_AREA_PER_PAGE} else 0
With this formula, I am trying to sum at a group level, not the details level. When I just sum the group level number, it is adding it every time the value is listed in the details as well.
I am open to any suggestions.
Thanks!
For the first scenario,
Create 1 variable formula in detail level to hold with your requirement.
for e.g.
#NetPrice , formula if {tblPostedLine.pli_QUANTITY_SHIPPED} >= 1 then
{tblPostedLine.pli_NET_PRICE} else ({tblPostedLine.pli_NET_PRICE} * -1)
using running total field feature in your Field Explorer to sum up the value and place
your group footer.
For the second scenario, I believe it relate to promotion group and again you could use the running total field feature to evaluate the sum condition and reset the value when condition are meet like field value change.

Calculating a weighted average for a group

I have a reports similar to the following:
I need it to look like the following:
The report is grouped by Department. I cannot figure out how to create the formula field YTD AVG to calculate and show in each group footing and then reset for the next group.
I understand the calculation for the YTD AVG, for example YTD AVG for dept1 would be:
((80*100)+(100*40)) / (100+40)
I just don't know how to get it in Crystal Reports.
Use Crystal's weighted average summary function:
Insert a summary, and select the group footer
Select the database field containing the average
Select Weighted average with
Select the field containing the number of responses
Create a formula called 'Month_Total' and place it in the details section for each row/month and suppress it {month.average} * {month.responses} In your example, this will give you the "(80*100)" and "(100*40)" portions.
Create another formula called 'Department_Avg' and place it in the department group footer section sum({#Month_Total},{month.month_name}) / sum({month.responses},{month.month_name})
The second parameter to Sum() should match whatever department-related field you're already grouping on and specifies that you want to sum only over the individual groups. This will give you your entire YTD calculation for each group/department.