Search code examples
crystal-reports

Show Last Record only if Condition Met


My report needs to show the last record of a client only if certain conditions are met. But I also need to still show a client who hasn't met those conditions.

The report currently shows clients that have been coded with 303 (only the last time) and those that haven't. But those that aren't 303 shouldn't show anything.

Client    Date          Process Code  

4         4/1/2017      303        
4         5/1/2017      101       
4         6/1/2017      303         

6         4/1/2017      101
6         6/3/2017      101

7         5/15/2017     303
7         5/28/2017     101

What they want to see on the report is:

Client      Date           Process Code
4           6/1/2017       303
6    
7           5/15/2017      303

How can I achieve this?


Solution

    • Create a group for your client
    • Sort the records within that group by date descending (don't sort the group itself)
    • Print client details in detail block
    • Suppress details block if process code is not 303 or one detail row has already been printed

      • Add an additional Detail section after the existing one(s). Suppress it if you want to.
      • Place a formula @printed in the added Detail section, containing something like

        shared BooleanVar printed303; 
        if {Yourtable.ProcessCode = 303 then printed 303 := true;
        
      • Place another formula @reset in the group header containing something like

        shared BooleanVar printed303; 
        printed303 := false;
        
      • Add a Suppress Condition to your detail section containing somthing like

        shared BooleanVar printed303; 
        {Yourtable.ProcessCode <> 303  or printed303;
        

    That should do what you described.