Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula doesn't calculate last record using next/nextisnull 1

Status
Not open for further replies.
Joined
Sep 8, 2005
Messages
54
Location
US
Using Crystal 10 connecting to MS SQL via ODBC.

The following formula doesn't calculate for the last record. If I use previous, it doesn't calculate the first record. It just leaves a blank field. Any idea why the NextIsNull isn't working as expected?

thanks,
damon


if {CommOut.contact_id} = next({CommOut.contact_id})
and {CommOut.person_id} = next({CommOut.person_id})
and {CommOut.org2_name} = next({CommOut.org2_name})
then 0

else if NextIsNull({CommOut.contact_id})
then {CommOut.duration}

else {CommOut.duration}
 
Looks like part of the formula is redundant.

if onlastrecord then
"blah"
else
if
{CommOut.contact_id} = next({CommOut.contact_id})
and {CommOut.person_id} = next({CommOut.person_id})
and {CommOut.org2_name} = next({CommOut.org2_name})
then
0
else
{CommOut.duration}

Wasn't sure what your intent was, but try using onlastrecord.

-k
 
Just using next or previous left of the last or first record. Thanks for the heads up on 'onlastrecord' I ended up using the following:

if not onlastrecord
then
(if {CommOut.contact_id} = next({CommOut.contact_id})
and {CommOut.person_id} = next({CommOut.person_id})
and {CommOut.org2_name} = next({CommOut.org2_name})
then 0
else {CommOut.duration}
)

else
(if {CommOut.contact_id} = previous({CommOut.contact_id})
and {CommOut.person_id} = previous({CommOut.person_id})
and {CommOut.org2_name} = previous({CommOut.org2_name})
then 0
else {CommOut.duration}
)
 
Now that I'm thinking more about it, if the last two records match up, they will both come back as 0 (zero). This is ok if third to last matches, but not ok if it doesn't.

Why doesn't this work?
if {CommOut.contact_id} = next({CommOut.contact_id})
and {CommOut.person_id} = next({CommOut.person_id})
and {CommOut.org2_name} = next({CommOut.org2_name})
then 0
else {CommOut.duration}
 
Group by the 3 fields, and place all of your fields in the group header and suppress the details.

You'll get one row for each.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top