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.
2 Answers
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... :)