Hello,
I am having some trouble using a calculated field to accurately determine the amount on hand. I have a UNION query which joins two queries.
The first query uses the amount of stock of an item joined with the items that have been checked out. I use these numbers to calculate the amount on hand.
SELECT [AcqDetailQuery].SumOfstockQuantity, (([AcqDetailQuery].[SumOfstockQuantity])+([Expr1])) AS AOH, IIf([PurchaseType].[purchasetypeID]<=3,[CheckedOutQry]![qtycheckedOut]*-1,([CheckedOutQry]![qtycheckedOut])) AS Expr1, CheckedOutQry.productID, CheckedOutQry.qtycheckedout, PurchaseType.purchasetypeID
FROM AcqDetailQuery INNER JOIN (PurchaseType INNER JOIN CheckedOutQry ON PurchaseType.purchasetypeID = CheckedOutQry.purchasetypeID) ON [AcqDetailQuery].productID = CheckedOutQry.productID
GROUP BY [AcqDetailQuery].SumOfstockQuantity, CheckedOutQry.productID, CheckedOutQry.qtycheckedout, PurchaseType.purchasetypeID;
the second query uses the amount of stock of an item joined with the items that have been checked in. I use these numbers to calculate the amount on hand.
SELECT [AcqDetailQuery].SumOfstockQuantity, (([AcqDetailQuery].[SumOfstockQuantity])+([Expr1])) AS AOH, IIf([PurchaseType].[purchasetypeID]<=3,[CheckInQry]![qtycheckedIn]*-1,([CheckInQry]![qtycheckedIn])) AS Expr1, PurchaseType.purchasetypeID, CheckInQry.productID, CheckInQry.qtycheckedin
FROM (PurchaseType INNER JOIN CheckInQry ON PurchaseType.purchasetypeID = CheckInQry.purchasetypeID) INNER JOIN AcqDetailQuery ON CheckInQry.productID = [AcqDetailQuery].productID
GROUP BY [AcqDetailQuery].SumOfstockQuantity, PurchaseType.purchasetypeID, CheckInQry.productID, CheckInQry.qtycheckedin;
After I union these queries, this is my result:
Query3
productID/ SumOfstockQuantity/ AOH/ Expr1/ qtycheckedout/ purchasetypeID/
321/ 10/ 8/ -2/ 2 1/
321/ 10/ 8/ -2/ 2/ 2/
96/ 8/ 7/ -1/ 1/ 2/
96/ 8/ 6/ -2/ 2/ 3/
385/ 4/ 3/ -1/ 1/ 3/
96/ 8/ 9/ 1/ 1/ 4/
88/ 7/ 8/ 1/ 1/ 4/
As you can see, the AOH is incorrect. Beyond the first instance of the item being checked out, the AOH is calculated based on the initial amount of stock. I would like for it to subtract from the sumof stock first, and beyond that, add or subtract from the current AOH. Is there anyway to accomplish this?
Thank you in Advance for you assistance
I am having some trouble using a calculated field to accurately determine the amount on hand. I have a UNION query which joins two queries.
The first query uses the amount of stock of an item joined with the items that have been checked out. I use these numbers to calculate the amount on hand.
SELECT [AcqDetailQuery].SumOfstockQuantity, (([AcqDetailQuery].[SumOfstockQuantity])+([Expr1])) AS AOH, IIf([PurchaseType].[purchasetypeID]<=3,[CheckedOutQry]![qtycheckedOut]*-1,([CheckedOutQry]![qtycheckedOut])) AS Expr1, CheckedOutQry.productID, CheckedOutQry.qtycheckedout, PurchaseType.purchasetypeID
FROM AcqDetailQuery INNER JOIN (PurchaseType INNER JOIN CheckedOutQry ON PurchaseType.purchasetypeID = CheckedOutQry.purchasetypeID) ON [AcqDetailQuery].productID = CheckedOutQry.productID
GROUP BY [AcqDetailQuery].SumOfstockQuantity, CheckedOutQry.productID, CheckedOutQry.qtycheckedout, PurchaseType.purchasetypeID;
the second query uses the amount of stock of an item joined with the items that have been checked in. I use these numbers to calculate the amount on hand.
SELECT [AcqDetailQuery].SumOfstockQuantity, (([AcqDetailQuery].[SumOfstockQuantity])+([Expr1])) AS AOH, IIf([PurchaseType].[purchasetypeID]<=3,[CheckInQry]![qtycheckedIn]*-1,([CheckInQry]![qtycheckedIn])) AS Expr1, PurchaseType.purchasetypeID, CheckInQry.productID, CheckInQry.qtycheckedin
FROM (PurchaseType INNER JOIN CheckInQry ON PurchaseType.purchasetypeID = CheckInQry.purchasetypeID) INNER JOIN AcqDetailQuery ON CheckInQry.productID = [AcqDetailQuery].productID
GROUP BY [AcqDetailQuery].SumOfstockQuantity, PurchaseType.purchasetypeID, CheckInQry.productID, CheckInQry.qtycheckedin;
After I union these queries, this is my result:
Query3
productID/ SumOfstockQuantity/ AOH/ Expr1/ qtycheckedout/ purchasetypeID/
321/ 10/ 8/ -2/ 2 1/
321/ 10/ 8/ -2/ 2/ 2/
96/ 8/ 7/ -1/ 1/ 2/
96/ 8/ 6/ -2/ 2/ 3/
385/ 4/ 3/ -1/ 1/ 3/
96/ 8/ 9/ 1/ 1/ 4/
88/ 7/ 8/ 1/ 1/ 4/
As you can see, the AOH is incorrect. Beyond the first instance of the item being checked out, the AOH is calculated based on the initial amount of stock. I would like for it to subtract from the sumof stock first, and beyond that, add or subtract from the current AOH. Is there anyway to accomplish this?
Thank you in Advance for you assistance