How to subtract current value from previous value in a column

annuvereannuvere Member Posts: 4
I have a column that i need to subtract a current value from the previous value and save the result on another column. The value is incrementing instead of decrementing.

Here is the image of what i want to achieve
mb3oq7g8l104.jpg

This is my code:
LastDailyReturn := 0;
TempFundPriceNew.RESET;
TempFundPriceNew.SETCURRENTKEY("Fund No.",Date);
TempFundPriceNew.SETRANGE(TempFundPriceNew."Fund No.","Temp Fund Price New"."Fund No.");
TempFundPriceNew.SETRANGE(TempFundPriceNew.Date,StartDate,"Temp Fund Price New".Date);
IF TempFundPriceNew.FINDFIRST THEN REPEAT
  LastDailyReturn += "Temp Fund Price New"."Bid Price LCY";
UNTIL TempFundPriceNew.NEXT = 0;

Answers

  • KTA8KTA8 MadridMember Posts: 347
    I don't know if I get what you want.


    DailyReturn:=0;
    TempFundPriceNew.RESET;
    //maybe some item range -> TempFundPriceNew.SETRANGE("Item No", SelectedItem);
    TempFundPriceNew.SETRANGE(TempFundPriceNew.Date, StartDate, EndDate);
    IF TempFundPriceNew.FINDSET THEN BEGIN
    REPEAT
    DailyReturn += "Temp Fund Price New"."Bid Price LCY";
    //would be better to create a function
    SetNewPrice.RESET;
    SetNewPrice.SETRANGE("Item No", SelectedItem);
    SetNewPrice.SETRANGE(SetNewPrice.Date,"Temp Fund Price New".Date);
    IF (SetNewPrice.FINDFIRST) THEN BEGIN
    SetNewPrice.DailyReturn:=DailyReturn;
    SetNewPrice.MODIFY();
    END;
    UNTIL TempFundPriceNew.NEXT = 0;
    END;
  • annuvereannuvere Member Posts: 4
    @KTA8 thank you so much, let me try it out now
  • krikikriki Member, Moderator Posts: 9,043
    [Topic moved from 'Navision Attain' forum to 'NAV/Navision Classic Client' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!

  • spidionespidione Member Posts: 3
    For the sake of sql, when use repeat always use FINDSET
    When you modify record just use FINDSET(true,false)
Sign In or Register to comment.