How to avoid including duplicate records in group summaries in Crystal Reports - crystal-reports

I have a report which groups the record by company, customer, Invoice, date... but i have duplicated records. I want to sum the total and not include the duplicate records. I use the running total, and ongroup change to invoice. It works for the grand total in the report footer but i still want to get a subtotal in this case will be 15006.26 + 39772.26 + 21140.00 + 4571.92.
I tried to use the whileprintingrecords and declare a currencyvar=0 and recalculate the total like this
Whileprintingrecords;
currencyvar Amt;
if previous ({brptARAgeUPSSequence;1.Invoice})<>{brptARAgeUPSSequence;1.Invoice} then
currencyvar Amt:= Amt + {brptARAgeUPSSequence;1.AgeAmount}
else if onfirstRecord then
currencyvar Amt:= {brptARAgeUPSSequence;1.AgeAmount}
But I get all the O , i do not know what is the problem

You need two Running Totals: one for the grand total and one for the group level. Since it sounds like you've got the one for grand totals working, all you need to do is duplicate that one and make one small change to it to get it to work at the group level.
In the new Running Total settings, just change the "Reset" field from "None" to "On change of group" and select the group level you want this to work at. Then, place this new RT in the appropriate Group Footer section of your report.

Seems like Amt is being re-declared. Try this
Whileprintingrecords;
currencyvar Amt;
if previous ({brptARAgeUPSSequence;1.Invoice})<>{brptARAgeUPSSequence;1.Invoice} then
Amt:= Amt + {brptARAgeUPSSequence;1.AgeAmount}
else if onfirstRecord then
Amt:= {brptARAgeUPSSequence;1.AgeAmount}

Related

Crystal Reports - add results of grouping together

Really low level question, but it's been 5 years since I used Crystal Reports and I want to ensure that before I think about using it again that it would be suitable - I think it will.
I have two groups of data - Group 1 is Income, Group 2 is Expenses. I am looking to create a Profit result by a formula to take the sum of Group 2 away from the sum of Group 1. If I recall this is quite straightforward, but just throwing this one out there to begin with.
Thanks
are income and expenses 2 different values of the same field in the database? If so, create a formula like below to storage Income and expenses total values and place it on your group footer
if {database your field} = "Income" then numbervar Income := {your group total} else numbervar Expenses := {your group total}
Then subtract them in a second formula placed on your report footer(numbervar Income - numbervar Expenses)

How do I stop data from continuing to second record in Crystal Report?

my title could be a bit confusing...I will explain in details here.
My current problem is that I am creating a report for a company, when I select only 1 vendor at a time, the report works fine. Please look at the picture 1 below for further details:
So basically, the report will only show the amount when the value is not 0. Note that at "Bal. Amount", the data is calculate by the formula:
CurrencyVar Amount;
Amount := Amount + ({#DebitAmt} - {#CreditAmt});
However, when I chose a range of different vendors. The report went haywire. Now let's take a look at second picture:
If you notice it, the last result in Picture 1 was 605.00. The report took the data and deduct the 2160.00.
What I really want is to start fresh and make sure the report doesn't take the data from previous vendor...how can I do this?
Group by vendor and do your calculations according to the group... so that there will be fresh entry for the each time vendor changes
Edit..............................................................
Place fields in details and take summary in group footer and write your calculation part Bal Amount in group footer itself and supress the details
Two options:
Use a running-total field; key is to reset the field's value on change of vendor
Use your current approach (manual, running total), but add the missing logic:
// {#reset}
// place in group-header section
WhilePrintingRecords;
CurrencyVar Amount:=0;
// {#increment}
// place in details section
WhilePrintingRecords;
CurrencyVar Amount + ({#DebitAmt} - {#CreditAmt});
// {#display}
// place in group-footer section
WhilePrintingRecords;
CurrencyVar Amount;

Conditional Running Total in Crystal Reports

Using VS 2008 Crystal Reports, I would like to do a running total on a formula that is calculated on a group change. When I click on add a running total, this formula does not appear in the Available Tables and Fields list.
This is the logic:
On Change Group of group
if CalculatedValue > 0 then
ReportRunningTotal1 += CalculatedValue
else
ReportRunningTotal2 += CalculatedValue
Can I specify a condition in a running total? If not, how else could I do this?
More info: I am doing a running total called GroupRunningTotal of the value of db field BillableHours. At change of group, I am comparing GroupRunningTotal to a db field for that group MaxHours, and I display a result of MaxHours - GroupRunningTotal at the group level.
Appropriate today - Think of it like the electoral college - the person who wins the election does not depend on total number of votes, but of number of votes in the electoral college.
I'm interpreting your question to mean that you want to add up all the negative values in one running total (RT_Neg) and all the positive values in another (RT_Pos). How about this:
Make the RT_Neg running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}<0" as your custom formula. Never reset.
Make the RT_Pos running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}>0" as your custom formula. Never reset.
Insert both running totals in the group footer (if you put them in the header, it may not sum properly)
Alternatively, you can:
Make a custom formula "If {Tbl1}.{Amount}<0 then {Tbl1}.{Amount} else 0" and make a running total based off that.
I think one of these 2 options will get you to your goal.
You most likely cannot use one RT field as condition for other RT field. You can use formulas, placed on group footer and evaluated 'whileprintingrecords()'; in these formulas you can assign/sum into some variables and display these variables at the end of report. About like next (generic idea only, you need initialization and display routines as well):
numbervar rtcurrent := sum({somefield}, {groupfield});
numbervar rtplus;
numbervar rtminus;
if (rtcurrent > 0)
then rtplus := rtplus + rtcurrent
else rtminus := rtminus + rtcurrent;

How can I filter a report with duplicate fields in related records?

I have a report where I need to filter out records where there is a duplicate contract number within the same station but a different date. It is not considered a duplicate value becuase of the different date. I then need to summarize the costs and count the contracts but even if i suppress the "duplicate fields" it will summarize the value. I want to select the record with the most current date.
Station Trans-DT Cost Contract-No
8 5/11/2010 10 5008
8 5/12/2010 15 5008
9 5/11/2010 12 5012
9 5/15/2010 50 5012
Create a group on Contract-No.
Create a formula field to display most recent Trans-DT.
Something like: Maximum ({Trans-DT}, {Command.Contract-No})
Create your summary fields or running totals based on the newly created Contract-No group.
Edit:
To summarize costs and count contracts, you'll need a bit of trickery.
Add this (in a formula field) to the report header section:
// start the sum
// put in report header
WhilePrintingRecords;
Global NumberVar TotalCost := 0;
This goes in the report footer:
// final count
// put in report footer
WhilePrintingRecords;
Global NumberVar TotalCost;
TotalCost;
And place this in a formula field within your Contract-No or Station group:
WhilePrintingRecords;
Global NumberVar TotalCost;
if {Command.Trans-DT} = maximum({Command.Trans-DT}, {Command.Contract-No}) then
TotalCost := TotalCost + {Command.Cost}
else
TotalCost;
I'll leave the counting part to you. Good luck!

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.