Problem grouping SUMS using Queries

attieffe
Member Posts: 3
Problem with Nav C/AL Queries
Hello,
i'm using NAV 2017 and i attempt to the the following (the real case is more complex but i just ask for a specific function):
I have a table Items and i want to use a Query that give me bak ONE record for ITEM, with some static field and some computed fields:
- purchased quantity (sum of quantity from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
- purchased value (sum of COST AMOUNT from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
- sale quantity (sum of quantity from Item Ledger Entry with TYPE SALE, in a specific period and location filters)
- sale value (using the purchase value not the sell one) (sum of COST AMOUNT from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
So i setup a Query with 3 level:
level 1: ITEM
level 2: ILE_BUY linked by fields on ITEM table, datefilter, location filter, Types Purchase/Transfer
level 3: ILE_SALE linked by fields on ITEM table, datefilter, location filter, Type Sale
Now the problem:
There is one record on table ITEM,
ONE record of Purchase TYPE and quantity 2
TWO record of Sale type with quantity -1 / -1
Running the query i found:
Purchase quantity amount => 4 (2 expected)
Sale quantity amount => -2
So the problem is that it brings those 2 PURCHASED quantity on EACH SALE record, so it SUMS 2 times 2 quantity.
I tried moving both Item ledger entry at the same LEVEL it says me that is not possible.
If I remove all the SALE part on the design the Purchase quantity is correct => 2
I post an image of my current setup.


All relations between tables have DataItemLinkType Exclude Row If No Match (i tried also other values but the results is still the same).
Thank you
Attilio
Hello,
i'm using NAV 2017 and i attempt to the the following (the real case is more complex but i just ask for a specific function):
I have a table Items and i want to use a Query that give me bak ONE record for ITEM, with some static field and some computed fields:
- purchased quantity (sum of quantity from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
- purchased value (sum of COST AMOUNT from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
- sale quantity (sum of quantity from Item Ledger Entry with TYPE SALE, in a specific period and location filters)
- sale value (using the purchase value not the sell one) (sum of COST AMOUNT from Item Ledger Entry with TYPE PURCHASE OR TRANSFER, in a specific period and location filters)
So i setup a Query with 3 level:
level 1: ITEM
level 2: ILE_BUY linked by fields on ITEM table, datefilter, location filter, Types Purchase/Transfer
level 3: ILE_SALE linked by fields on ITEM table, datefilter, location filter, Type Sale
Now the problem:
There is one record on table ITEM,
ONE record of Purchase TYPE and quantity 2
TWO record of Sale type with quantity -1 / -1
Running the query i found:
Purchase quantity amount => 4 (2 expected)
Sale quantity amount => -2
So the problem is that it brings those 2 PURCHASED quantity on EACH SALE record, so it SUMS 2 times 2 quantity.
I tried moving both Item ledger entry at the same LEVEL it says me that is not possible.
If I remove all the SALE part on the design the Purchase quantity is correct => 2
I post an image of my current setup.


All relations between tables have DataItemLinkType Exclude Row If No Match (i tried also other values but the results is still the same).
Thank you
Attilio
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