Calculate total on a variable of type record filtered

andy76
Member Posts: 616
Hello,
I have a report based on a dataitem of type "Item".
In this report I set various variables and filters and at the end I have a variable of type record "Sales Invoice Line" filtered for various field dynamically setted.
I want to calculate some total as for example Quantity or Amount. How is that possible? "Sales Invoice Line" is not a dataitem but only a record variable.
Do I have to loop for each single line to add the values?
I am developing a very complex analysis report.
Thank you very much
I have a report based on a dataitem of type "Item".
In this report I set various variables and filters and at the end I have a variable of type record "Sales Invoice Line" filtered for various field dynamically setted.
I want to calculate some total as for example Quantity or Amount. How is that possible? "Sales Invoice Line" is not a dataitem but only a record variable.
Do I have to loop for each single line to add the values?
I am developing a very complex analysis report.
Thank you very much
0
Comments
-
Hi Andy,
have a look at the CALCSUMS function - it should solve a lot of your problems.0 -
I though the same thing but CALCSUMS is not for recalculate the field of a single record? not for a total of a range?#-o
Thanks0 -
Hi Andy,
I think you're mixing this up with CALCFIELDS which is for flowfields.
See the example in the helpExample
This example shows how to use the CALCSUMS function.
"Cust. Ledger Entry".SETCURRENTKEY("Customer No.","Date");
"Cust. Ledger Entry".SETRANGE("Customer No.", 'AAA 1050');
"Cust. Ledger Entry".SETRANGE("Date", 010196D, 123196D);
"Cust. Ledger Entry".CALCSUMS("Amount");
The first line selects a key. The second and third lines set filters for the fields Customer No. and Date in the Cust. Ledger Entry record so the total is only calculated within the specified range. The CALCSUMS function then finds the net change in account AAA 1050 for 1996. The Amount field will show the result of the calculation.0 -
Ok, so it is perfect... but can I sum everyfields? or only some types (as flowfield...)?
Thank you very much0 -
Hi Andy,
This command works with Sumindexfields which are setup on the keys tab on the table you are using.0 -
For example, I have to make sums on a variable record of table "Sales Invoice Line".
On this table the only SumIndex keys that I see under Key windows are : Amount,Amount Including VAT
1) Can't I use CALCSUMS for sum Quantity field?
2) do I have to use primary key "Document No.,Line No." or can I use a secondary key as "Type,No.,Sell-to Customer No." to be able to use CALCSUMS?
3) to get the value calculated in your previous example:
"
"Cust. Ledger Entry".SETCURRENTKEY("Customer No.","Date");
"Cust. Ledger Entry".SETRANGE("Customer No.", 'AAA 1050');
"Cust. Ledger Entry".SETRANGE("Date", 010196D, 123196D);
"Cust. Ledger Entry".CALCSUMS("Amount");
"
I have to read the value "Cust. Ledger Entry".Amount where there is the total ?
Thank you0 -
Hi Andy,
1) Yes you can use the Quantity field but you will have to add it to an index.
2) You can add the sumindexfield to any of the key - use the one which is best for you as this can have a performance implication (look at the sales line table 37 for an example)
3) The total is in the value of "Cust. Ledger Entry".Amount after the call to the command. If you are using the line values in a report then Currreport.CreateTotals is the way to go.
Hope this helps.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions