0
votes

I am new in crystal reports so I don't know what to do

How can I make a group with this formula:
in Main Report

if DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO})=1 then
//group by
PROD.GROUP_ID
else if DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO})>1 and 
   ({PROD.GROUP_ID}=previous({PROD.GROUP_ID}) or 
   {PROD.GROUP_ID}=next({PROD.GROUP_ID})) then
//group by 
    PROD.DOC_ID
else
//group by 
    PROD.GROUP_ID

Please help me with this I am new in crystal reports and I need to make this badly

I have this in my main report:

in the group header and it is group by {PROD.GROUP_ID}
Sub_Car
Sub_Airplane

Some of my sub reports are working when it is group by {PROD.GROUP_ID} and some sub reports works when this is group by {PROD.DOC_ID}

1

1 Answers

0
votes

you are trying to group the result of the grouping to regroup which is not possbile by the way you wrote the formula because DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO}) is itself the output of the grouping.

To achive this you need to use the sub report and pass the distinct count to use as grouping in sub report.

Take another section group footer b and place the sub report there and using Change sub report links pass the DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO}) to the sub report

in sub report it will be appearing in parameter fields as {?DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO})} now create your formula as @grouping and write below code:

if {?DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO})}=1 then
//group by
PROD.GROUP_ID
else if {?DistinctCount ({PROD.GROUP_ID}, {PROD.ID_NO})}>1 and 
   ({PROD.GROUP_ID}=previous({PROD.GROUP_ID}) or 
   {PROD.GROUP_ID}=next({PROD.GROUP_ID})) then
//group by PROD.DOC_ID
else
//group by PROD.GROUP_ID

Now use the formula to group the sub report... if you wish display data in main report or remove all fields of main report and just show sub report