Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10

    Using DSUM resetting upon next ID in dataset

    You can see below my very simplified example. I want RunTot to sum until a new ITEM is reached, then reset.
    Ideally,




    But here is my output:


    Here is my code in Query Design:
    RunTot: DSum("QTY","TABLE1","ITEM=[ITEM]")
    I'm aware the last part is where I'm wrong.. help please?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Is there a reason you're doing this in a query instead of as a running sum on a report? Using Domain functions in queries is extremely memory intensive and will bloat your database very quickly.

    RunTot: DSum("QTY","TABLE1","ITEM= " & [ITEM])

    if ITEM is a number (autonumber field)

    RunTot: DSum("QTY","TABLE1","ITEM= '" & [ITEM] & "'")

    NOTE: this will not work because there is no way to identify a differentiation between ITEM1 records, if you had a date in there and there was no possibility that the same item had the same date you could use:

    RunTot: DSum("QTY","TABLE1","ITEM= '" & [ITEM] & "' AND [SaleDate] <= #" & [SaleDate] &"#")

    if ITEM is a text field (description)

    I'd really strongly suggest you try to do running sums in reports only, trying to do them in queries is really a bad practice. I'll explain why. Every time you use a domain function it is processing your ENTIRE data set. So let's just take this query for example. You have 8 records, what your query is actually doing is individually processing each record of those 8 records for every line in your query. So you're not actually running 1 query, you're running 9, the main query and a separate query for each domain function. You can see how this would quickly get out of hand for larger data sets. Let's say this is just a total for january, now it's december and we'll assume for the sake of simplicity you've had 8 records every month for the whole year, your domain function will now be processing 96 lines of data for each line of your december data and it will be doing that 8 times for each domain function.


  3. #3
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    The ultimate goal is to compare available inventory vs. customer orders and to signal which order we run out by, and yes they are in date order.

    Example: 6 pcs available, customer orders for 1,3,2,5. My goal is to show that we are 'covered' for the first 3 orders as 6 pcs are available for 6 needed. Then to show the final order for 5 as NOT AVAILABLE.

    I've taught myself my way through Access so I am sure I have some bad practices..

    Thank you for the response, I'll give your date suggestion a go and come back here with results.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can do that without using domain functions.

  5. #5
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    Sorry, I'm not sure I follow. Can you expand on your suggested method? I'm OK using Excel for as much as possible, to simplify for other users too.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    How are you keeping track of your receipts vs your expenditures? Are they in separate tables?

    In other words how do you know how much you have on hand. I am assuming this is some sort of inventory control database where you're recording incoming and outgoing materials and hopefully coming up with an on hand quantity and what you're trying to figure out is some sort of projection report?

  7. #7
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    Essentially it's an order backlog table from excel I'm importing into access, including all orders with their due dates, on hand quantity, etc.

    With this, sorted by oldest due date, I want to filter my list to orders that we do not have available inventory. It narrows the focus for the operations team.

    I have a stagnant field that shows qty on hand when the report is run.

    My thought was if I could create a running total of open qty and sort by oldest order, I can compare to on hand Qty and only show the orders that exceed available qty.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I am not following your description of how your data is set up. How are you getting your 'on hand' quantity if you're not storing receipts as well as disbursements of inventory? Are you saying on every order you are also have a field that is quantity on hand after the items are removed? what do you mean by 'I have a stagnant field that shows qty on hand when the report is run' I don't follow that bit at all.

    Any chance you can provide a sample of your database.

  9. #9
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    The report is created each day from our ERP system and dumped into Excel. On Hand Qty is from the snapshot in time when the report is run. In the example below, we have 6 on hand of ITEM1, but orders that total 19 for this item. I eventually would compare the running total to see what day we are unable to support the order. In this example, We have enough (6) to support the first 3 orders, before being out of inventory.

    The RunTot column is my goal so that I can use the available column to see where we are short.

    Click image for larger version. 

