Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2014
    Posts
    4

    Unanswered: Getting the last record from detail section in header section

    Hi everyone!, I'm a bit new to Crystal Reports and having a big problem (at least big for me)...I need to get a last record field from the detail section and show it in the header section. I'm using the following two simple formulas:

    //------------------------------------------------------
    Header section:

    //Formula1 (just for showing the variable got from Formula2)
    whileprintingrecords;
    shared numbervar Saldo;

    //------------------------------------------------------
    Detail section:

    //Formula2
    whileprintingrecords;
    shared numbervar Saldo;
    if onlastrecord = true then Saldo:={spKardex_CodZOFRI.amount};

    //------------------------------------------------------

    Ex. for a 4 records dataset:
    1- 255
    2- 122
    3- 69
    4- 56

    I'm always getting the first amount (in this case 255) but I need the last one (56) on my header section.

    What am I doing wrong??? thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You're not doing anything wrong - it's a shortcoming of Crystal that you are battling.

    Basically, CR cannot determine the "last" record in a section until it has printed it, and by that point it is too late to show it in the section header!

    The workarounds include:
    a) "Sod it, I'll put it in the section footer"
    and
    b) "I'll have to add another (or modify the) data source on my report to provide this value for me"


    Sorry dude
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2014
    Posts
    4

    Thumbs up

    Got it! thanks anyway George.

    Regards,
    Patrick

  4. #4
    Join Date
    Dec 2014
    Posts
    4

    Lightbulb I've got the solution!

    It's me again. Finally, I've got the solution, It's quite simple, just use the function Minimum({Field}) in the header section, in my case Minimum({spKardex_CodigoZOFRI.amount}), that's it!!

    Regards!
    Patrick

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hi Patrick, that's great, as long as you realise that Minimum() returns the "lowest" value, not necessarily the "last".

    Using your example dataset with a slight tweak:
    A - B
    ------
    1- 255
    2- 122
    3- 69
    4- 56
    5 - 937

    Given this data, sorted by A, the "last" value of B is 937. However, the Minimum() value of B is 56.

    Does that make sense?
    George
    Home | Blog

  6. #6
    Join Date
    Dec 2014
    Posts
    4

    Thumbs up

    Hi George!, you are totally right!, it's a detail that I did't include in my initial question. The last record that I want to get will always be the lowest amount.

    Thanks for your help!

    Best regards!
    Patrick

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •