Sum the Records based on Records from Another Table

mysamza
Member Posts: 66
So I am trying to sum the Base and Amount of VAT Entry Table.
But for only those records that have a particular Global Dimension.
So from the GL Entry Table I can get all the Document No. filtered on the Global Dimension 1 I want.
Then I want to filter the VAT Entry table with those Document No. found from GL Entry table and Sum their Base and Amount.
Here is what and not getting the expected result for the sake of this example we will call the Global Dimension 1 as 'AB'
On my report's (which has VAT Entry as its dataitem) onaftergetrecord()
GLEntry.SETFILTER("Global Dimension 1 Code", 'AB');
"VAT Entry".SETFILTER("Document No.", GLEntry."Document No.");
"VAT Entry".SETFILTER("Type", 'Sale');
"VAT Entry".SETFILTER("VAT Prod. Posting Group", '5% VAT');
IF "VAT Entry".FINDSET THEN BEGIN
REPEAT
TotalPS := TotalPS + "VAT Entry".Base;
TotalVATAmountPS := TotalVATAmountPS + "VAT Entry".Amount;
UNTIL "VAT Entry".NEXT=0;
END;
The result I get tells me GLEntry.SETFILTER("Global Dimension 1 Code", 'AB'); didn't work.
Any hint would be highly appreciated thanks in advance.
But for only those records that have a particular Global Dimension.
So from the GL Entry Table I can get all the Document No. filtered on the Global Dimension 1 I want.
Then I want to filter the VAT Entry table with those Document No. found from GL Entry table and Sum their Base and Amount.
Here is what and not getting the expected result for the sake of this example we will call the Global Dimension 1 as 'AB'
On my report's (which has VAT Entry as its dataitem) onaftergetrecord()
GLEntry.SETFILTER("Global Dimension 1 Code", 'AB');
"VAT Entry".SETFILTER("Document No.", GLEntry."Document No.");
"VAT Entry".SETFILTER("Type", 'Sale');
"VAT Entry".SETFILTER("VAT Prod. Posting Group", '5% VAT');
IF "VAT Entry".FINDSET THEN BEGIN
REPEAT
TotalPS := TotalPS + "VAT Entry".Base;
TotalVATAmountPS := TotalVATAmountPS + "VAT Entry".Amount;
UNTIL "VAT Entry".NEXT=0;
END;
The result I get tells me GLEntry.SETFILTER("Global Dimension 1 Code", 'AB'); didn't work.
Any hint would be highly appreciated thanks in advance.
0
Answers
-
You're applying the filter to the GLEntry variable but you're not doing anything with it...
You must add a dataItem for the G/L Entry table and set the filter on the OnPreDataItem trigger and then link the VAT Entry dataItem with "Document No." = "Document No." on the dataItem property DataItemLink.
You can also just have the G/L Entry dataItem and do the calculation with your code applying the same filters on the onaftergetrecord of the G/L Entry dataItem.
Be aware that the G/L Entry has many records with the same Document No. so you'll have to control this, since you don't want to calculate more than once the same document.
You also check the keys in the VAT Entry table and select or add a new key with document no. in which the SumIndexFields contain the Base and Amount fields and you won't have to the the iteration on that table. You'll just have to VATEntry.CALCSUMS(xxx, xxx);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