Crystal Report sum by column - crystal-reports

The Problem
This is the problem with my crystal report, I need to sum values from different columns with the same name.

Create a formula for each material that, depending on what position it is, returns the value for it.
For example, 1210P_Kg could follow the logic of:
IF {Material 1} = "1210P" Then {Material 1_Kg}
Else IF {Material 2} = "1210P" Then {Material 2_Kg}
Else IF {Material 3] = "1210P" Then {Material 3_Kg}
Then, show the sum of each of these formulas in a footer section.
A more powerful solution would be to use a UNION view, command, or SP to turn each record into 3 records with Material, Kg, etc.

Related

A "While printing" formula can not be used to group Crystal Clear

I am working on a report where I created a formula to add 5 different totals of 5 different formulas to give a grand total.
Example: (all these formulas have different calculations)
Formula Total_1 [x1+y1 = 50]
Formula Total_1 [x1+y1 = 50]
Formula Total_2 [x2+y2 = 10]
Formula Total_3 [x3+y3 = 20]
Formula Total_4 [x4+y4 = 10]
Formula Total_5 [x5+y5 =10]
Then I created another formula
[Grand_total= Total_1 + Total_2 + Total_3 +Total_4 +Total_5]
However now I want to sort my records in descending order of the value of the [Grand_total Formula.]
But I get an error saying A "While printing" formula can not be used .
What can I do to get around this?

Remove formula from column with python

I am trying to remove the formula from a column in a existing sheet with python.
I tryed to set my formula to None using the column object (column.formula = None)
It does not work and my column object remains unchanged. Anyone have inputs to solve this issue ? Thank you !
This took me a bit to figure out, but seems like I've found a solution. Turns out that this is a 2-step process:
Update the column object to remove the formula (by setting column.formula to an empty string).
For each row in the sheet, update the cell within that column to remove the formula (set cell.value to an empty string and cell.formula to None).
Completing the STEP 1 will remove the formula from the column object -- but that cell in each row will still contain the formula. That's why STEP 2 is needed -- STEP 2 will remove the formula from the individual cell in each row.
Here's some example code in Python that does what I've described. (Be sure to update the id values to correspond to your sheet.)
STEP 1: Remove formula from the Column
column_spec = smartsheet.models.Column({
'formula': ''
})
# Update column
sheetId = 3932034054809476
columnId = 4793116511233924
result = smartsheet_client.Sheets.update_column(sheetId, columnId, column_spec)
STEP 2: Remove the formula from that cell in each row
Note: This sample code updates only one specific row -- in your case, you'll need to update every row in the sheet. Just build a row object for each row in the sheet (like shown below), then call smartsheet_client.Sheets.update_rows once, passing in the array of row objects that you've built corresponding to all rows in the sheet. By doing things this way, you're only calling the API once, which is the most efficient way of doing things.
# Build new cell value
new_cell = smartsheet.models.Cell()
new_cell.column_id = 4793116511233924
new_cell.value = ''
new_cell.formula = None
# Build the row to update
row_to_update = smartsheet.models.Row()
row_to_update.id = 5225480965908356
row_to_update.cells.append(new_cell)
# Update row
sheetId = 3932034054809476
result = smartsheet_client.Sheets.update_rows(sheetId, [row_to_update])

How to display total sum values in summary band of groups partial sums

I have a report like the image below:
Note that the sections separated by a blank space are grouped by the month and are iterated over a group band. I want to put partial in the summary band by the type of the register, like in the example figure get the sum for Register type A in January = 10, February = 5, March = 1 so as the total = 10 + 5 + 1 = 16. So the summary will look like:
How can I achieve that kind of conditional sum in jasper? Thanks in advance.
After trying a little bit with iReport I found a solution: to get the partial sum by type you have to add a variable that has the calculation type as "sum" and the reset type set as "Report". Once you set the values you have to create a variable Expression that has value only when the cell value of type is the desired value, so for the example in the question, in the column Value of the summary band in cell with the value "16" you have the expression :
$F{type}.equals("A") ? $F{value} : 0
and so on for the other types in the summary.

Crystal Reports -- How to show after decimal value differentnly in formula

I want to show after decimal 2 value in report but there a condition if value meet that condition then need to show full value. formula is given below but it is giving error
if trim({As400InTemp.PARTYCODE})='006883' then
{As400InTemp.SPPRIC}
else
round({As400InTemp.SPPRIC},2)
you can use MID like this:
"33.09789"
MID({yourstringhere}, 4)
or
MID(CSTR({yourstringhere}), 4)
it will return a value of 09789;

Calculation of Previous field

New to CR and use CR v10 and SQL Server 2000.
For the first record i.e Beginning Balance , the calculation is sum(field) from the input date, which I have calculated in SP as BegDateSum
But for the rest of the records under a group, the calculation should be previous(balance)+IN+OUT
Sample has been given:
Date Doc Descrip IN OUT Balance
Group Header-------- Beginning Balance-------------- 50 <---- sum(field) from my inputdate
3/2/2012 A -1 0 49 <-- (50+(-1)+0)
4/2/2012 B -2 0 47 <-- (49+(-2)+0)
5/2/2012 C 0 3 50
6/2/2012 D -2 3 51
How do I achieve this?
I am not sure whether to use running total, in case I have to how to do it.
A running total field won't work in this case, they are designed to add up (or count, or average, etc) one field and give you the sub-totals automatically. But, we can do some custom functions that will give the results you need. Assuming that your initial 50 is a static value, you would set a variable to that amount, and then add the IN and OUT values as you go along (printing that result of that).
First, initialize the value in the report header with a formula like:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := 50;
""; //print nothing on the screen
Then, the formula to calculate and show the new balance, in the bar where the data is:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := Balance + {tableName.IN} + {tableName.OUT};
The last line both calculates the new value, and tells what the result of the formula should be.
If the "50" is calculated somehow, then that will have to be done before the formula that calculates the new balance. If it is based off of the first record read in, you'll want to use a formula that includes If PreviousIsNull({tableName.Balance}) Then ..., that is usually a good indicator of the first record in the data set (unless that field can be null).