How to do a Sum total without using the FlowField

i_musaliyui_musaliyu Member Posts: 5
edited 2019-03-29 in NAV Three Tier
I have a page and table with various data, i want to sum up the data in each fields in the line and show in the page total i created without using the flowfield but a CODE unit. Can anyone assist or give me a walk through.

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2019-03-30
    if your field to be summed up is of decimal type, and if you can use filters to isolate/select a set of records to be summarised, use CALCSUM
    SomeRec.SETRANGE("Field 1", 'smth');
    SomeRec.SETRANGE("Field 2", 'smth');
    SomeRec.SETRANGE("Field 3", 'smth3', 'smth4');
    SomeRec.CALCSUM("A decimal field to be summarised");
    

    If your field is of the integer type, or the subset of records cannot be expressed in terms of NAV filters then you need to loop through records and add them up manually.
    SomeRec.SETRANGE("Field 1", 'smth');
    SomeRec.SETRANGE("Field 2", 'smth');
    SomeRec.SETRANGE("Field 3", 'smth3', 'smth4');
    IF SomeRec.FINDSET THEN 
    REPEAT
      IF someComplicatedContition = TRUE THEN
         Total += "A field to be summarised";
    UNTIL SomeRec.NEXT = 0;
    

    Then you need to assign calculated value to a global variable, and put a field on a Page with SourceExpr property set to this global variable
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • RockWithNAVRockWithNAV Member Posts: 1,139
    You simply need to convert then Flowfields intio a loop code if its for sum. It depends exactly which Flowfield you want to convert?
  • krikikriki Member, Moderator Posts: 9,115
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]

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


Sign In or Register to comment.