I have a GI that shows the Qty On Hand for each item by Warehouse. I want to get the total quantity on open Production orders at that warehouse for that item. What tables/DACs do I need to join to my GI to pull in those numbers?
Total open quantity on Production orders for an item by warehouse
Best answer by aryanjadhav50
I created a separate GI based on AMProdItem in order to summarize the total quantities by Warehouse and Item (see code below). Then I referenced that GI in my original one and did a LEFT join on InventoryID and SiteID.
Everything works fine, except for the items that have no matching record in the AMProdItem GI. Instead of showing a value of 0 or blank or null, it shows a value of 1.0.
I tried adding a formula like
=IsNull([PFTOpenProductionTotals.AMProdItem_qtyRemaining],0) but it gives me an error about using a virtual field in a conditional expression. How can I fix this?
FROM AMProdItem
WHERE AMProdItem.StatusID = 'R'
OR AMProdItem.StatusID = 'I'
GROUP BY
AMProdItem.SiteID,
AMProdItem.InventoryID
SELECT
AMProdItem.SiteID AS 'SiteID',
AMProdItem.InventoryID AS 'InventoryID',
SUM(AMProdItem.QtytoProd) AS 'QtyToProd',
SUM(AMProdItem.QtyComplete) AS 'QtyComplete',
SUM(AMProdItem.QtyRemaining) AS 'QtyRemaining'
The issue happens because you’re LEFT joining to a summarized GI. When no matching record exists, the grouped result can evaluate to 1 due to aggregation behavior.
You cannot use IsNull() because the field is already an aggregated (virtual) field.
Best solution (recommended):
Do not use a separate GI. In your main GI:
-
Add AMProdItem directly
-
LEFT join on InventoryID and SiteID
-
Add condition: AMProdItem.StatusID IN ('R','I')
-
Create calculated field:
AMProdItem.QtytoProd - AMProdItem.QtyComplete -
Set Aggregate = Sum
-
Group by InventoryID and SiteID
This avoids nested aggregation and will correctly return 0 when no production orders exist.
Hope this works for you.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.