Crystal Reports Cross-Tab Column Totals as Variables - crystal-reports

I have a report within Crystal 2008 that has 2 subreports, each of which is a Crosstab. I have split them into different reports as their selection and database queries are unrelated.
What i need to be able to to is to create a variable for each of the Column Totals and be able to pass this onto a third report for each of the two cross Tabs.
The Layout of each cross tab is formatted the same, with the columns being the PO Number and the rows being charges against each PO. It is the total of the columns that I need to perform a further calculation on.
Total of Crosstab1 Column1 - Total of Crosstab2 Column1 for each column that is displayed by the selection query to give me a difference between the two crosstabs.
I have tried using the CurrentFieldValue but this only appears to set the total of the very last record to the variable.
I hope that there is a way to do this and that i have provided enough information for you to be able to assist me.

I think its hard to get the value from crosstab but one workaround would be.
Create a shared variable in both subreports and assign the summary value to the shared variable.
Suppose cross tab is showing employee salary sum then in the formula assign the value to the shared variable as
Shared Numbervar report1;
report1:=Sum(employee.salary)
similarly do in the second subreport aswell.
Now in main report create a formula
Shared NumberVar report1;
Shared NumberVar report2;
report1+report2;
let me know how it goes.

Related

Crystal Reports, driving Header/Footer decisions based on a specific detail row

