Crystal Report: Summarize multiple date fields in one - date

please help me..I've been trying to search this for weeks but can't find the answer..
Given: Currently I have these dates field on my crystal.
01/01/2015
02/24/2015
02/27/2015
02/28/2015
02/29/2015
How can I summarize it in one field to be like this,
01/01/2015, 02/24/2015, 02/27-2015 - 02-29-2015
generally, separate different dates with comma and join dates that are in range or consecutive in order.
Thank you very much.

There is no direct way of summarizing the field in crystal report like you mentioned in your question.
However, you could try a work-around.
Create a Group and group by the 'date' field you want to summarize and then-
1) Create a formula with a shared variable to be placed in the header section of the report:
shared stringVar result="";
2) Create another formula with the same shared variable to be placed in detail section which concatenates your result into a comma separated array:
whileprintingrecords;
shared stringVar result;
if(result='')
then result:=CStr ({Date1.Date1_Text})
else
result:=result + "," +CStr ({Date1.Date1_Text});
Here ,{Date1.Date1_Text} is the date field which you want to summarize.
3) Create another formula with the same shared variable to be placed at the report footer:
shared stringVar result;
NumberVar i;
StringVar array dates := Split(result,",");
//Here you could put your logic to convert dates to date range.
//....
result; // returns final result

Related

Crystal Reports - concatenating rows based on a field's value

I have a report by a dataset by two master-detail tables (For example, Organizations and Persons).
I have a group section by the master ID.
I want to show the list of the persons in each organization separated by comma in a single row instead of showing each person in a row.
How can I do it?
I found out how can I do it.
I added a group on organizationID.
Added this formula to the group's header section and suppressed it:
WhilePrintingRecords;
StringVar Array reset;
StringVar Array names:=reset;
True;
Added this formula to the detail section and suppressed it:
WhilePrintingRecords;
StringVar Array names;
Redim Preserve names[Ubound(names)+1];
names[Ubound(names)]:={persons.name_field};
Added this formula to the group's footer section:
//{#display}
WhilePrintingRecords;
StringVar Array names;
Join(names, ",");

Crystal Reports - Selecting data in the first row to be used in a formula

I have a very basic report with no groups. The details consists of a number of numeric columns. I want to add a formula field which will use a field from the first row. Example:
(ColumnAFromCurrentRecord - ColumnBFromFirstRecord) / ColumnBFromFirstRecord
Can someone point me in the right direction?
1.
Create a formula named AssignFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue := {MYDBNAME.MYSTRINGFIELD};
Put the AssignFirstValue formula in your Report Header and suppress it.
2.
Create a formula named PrintFirstValue and define it like this:
WhilePrintingRecords;
Global StringVar strFirstValue;
strFirstValue
Put the PrintFirstValue formula wherever you want to display the first value in your report.
you need to extact the column b from first record. try below solution.
Note: This is not a tested solution as I at present I don't have CR.
create below formula Count and place in detail section:
Local NumberVar a;
a:=a+1;
This will number the rows starting from 1 to the last row.
Now create one more formula StoreB:
Share NumberVar b;
if {#Count}=1
then b:=columnb
This will store the value of columnb in first record in variable b
Now use where you want:
EvaluateAfter(#StoreB)
Shared NumberVar b;
(ColumnAFromCurrentRecord - b) / b
Let me know how it goes.

Concatenate string field in crystal reports

I have below data in my detail section.
Contract No
VTC/2013/0026
VTC/2013/0028
VTC/2013/0030
These data are belong to a one field in a table and there can be more.
I want to display the same details in the report header like below.
VTC/2013/0026, VTC/2013/0028, VTC/2013/0030, ...
How can I do that without using a sub-report?
Follow below steps:
Create a formula Concat and write below code and place in right most part of the report.
Shared Stringvar a;
a:=a+Contract No+", " ;
now create one more formula display and place in report header.
EvaluateAfter(#Concat);
Shared Stringvar a;
a

Crystal Reports formula to grouping field

I am trying to create a formula in Crystal Reports which would return the grouping field depending on what group the formula is placed. For example, if the formula inserted in the group row 'Month', the formula should return ‘command.month’. If the formula inserted in the group row 'Year', the formula should return ‘command.year’. Can anyone help with this, please?
Thank you.
If your date field format is MM/DD/YYYY then you can use below condition in Formula field. and use this formula field in grouping.
if {YourGroupFieldValue }='month' then
left({DateField}',2)
else if {YourGroupFieldValue }='Day' then
mid ({DateField}',2,2)
else
right({DateField}',4)
It should work because i have used it.
Consider you have two groups Month and Year. Add one formula in month group. In that formula create a shared variable as shown below.
Shared numbervar num:=0;
Create another formula in Year group. In that formula create a same shared variable as shown below.
Shared numbervar num:= 1;
Now create third formula, in that formula add below declaration.
Shared numbervar num;
if num = 0 then {your logic}
else if num =1 then {your logic};
Put your third formula in both groups and run the report. Same formula will show different values in different groups. I hope I got you this time... :)

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!