Print Page | Close Window

Selecting the last record in a group

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=19103
Printed Date: 03 May 2024 at 5:05pm


Topic: Selecting the last record in a group
Posted By: adavis
Subject: Selecting the last record in a group
Date Posted: 13 Feb 2013 at 9:35am
Is there a way to select (or at least only show) the last sequential record for a group?

For example I have a report that more or less looks like this

Group level 1
    Group level 2
          Record 1
          Record 2
          Record 3
          Record 4


I only want Record 4 to show in the Details section.

Any advice would be greatly appreciated.



Replies:
Posted By: adavis
Date Posted: 13 Feb 2013 at 9:43am
To make this slightly more complicated. I also need to be able to add a Sum to the report footer for two different fields associated to the last record in each group. I figure I will deal with that once I get past this first hurdle though!


Posted By: adavis
Date Posted: 13 Feb 2013 at 10:07am
Okay I am a space monkey. I figured out how to show only the last record. I just sorted descending and then placed the field in the group header. Haha. So simple. Anyway... any idea on how to sum only the visible fields?


Posted By: DBlank
Date Posted: 13 Feb 2013 at 10:08am
display is simple, just drop the fields onto the group footer
summing is more complicated.
You could use shared variables with next() functions possibly.


Posted By: adavis
Date Posted: 13 Feb 2013 at 10:42am
Summing certainly is complicated. I thought maybe I could do something with TopN where N=1, but I'm not getting anywhere with that.
Don't you have to declare the variable for shared variables? Would that work where X would be whatever value is stored in the record.

Thanks for the reply DBlank. It is getting late in the day. I will have to try again tomorrow with fresh eyes.


Posted By: DBlank
Date Posted: 13 Feb 2013 at 11:02am
since you reversed your sort it should be pretty easy.
Right click on Running Totals
select new
name=whatever
field to summarize=whatever field you want to sum
type=sum
evaluate=on chaneg of group (pick group1)
reset=never if you want a report total
place in the report footer (RTs do ot work in headers)
 


Posted By: adavis
Date Posted: 14 Feb 2013 at 8:29am
As usual, your advice is perfect.

I am getting better at CR everyday and I am just amazed at how friendly and helpful everyone on this forum is. I really appreciate it!




Print Page | Close Window