0
votes

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
Do you want to dynamically change the grouping? like if your column gives some values; based on that value you will decide whether it should be a month or a year...right?Pratik Kaje
Well, not exactly. Values in column are all in texts for all groups.What I want is if I place the formula in Group#1, it will return the field Group#1 is grouping for. If I place the same formula in Group#2, it will return the field Group#2 is grouping for.Thanks.Nyi Nyi

2 Answers

1
votes

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.

1
votes

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