Name:	Capture 3.PNG 
Views:	15 
Size:	16.2 KB 
ID:	15011

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Which of these fields come from the ERP report other than the item and the on hand qty?

    I suppose before I get on my high horse about not using domain functions I should ask, I have assumed to this point that you want to print out a report... but that may not be accurate are you trying to put this information on a form? Or are you required to leave it in a query?

    Here's an example file putting the information on a report.

    ellisjo3.zip

  11. #11
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    Every field comes from the ERP report, and I would calculate 'remaining' such as what you did.

    I would actually need it in a query so that I can export to Excel and add things such as comments from different people and sort different ways for different use.

    That looks so simple with a report though =/

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Every field can't be coming from the export or we wouldn't be having this conversation

    Are you saying every field except runtot and available? come from the ERP side?

    Is there a reason you can't do all your 'add things such as comments from different people and sort different ways for different use' from access directly and use the access side as a general lookup database for your users? Seems like an awful waste of time to import a spreadsheet into access, maniuplate it then re-export it to access. It might just be easier to manipulate the original text field to add the two fields (runtot and available) via VBA than importing/re-exporting the whole thing.

  13. #13
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    Yes everything except Runtot and Available.

    I'm with you on the VBA part, that's what I meant to ask originally, but probably failed to explain clearly.

    I get the report (minus runtot and available) in Excel. I was importing to Access to do a lot of filtering based on the next 7 days of orders, excluding orders that are on a HOLD, excluding certain types of ITEMS, etc.
    The ideal step for me is to include runtot and available in another Query design, with a step that looks like what you created in the Report. With this runtot and available, I can filter out what is covered, and only display the orders that are not fulfilled.

    I apologize for any confusion, but the VBA code (DSUM from what I read) is what would be best for me at this time. I struggled with how to create a 'runtot' field that reset when it reached a new ITEM.

    IF we can create runtot in a query design, my problem is solved.

  14. #14
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I'm using VBA differently than you are, Domain functions are not VBA, the are part of a 'default' set of code that allow you to perform specific functions.

    when I talk about VBA I mean that you process your text file without importing it at all but it doesn't seem you want to do that either.

    I am trying desperately to dissuade you from using a domain function in a query because they are so hard on memory and bloat your database but you can do it using a formula like this:

    (This assumes that you are sorting your data FIRST by item, SECOND by date, THIRD by order number)

    RUNTOT: Dsum("[Order Qty]", "Table1", "[ITEM] = '" & [ITEM] & "' AND [DUE] <= #" & [DUE] & "# AND [ORDER] <= '" & [ORDER] "'")

    this assumes order and item are both text fields.

    Just remember I warned you. DSUM is going to affect both your runtot and remaining columns in effect you are going to be processing the number of records in your TABLE1 2x for every record of your report so if you have 2000 records in your table 1, even if only 10 of them are showing you are processing, in effect, 40,000 records just to create this query.

  15. #15
    ellisjo3 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    10
    I know I know I know. The novice description under my account name is pretty accurate of my level of experience.

    You have been extremely helpful. The only missing piece now.. If the Order # for a LATER date is less, it restarts.. see below.
    Instead of 2, it needs to show 5.
    I am sure this tweak is minor to the code, but I am really struggling.

    Click image for larger version. 

Name:	Capture 4.PNG 
Views:	14 
Size:	3.4 KB 
ID:	15030

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. track updates in a dataset
    By sssandhya89 in forum Access
    Replies: 1
    Last Post: 03-21-2013, 11:13 AM
  2. Replies: 1
    Last Post: 03-17-2013, 01:37 PM
  3. How to run macro on filtered dataset
    By FredLanger in forum Forms
    Replies: 7
    Last Post: 04-02-2012, 12:27 PM
  4. Dataset returning different results
    By Juan23 in forum Programming
    Replies: 8
    Last Post: 09-16-2011, 03:03 PM
  5. Help filtering a dirty dataset
    By za20001 in forum Queries
    Replies: 0
    Last Post: 04-16-2011, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums