How to calculate sum of a formula field in crystal Reports? - crystal-reports

In some inherited code, I see group headers/footers have items like 'Sum of #numcount' . I cannot get the sum of a formula field. Any thoughts?

The only reason that I know of why a formula wouldn't be available to summarize on is if it didn't reference any database fields or whose value wasn't dynamic throughout sections of the report. For example, if you have a formula that returns a constant it won't be available. Or if it only references a field that is set throughout the report and returns a value based on that field, like "if {parameter}=1 then 1" would not be available either.
In general, the formula's value should not be static through the sections of the report you're summarizing over (Though the way Crystal determines this is beyond me and this doesn't seem to be a hard and fast rule)
EDIT: One other reason why a formula wouldn't be available is if you're already using a summary function in that formula. Only one level of summaries at a time!

(Assuming you are looking at the reports in the Crystal Report Designer...)
Your menu options might be a little different depending on the version of Crystal Reports you're using, but you can either:
Make a summary field: Right-click on the desired formula field in your detail section and choose "Insert Summary". Choose "sum" from the drop-down box and verify that the correct account grouping is selected, then click OK. You will then have a simple sum field in your group footer section.
Make a running total field: Click on the "Insert" menu and choose "Running Total Field..."*** Click on the New button and give your new running total field a name. Choose your formula field under "Field to summarize" and choose "sum" under "Type of Summary". Here you can also change when the total is evaluated and reset, leave these at their default if you're wanting a sum on each record. You can also use a formula to determine when a certain field should be counted in the total. (Evaluate: Use Formula)

You Can simply Right Click Formula Fields- > new
Give it a name like TotalCount then Right this code:
if(isnull(sum(count({YOURCOLUMN})))) then
0
else
(sum(count({YOURCOLUMN})))
and Save then Drag and drop TotalCount this field in header/footer.
After you open the "count" bracket you can drop your column there from the above section.See the example in the Picture

You can try like this:
Sum({Tablename.Columnname})
It will work without creating a summarize field in formulae.

Related

How to filter records in a single section of Crystal Reports

I have my base record set filtered with a parameter. However, this leaves me with 6 records and I need to filter down to one particular record in each of my sections. If none of the records meet my criteria i cannot suppress the section, it will need to just stay there and blank.
Essentially, I need a method to filter down records that hit one of my sections but not affect the report as a whole.
A few notes:
I cannot use a subreport for this. I need to duplicate this effort over a couple of sections and if I add any more sub reports it just crashes crystal reports (I have a lot of data & a ticket with SAP)
Using a suppression formula hasn't worked yet because I need the section to exist, if it has a null value
Applying no filter doesn't help me because it will duplicate my section 6 times
2 options.
a)
Right Click on white space and choose Insert Group
Choose your field and select specified order or use another record that can filter your data
On the Specified Order Tab click New
Select equal to on the combo box and specified what record you need to be shown
or
b)
Right click on the record
Next to the suppress check box, click on x-2
Here you can create a formula to suppress the records that you don't need.

Crystal report Cross-Tab order by another column

I've made a crosstab in crystal report like below:
However, as you can see, the ordering is weirld (i.e. the correct one should be like below:)
And the ordering is stored in another field called order, I took a look in the crystal report's cross-tab expert sorting option, it doesn't allow me to order by another column, it only allows me to sort either ascending or descending, how can I set the ordering by another column?
Crosstab's sorting is based on the rows order, if you want to sort it in your on you have to add some extra rows and have to suppress subtotal and Label in Customize Style of Crosstab Expert
Example:
If you have 3 rows(A,B,C) to display and you have to sort it in order like B,C,A then you have to add 2 new rows(B,C) now your Crosstab looks like (B,C,A,B,C) now you have to suppress Rows B and C you meet your both requirements for sorting and display order
But This solution have some limitations like
if you want to export the report in Excel then it will add extra cells in grand total.
otherwise you are good to go.
Example:
If you have 3 rows(A,B,C) to display and you added one row and you suppress it to solve your sorting issue then in Excel its grand total looks like
A B C
a 1 3
b 2 2
---------------------------
Total: 3 5
Yes, you can not sort on another column. You must use any of one column as a header.
In Crystal report, sorting happened based on header column's value (That's why you see as per alphabetic).
I also face this issue and how I solved, that I am explain. You have to use a formula which have order, but either hide it or use a value like in this link.
https://scn.sap.com/thread/3341846
Second option as per this link. (I think first you check this)
http://www.codeproject.com/Tips/493334/Custom-sorting-for-Crystal-Report-Cross-Tab
https://scn.sap.com/thread/1172741
open crosstab expert, highlight the column that you want to reorder, go to Group Options and select in specified order. This will open another tab where you will have your available values listed there. Using the arrows on the right side you can move up or down your values and accommodate them in the order you want them to be displayed.
Simple way would be take order column from stored procedure to cross tab and set the order according to that column.
Then supress the order column and reduce the width of that column to minimum pixel so that it doesn't appear in cross tab.
Make the field you want to sort by a group field and hide it. To hide it, in the Crosstab Expert > Customize Style dialog select this group then use the Group Options area to Suppress Subtotal and Supress Label. Worked for me.
Use the order field as the grouping column and change the label for said column to show the actual sizes. The labels can be changed in Crosstab Expert, Grouping Options and then the tab Options.

