Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37

    cumulative sum by date&time

    Hello everyone,


    I stucked on a problem in my next project and I would like to ask you for help...
    I need to make cumulative sum query to make diagram of "fail rate" in time.


    Following table is a result of my first querry which is filtering "ComponentName" from all entries and sorting data by "ProductionDate":
    ProductionDate ComponentName Picks Placements MachineName
    4. 11. 2013 12:45:05 026/000 23 22 HSC
    4. 11. 2013 13:00:02 026/000 18 18 HSC
    4. 11. 2013 13:15:02 026/000 26 26 HSC
    4. 11. 2013 13:30:03 026/000 18 18 HSC
    4. 11. 2013 13:45:02 026/000 6 6 HSC
    4. 11. 2013 14:00:02 026/000 12 12 HSC
    4. 11. 2013 14:15:03 026/000 6 6 HSC
    4. 11. 2013 14:30:03 026/000 52 52 HSC
    4. 11. 2013 14:45:03 026/000 38 38 HSC
    4. 11. 2013 14:58:02 026/000 36 36 HSC
    4. 11. 2013 14:59:02 026/000 6 6 HSC
    4. 11. 2013 15:15:03 026/000 18 18 HSC
    4. 11. 2013 15:30:03 026/000 42 42 HSC
    4. 11. 2013 15:45:03 026/000 30 30 HSC


    Now I need to add three new columns which should contain cumulative sum of "Picks" and "Placements". Last column will be used to count fail rate.
    I know I have to use DSum function to make cumulative sum, but I have problems with condition of cumulative sum...

    Code:
    CumSumPicks: DSum("Picks";"dbo_PickPlaceEntry";"[ProductionDate]<="???????????)
    Can you advice please?

    Thank you very much.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Use the form syntax, but just use the field name in place of the form reference:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Assuming this table layout
    Code:
    tblPickPlace
      ProdDate     Date
      CompName     Text
      MachName     Text
      Picks        Number
      Places       Number
    This query gives you cumulative picks and places
    Code:
    SELECT 
      T1.ProdDate,
      T1.CompName,
      T1.MachName,
      First(T1.Picks) As Picks,
      First(T1.Places) As Places,
      Sum(T2.Picks) AS CumPicks,
      Sum(T2.Places) AS CumPlaces  
    FROM
       tblPickPlace AS T1 
       INNER JOIN
       tblPickPlace AS T2
       ON T1.CompName = T2.CompName
       AND T1.MachName = T2.MachName
    WHERE
       T2.ProdDate <= T1.ProdDate
    GROUP BY 
      T1.ProdDate,
      T1.CompName,
      T1.MachName;
    But I don't know where you're getting fail rate, unless it's the difference between picks and places.
    FYI - I made the assumption that you want to compare fails only against work done on the same machine.

  4. #4
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Quote Originally Posted by pbaldy View Post
    Use the form syntax, but just use the field name in place of the form reference:

    DLookup Usage Samples
    Thank you for answer, I tried all of this syntax and none of this is working
    Can you advice me what exact condition should be there? I am not sure ProductionDate <= ProductionDate condition is OK

  5. #5
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Quote Originally Posted by Dal Jeanis View Post
    Assuming this table layout
    Code:
    tblPickPlace
      ProdDate     Date
      CompName     Text
      MachName     Text
      Picks        Number
      Places       Number
    This query gives you cumulative picks and places
    Code:
    SELECT 
      T1.ProdDate,
      T1.CompName,
      T1.MachName,
      First(T1.Picks) As Picks,
      First(T1.Places) As Places,
      Sum(T2.Picks) AS CumPicks,
      Sum(T2.Places) AS CumPlaces  
    FROM
       tblPickPlace AS T1 
       INNER JOIN
       tblPickPlace AS T2
       ON T1.CompName = T2.CompName
       AND T1.MachName = T2.MachName
    WHERE
       T2.ProdDate <= T1.ProdDate
    GROUP BY 
      T1.ProdDate,
      T1.CompName,
      T1.MachName;
    But I don't know where you're getting fail rate, unless it's the difference between picks and places.
    FYI - I made the assumption that you want to compare fails only against work done on the same machine.

    Fail rate will be calculated like (Picked-placed)/(picked)
    And also in a reference control there are machine choosed by user...
    Unfortunatelly your query is not working on my database

    I have modified names, because you changed some of them, but it is not working... Access is calling many errors.
    Any thoughts?

  6. #6
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Post the names of your tables and fields, please.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    "ProductionDate <= #" & ProductionDate & "#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Quote Originally Posted by pbaldy View Post
    "ProductionDate <= #" & ProductionDate & "#"

    Code:
    CumSum: DSum("Picks";"dbo_PickPlaceEntries";"ProductionDate <= #" & [ProductionDate] & "#")
    This is not working. As a result there is a field "CumSum" and every value is #error

  9. #9
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Quote Originally Posted by Dal Jeanis View Post
    Post the names of your tables and fields, please.
    Original tables are:

    dbo_PickPlaceEntries:
    ID - automatic number
    MachineID - number (foreign key to dbo_Machines)
    ComponentRID - number (foreign key to dbo_Components)
    ProductionDate - date&time
    Picks - number
    Placements - number

    dbo_Components:
    ID - automatic number
    ComponentName - text


    dbo_Machines:
    ID - automatic number
    MachineName - text


    In a form I am using text boxes to define dates as a criterium for ProductionDate (first and last day), ComponentName and MachineName.

  10. #10
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Try This:
    Code:
    SELECT 
      TC.ComponentName,
      TM.MachineName,
      T1.ProductionDate,
      First(T1.Picks) As Picks,
      First(T1.Placements) As Places,
      Sum(T2.Picks) AS CumPicks,
      Sum(T2.Placements) AS CumPlaces,
      (Sum(T2.Picks) -  Sum(T2.Placements))/Sum(T2.Picks) AS CumFail
    FROM
       ((dbo_PickPlaceEntry AS T1 
        INNER JOIN
        dbo_PickPlaceEntry AS T2
        ON T1.ComponentRID = T2.ComponentRID
        AND T1.MachineID = T2.MachineID)
          INNER JOIN dbo_Components AS TC
          ON TC.ID = T1.ComponentRID)
            INNER JOIN dbo_Machines AS TM
            ON TM.ID = T1.MachineID
    WHERE
       T2.ProductionDate <= T1.ProductionDate
    GROUP BY 
      TC.ComponentName,
      TM.MachineName,
      T1.ProductionDate;
    If that works, you can add another test to the WHERE clause to limit the results to the desired ComponentName or ComponentID and MachineName or
    MachineID.
    Code:
    WHERE T2.ProductionDate <= T1.ProductionDate
    AND TC.ComponentName = Forms!MyForm!MyComponentControl
    AND TC.MachineName = Forms!MyForm!MyMachineControl

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    I had to upload DB to free storage, because file uploading on this site is not working to me

    Code:
    http://ulozto.net/xtNEYNPD/temp-accdb
    I deleted from DB many datas to reduce it.
    There is only one querry, where I need to make cumulative sum...

    Thank you once more.

    Edit:
    I´ve just find out, why I am not able to upload DB on site... My DB is too large :-D

  13. #13
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Have you tried the code in post #10?

  14. #14
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Quote Originally Posted by Dal Jeanis View Post
    Have you tried the code in post #10?
    Of course I did, but Access is still asking me about parametr entry (TC.ComponentName and other...)
    You can download piece of db and try your querry if you want.

  15. #15
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    I assumed it was dbo_components with an underscore. Is that a space between dbo and components? If not, I'll have to try downloading at home tomight.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-06-2013, 02:32 PM
  2. Breaking out the time from date/time
    By detaylor1242 in forum Programming
    Replies: 1
    Last Post: 02-19-2013, 08:10 PM
  3. Getting Just the Date part of Date/Time field
    By GaryElwood in forum Reports
    Replies: 7
    Last Post: 09-28-2011, 09:58 AM
  4. Replies: 12
    Last Post: 02-22-2011, 03:39 PM
  5. Replies: 6
    Last Post: 01-04-2011, 05:43 PM

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