Options

add two values from the same field from same table

ha101ha101 Member Posts: 4
Hi i am new to navision. I have a problem. I have to add two values from the same field from the same table which has lots of data. They have the same document no. and supplier no. .
For e.g

Docu no. supplier no. value
34652 234 15
34652 234 0.01

How do i filter the two values' document and supplier no. out so that I can add them together. Please advice.

Comments

  • Options
    annivasuannivasu Member Posts: 10
    Hi Ha101,
    Please put following formula.

    value :='34652 234 15';
    FirstValue := COPYSTR(value,1,5);
    secondvalue := copystr(value,7,3);
    message('First Value=%1 Second Value =%2',firstvalue,secondvalue);

    Hope this will help you :)
  • Options
    MBergerMBerger Member Posts: 413
    If i am correct, ha101 wants to see the total value of all lines with document no = 34652 and supplier no = 234.
    That can be done by making a flowfield to the table itself, just calculate the sum of the field "value" of all lines with the same document no. and supplier no.
  • Options
    DakkonDakkon Member Posts: 192
    If you want to get two distinct records and add them, you could Fetch each record using its primary key fields and the Record.GET() function, then value field from each record to a variable. If you simply want to sum the value field for all records with the same "Document No." and "Supplier No." then you could use some code like the following:

    Assume you have a Record variable called MyRec that relates to your data table, as well as a decimal variable called MySum.
    MyRec.SETRANGE("Document No.", '34652');
    MyRec.SETRANGE("Supplier No.", '234');
    MyRec.CALCSUMS(Value);
    MySum := MyRec.Value;
    

    Now of course this is simple sample code. You would want to use SETCURRENTKEY to select a better key for the record if the primary key doesn't include those two fields and you would never want to hardcode your filter criteria into the code in real use. I hope this helps, without more specific information it is hard for me to give a more targeted example.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
Sign In or Register to comment.