Infinite
More left to learn.
- Local time
- Today, 01:13
- Joined
- Mar 16, 2015
- Messages
- 402
Hello! I have this query:
And I will explain what I want it to do, and upload a small database so you can see what it should do.
If you open the database, you will see the qryItemRetail. That is the main query for now. In it, you can see the rows. The row named "Work" Is what I want to work. If you look in the tblItemShowSales, you will see I have 8 Sales. That means, in all the query's, there should not be more then 8 records. Or so one would think. What I want is to get the Retail price of each item. In the qryItemsSold I have total sales of the items. And in qryAllItemsSold, I have the totals and the names sorted out to the correct items, so I only have there totals. The problem I am having is in qryItemRetail.
If a items sale falls between the start and end date in tblItemRetail, then that is what the Quantity sold should be multiplied by.
So, as you can see, I sold a total of 3 "22 Pistols" on 3/31/2012. If we look at the start and end dates in tblItemRetail, we see that falls between the 1st record. And that records price is $4. So the total retails for that should be $4*3. That would give us $12 for the 22 pistols retail for that show. The problem im having, is that as I have 2 records for the 22 Pistol, the qryItemRetail gives me 2 records. So even though I have a total of 8 sales the qryItemRetail gives me 12 records. The reason being its giving me a record for each item that falls between the dates. I have 3 records.
Its confusing me, and im not sure why its not working. Any help would be appreciated! Thanks!
Code:
Work: First(IIf([Date]>[RStartDate] And [Date]<[REndDate],[Price]*[Quantity],[RCost]*[Quantity]))
And I will explain what I want it to do, and upload a small database so you can see what it should do.
If you open the database, you will see the qryItemRetail. That is the main query for now. In it, you can see the rows. The row named "Work" Is what I want to work. If you look in the tblItemShowSales, you will see I have 8 Sales. That means, in all the query's, there should not be more then 8 records. Or so one would think. What I want is to get the Retail price of each item. In the qryItemsSold I have total sales of the items. And in qryAllItemsSold, I have the totals and the names sorted out to the correct items, so I only have there totals. The problem I am having is in qryItemRetail.
If a items sale falls between the start and end date in tblItemRetail, then that is what the Quantity sold should be multiplied by.
So, as you can see, I sold a total of 3 "22 Pistols" on 3/31/2012. If we look at the start and end dates in tblItemRetail, we see that falls between the 1st record. And that records price is $4. So the total retails for that should be $4*3. That would give us $12 for the 22 pistols retail for that show. The problem im having, is that as I have 2 records for the 22 Pistol, the qryItemRetail gives me 2 records. So even though I have a total of 8 sales the qryItemRetail gives me 12 records. The reason being its giving me a record for each item that falls between the dates. I have 3 records.
Its confusing me, and im not sure why its not working. Any help would be appreciated! Thanks!