I have a simple report that can display many detail rows.
I want to target a specific row and use it's values to populate aspects in the Report Header and Footer.
For example , I know what the minimum(primarykey) within the detail rows that I display.
A simply formula can capture that.
I want to pick up other attributes of the row with the minimum(primarykey) and display in the header or footer.
I therefore want to select a specific row select and use its data in the header and footer, something like:
Select NAME, DATE from DETAILSROWS where DETAIL.PRIMARYKEY = minimum(DETAIL.PRIMARYKEY)
I've thought about using a subreport here, and passing values back to the main report, but that doesn't see to the way to go... I've tried for example passing minimum(DETAIL.PRIMARYKEY) to the subreport so that the sub loads only the row I want, then passing the values back via shared variables. But I don't want to display the subreport, and if I suppress it, my shared variables don't seem to populate.
Displaying the values in the Report Footer would be easier than the Header. All you'd need to do is compare each row's primary key to the value of maximum({DETAIL.PRIMARY_KEY}) and save off the values. So something like:
stringvar saved_column1;
stringvar saved_column2;
if {DETAIL.PRIMARY_KEY}=maximum({DETAIL.PRIMARY_KEY}) then
(saved_column1 := {DETAIL.COLUMN1};
saved_column2 := {DETAIL.COLUMN2})
For the header, really the only way I can think of is to use the subreport like you're already doing. I'd just format the subreport to display itself, though, and not mess around with shared variables.
Okay so it turns out the SUBREPORT option is the way to go.
SUBREPORT is a bare minimum report that has passed to it, the lookup value you are after.
Long winded, I link to it using a formula that holds essentially: minimum(DETAIL.PRIMARYKEY).
In turn the subreport selects that single detail record.
Within the subreport, build a Formula and drop it the into its report header:
WhilePrintingRecords;
Shared DateTimeVar subCreationDate := {DETAIL.CREATIONDATE};
Shared StringVar subCreationName := {DETAIL.CREATIONNAME};
Finally, suppress all the the sections (delete what u don't need) on the SUBREPORT, and close.
On the main report... Not sure but it looks like the SUBREPORT can sit anywhere.
And because you've suppressed elements WITHIN the SUBREPORT, it won't display on the main report.
(So no need to suppress on the main report - and if you do suppress it there, it won't work anyway!)
Now create your formulas (in my case 2) on the main report and in each, repeat the variable declaration.
Shared DateTimeVar subCreationDate
Shared StringVar subCreationName
Again, each of the above sit in their individual formula declaration.
And from there, you now have "standard" formulas to work with on your main report.
They can be referenced just like any other!
Thx Ryan - your answer certainly helped me get where I need to go - u still get my +1!

Add 3 rows separately at the end of the crosstab

I am working on crosstab in Crystal Reports, I am able to see required data and everything is fine but I am stuck at one point where I need to insert Total, Avg and Max as 3 rows one below one at the end of cross tab.
I have tried Embedded Summary but that one is inserting a row below every row of the cross tab but I don't need that way.
I searched the web, but couldn't find the solution.
Have Global variables Like below:
Shared integer TotalCol1 CurrentVers;
Shared integer MaxCol1;
In the details section, use a formula to calculate these variables. (Max, Sum, Avg should be computed. Max may required a condition check before replace the present global value).
At the end, you can print these variables using a formula in the Footer (Group or report that you can decide)
I finally found a solution.:
In preview mode added the rows using the option Calculated Summary, by this way we can add any number of rows at the end of the cross tab.
Now by editing the required row, added the calculation formula for Sum, Max and Average.

Crystal Reports is grouping by default

I have a crystal report with three columns. I want to display all the records and a total in the last row. However, my crystal report is grouping by default. I am confused
This is how I do it in the CR.
This is how it shows
Thi sis how i wanted
I want everything in a single table and a one toal for each. Why is it grouping this way? Any help would be appreciated.
EDITED
Below is how i arrived at the TOTAL
Formulas
O/S BALANCE := amount - collected.
OSBALANCE TOTAL := SUM{#O?S BALANCE});
COLLECTED TOTAL := SUM({colection})
Add a cross-tab object to the report's footer section. Use the OS BALANCE field for the rows field and the COLLECTED for the summarized field.
See that is where it makes the difference in crystal reports. I will suggest one thing place OSBalance in detail and put the total in report footer and let me know the result

Referencing the last row's data in Crystal Report

I have a report where the fields come from data pulled from a SQL server. I have a total field that i have added to the report...however i have an interesting conundrum--i was hoping someone had a formula i could use.
Three of my columns do NOT need summation...however my project requirements are telling me instead to just pull the last number from the last row in the report and putting that in the total row. To better clarify:
1999 0.1% 0.2% 0.3%
2001 -2% 0.3% 3.4%
Basically, in the total field, i'd be pulling the values from 2001 since it is the last report row. In my total row, i want to have -2%, 0.3% and 3.4% showing (since those are the last row's values). SO basically, i just want to pull the last report row's data (NOT total it).
Anybody have a formula i can use for this?
If I read this correctly, I typically would just put the fields themselves in the footer, without any formulas. The report should display the values from the last record in the group.
Well, I have two formulas you can use... I think the only way to do this is with a variable to capture the final value in the details section, and then display it in the group footer. So, in details, create formula field like this:
shared CurrencyVar lastValue;
if (OnLastRecord) then
lastValue := {my_table.field_name}
Add this to your details section and suppress it (so it doesn't display). Then add another formula like this:
shared CurrencyVar lastValue;
lastValue;
Add this to your group section where the total would normally go.
You will need another set for formulas for each field you need to handle this way. Note that you could handle all the fields in the first formula if you use basic syntax (so you can have multiple statements under the 'if').
I would like to share my example.
I should keep last modified value in details and represent in group.
In details I have:
shared NumberVar X1;
if {Q.SklID}={#InSkl8} AND ({Q.Poredak}=1 OR {Q.Poredak}=2) then X8:={Q.MCena};
and in group I have following formula:
shared NumberVar X8;
X8;
This way, I escape situation to have NULL in group formula because I don't have else clause in details formula.

Crystal Report-Running Total

I have a problem with running Total in Crsystal report9
if their is no values available for a Paticular field how can we return the running total as '0'
Instead of display the Running Total directly in your report create a Formula Field based on the Running Total and drag it into the report.
Your formula should look like this (Crystal Syntax)...
if ISNULL({#RunningTotalField}) then
"0.00"
else
ToText(RunningTotalField, 2)
If there is no data for that particular group, then Crystal won't show it easily. Your options are :
1) Use subreports to display the values for a particular group, and keep the main report just looking at the table(s) containing the group headers.
2) Use a stored procedure as the source so you have full control over the SQL that is run.
The problem is that as soon as you use a field to group, Crystal will only return records where that field has been used. If it was simply in the Details section you could modify the link to a LEFT JOIN and it wouldn't matter, but the group forces the INNER JOIN which means the groups without data are not returned.
Unfortunately Running Totals don't show up if there are no records that match your criteria. An alternative is to use a set of formulas calculated in various sections of the report. The technique is widely described in the Crystal literature. For example, this TekTips gives a very succinct overview of your options.
You set up an initialising formula in each header, with the evaluation time directive "WhilePrintingRecords". This approach was the only one available for doing running totals in the "good ol' days" before RunningTotal objects were available.