Pass Crosstab total to variable

I'm trying to create a crosstab in Crystal Reports, integrated with the Visual Studio environment. The problem is that I need to use the total value of the crosstab (here I mean the Line Total) to do some other calculations in the report.
I know a bit of Crystal Reports, but never did something similar. Searches on google resulted in nonsense answers or overly complicated solutions to solve the problem, or solutions that were not exactly my problem.
Is there a relatively simple way to do this? I just need to get the total value of the crosstab and put in a variable, that's all.
Thanks in advance.
Honestly, I didn't think this was possible, but I found a way:
In Preview mode, select the desired field (I used the grand total row/column).
Right click the field, choose 'Format Field..., select the 'Common' tab, then click the conditional-formula button adjacent to the 'Display String' property.
Enter the following text
:
// change to desired type
Shared Currencyvar amount := CurrentFieldValue;
// change formatting to match desired value
ToText(amount)
Create a formula {#amount}; enter the following text:
:
// change data type to match
Shared Currencyvar amount;
Place this field in a section that follows the section that contains the cross-tab
Insert a sub-report in the same section as the one that contains the cross-tab (you don't need to include any tables)
Create a formula field {#amount}; enter the following text:
:
// change data type to match
Shared Currencyvar amount;
The final result will resemble:

Crystal Reports - sum of report field error when inserted into report

I've created a crystal report with a field issueSUM.LineTL in the detail section of the report.
This field returns the correct information per line.
I need to sum this field in the report footer and i have created a formula field - Sum({IssueSum.LineTL}).
I inserted this field and at report generation it comes up with an error:
Error in formula Sum({IssueSum.LineTL})
The field name is not known
Please advise as to what could cause this
Many thanks
You have given wrong syntax in sum forumla, instead of creating a formula and writing the sum(). Right click on issueSUM.LineTL and go to insert summary and generate summary from there.
I'm not sure if it is just a typo here in your post, but your formula is Sum({IssueSum.LineTL}) whereas your field is issueSUM.LineTL. That's a capital 'I' versus a lower-case 'i'. When creating formulas, double-clicking on the field in the field explorer window of the formula editor to insert a field will help you avoid such typos.
Other than that I agree with #Siva that right-clicking and choosing "Insert" -> "Summary" is a much easier and more reliable way to create summaries. Make sure to choose "Sum" as the type of summary from the choices available and put the summary in the report footer.

strange crystal report summation issue for columns

I am trying to sum all the column value and want to display a summary. I am choosing Insert -> Summary -> Column name and Sum.. But rather then showing sum it is counting the rows and displaying the rows. Kindly please suggest some solution. I am available here if some one need for more info to help please comment. (Sap Scn Crystal Report)
Are you sure you are selecting the sum option from the summary?, because normally this should have returned the sum of the values. As an alternative you can use a Running Total Field.
From the Field Explorer window, right click on the "Running Total Fields" and select "New".
In the window that will appear, on the left side you will see the available tables and fields. From there select the field that you want to sum up and press the top ">" button.
As a type of summary select "sum", type a name for the "Running Total Name:" and press OK.
Drag and drop the new Running Total Field on a section of your report.