Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49

    Can you calculate energy consumption in an Access Query?

    Hello,

    I like to know there is a solution to calculate energie consumption in an Access Query?

    Click image for larger version. 

Name:	Meter-PositionsT 002.png 
Views:	33 
Size:	90.8 KB 
ID:	51230

    Click image for larger version. 

Name:	Can you calculate energy consumption in an Access Query.png 
Views:	35 
Size:	99.8 KB 
ID:	51229

    Regards


    Jaap
    Attached Thumbnails Attached Thumbnails Meter-PositionsT.png  
    Last edited by Jaap; 12-19-2023 at 02:03 PM. Reason: Wrong screenshot :-(

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    See if this is what you need (example is actually based on meter readings).
    http://allenbrowne.com/subquery-01.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Quote Originally Posted by Micron View Post
    See if this is what you need (example is actually based on meter readings).
    http://allenbrowne.com/subquery-01.html
    Thanks for the example you sended me.

    This example is to difficult for me, I was hoping something to do in an Query with: Totals, Min and Max.

    Jaap

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I suggest you post a copy of your database in order for someone to review your code or set up a query(ies) to illustrate the approach with your data.
    The example micron pointed you to is all about difference in meter readings -study the example carefully. It definitely applies to your issue.

    Break your requirement into steps.
    Post your sql.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Jaap View Post
    Thanks for the example you sended me.

    This example is to difficult for me, I was hoping something to do in an Query with: Totals, Min and Max.

    Jaap
    Code:
    SELECT MeterReading.ID,
    MeterReading.ReadDate,
    MeterReading.MeterValue,
     (SELECT TOP 1 Dupe.MeterValue                 
     FROM MeterReading AS Dupe                     
     WHERE Dupe.AddressID = MeterReading.AddressID 
       AND Dupe.ReadDate < MeterReading.ReadDate   
     ORDER BY Dupe.ReadDate DESC, Dupe.ID)          AS PriorValue
    
    That is a query?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    232
    NL
    Als je alleen die ene tabel hebt, kan je dit volgens mij beter oplossen in Excel.
    Het punt is dat Access in tegenstelling tot Excel niet zoiets kent als de "vorige regel". Je moet dat oplossen in termen van de vastgelegde gegevens. Dus iets als "vind het record met de hoogste datum kleiner dan de datum uit het huidige record". Om dat te realiseren heb je inderdaad ingewikkelde oplossingen nodig, maar het kan wel.

    ​EN
    If you only have that one table, I think you can solve this better in Excel.
    The point is that, unlike Excel, Access has no such thing as the "previous line". You have to solve that in terms of the data captured. So something like "find the record with the highest date less than the date from the current record". To achieve this you will indeed need complicated solutions, but it is possible.
    Groeten,

    Peter

  7. #7
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Quote Originally Posted by xps35 View Post
    NL
    Als je alleen die ene tabel hebt, kan je dit volgens mij beter oplossen in Excel.
    Het punt is dat Access in tegenstelling tot Excel niet zoiets kent als de "vorige regel". Je moet dat oplossen in termen van de vastgelegde gegevens. Dus iets als "vind het record met de hoogste datum kleiner dan de datum uit het huidige record". Om dat te realiseren heb je inderdaad ingewikkelde oplossingen nodig, maar het kan wel.

    ​EN
    If you only have that one table, I think you can solve this better in Excel.
    The point is that, unlike Excel, Access has no such thing as the "previous line". You have to solve that in terms of the data captured. So something like "find the record with the highest date less than the date from the current record". To achieve this you will indeed need complicated solutions, but it is possible.
    Beste Peter, bedankt voor het snelle antwoord.

    Dan wil ik je toch vragen of het werken met een 2e Tabel een oplossing kan zijn svp?

    Groeten

    Jaap

    EN
    Dear Peter, thank you for the quick answer.
    Then I would like to ask you whether working with a 2nd Table could be a solution, please?

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    To achieve this you will indeed need complicated solutions, but it is possible.
    Hasn't Allen Browne already given that solution?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    232
    Ik weet niet wat je in die tweede tabel wilt zetten. Met de huidige tabel is niets mis. Wat dat betreft heeft een tweede tabel dus geen zin en wordt het alleen maar ingewikkelder.Zoals anderen al schreven is het op te lossen. Alleen ziet het er ingewikkeld uit.

    I don't know what you want to put in that second table. There is nothing wrong with the current table. In that respect, a second table is pointless and it will only become more complicated. As others have already written, it can be solved. Only it looks complicated.
    Groeten,

    Peter

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    It is complicated, due to the fact that that table is not normalized?

    So not being normalized, Excel would be a better option.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    232
    Quote Originally Posted by Welshgasman View Post
    It is complicated, due to the fact that that table is not normalized
    That is interesting! What should the table look like?
    Groeten,

    Peter

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    this is the table I use to record the readings
    Click image for larger version. 

Name:	image_2023-12-21_182723427.png 
Views:	21 
Size:	6.3 KB 
ID:	51240

    And my sql to determine values is

    Code:
    SELECT 
      A.MeterFK, 
      A.ReadingDate, 
      A.Reading, 
      B.ReadingDate, 
      B.Reading,
      [a].[readingdate]-[b].[readingdate] AS days, 
      [A].[reading]-[b].[reading]-(100000*([a].[readingdate]=#2020-11-12#)) AS used, 
      choose(a.meterfk+1,1,11.30585333) AS ConvFactor, 
      ([used]*convFactor)/[days] AS perday, 
       [perday]*365 AS peryear
    
    
    FROM hseReadings AS A INNER JOIN hseReadings AS B ON (A.MeterFK = B.MeterFK) AND (A.ReadingDate > B.ReadingDate)
    
    WHERE (((A.MeterFK)<=1) AND ((B.Estimate)=False) AND ((A.Estimate)=False))
    
    ORDER BY A.MeterFK DESC , A.ReadingDate DESC , b.readingdate DESC;
    This compares all readings from a meter with all previous readings so you can see at a glance usage over the last month, 2 months, years, whatever and compare with same month last year, current 12 months with previous 12 months etc. Could easily have additional criteria to limit this.

    The conversion factor is used to determine kw from the usage based on the meter reading

    The used value has an additional calculation adjustment due to the meter 'rolling over' from 100,000 back to zero.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by xps35 View Post
    That is interesting! What should the table look like?
    My thoughts would be a field to hold the type of reading. That would hold the ID from the MeterTypes table.
    Then the sub query would also check the meter type.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    Jaap's Avatar
    Jaap is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Apr 2017
    Location
    North Holland
    Posts
    49
    Quote Originally Posted by CJ_London View Post
    this is the table I use to record the readings
    Click image for larger version. 

Name:	image_2023-12-21_182723427.png 
Views:	21 
Size:	6.3 KB 
ID:	51240

    And my sql to determine values is

    Code:
    SELECT 
      A.MeterFK, 
      A.ReadingDate, 
      A.Reading, 
      B.ReadingDate, 
      B.Reading,
      [a].[readingdate]-[b].[readingdate] AS days, 
      [A].[reading]-[b].[reading]-(100000*([a].[readingdate]=#2020-11-12#)) AS used, 
      choose(a.meterfk+1,1,11.30585333) AS ConvFactor, 
      ([used]*convFactor)/[days] AS perday, 
       [perday]*365 AS peryear
    
    
    FROM hseReadings AS A INNER JOIN hseReadings AS B ON (A.MeterFK = B.MeterFK) AND (A.ReadingDate > B.ReadingDate)
    
    WHERE (((A.MeterFK)<=1) AND ((B.Estimate)=False) AND ((A.Estimate)=False))
    
    ORDER BY A.MeterFK DESC , A.ReadingDate DESC , b.readingdate DESC;
    This compares all readings from a meter with all previous readings so you can see at a glance usage over the last month, 2 months, years, whatever and compare with same month last year, current 12 months with previous 12 months etc. Could easily have additional criteria to limit this.

    The conversion factor is used to determine kw from the usage based on the meter reading

    The used value has an additional calculation adjustment due to the meter 'rolling over' from 100,000 back to zero.

    Thank you all, I will look to the example of CJ_London.

    I also have to figure out how this all is working, this will take a lot of time, but it's worth it.

    Jaap

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by CJ_London View Post
    this is the table I use to record the readings
    Click image for larger version. 

Name:	image_2023-12-21_182723427.png 
Views:	21 
Size:	6.3 KB 
ID:	51240

    And my sql to determine values is

    Code:
    SELECT 
      A.MeterFK, 
      A.ReadingDate, 
      A.Reading, 
      B.ReadingDate, 
      B.Reading,
      [a].[readingdate]-[b].[readingdate] AS days, 
      [A].[reading]-[b].[reading]-(100000*([a].[readingdate]=#2020-11-12#)) AS used, 
      choose(a.meterfk+1,1,11.30585333) AS ConvFactor, 
      ([used]*convFactor)/[days] AS perday, 
       [perday]*365 AS peryear
    
    
    FROM hseReadings AS A INNER JOIN hseReadings AS B ON (A.MeterFK = B.MeterFK) AND (A.ReadingDate > B.ReadingDate)
    
    WHERE (((A.MeterFK)<=1) AND ((B.Estimate)=False) AND ((A.Estimate)=False))
    
    ORDER BY A.MeterFK DESC , A.ReadingDate DESC , b.readingdate DESC;
    This compares all readings from a meter with all previous readings so you can see at a glance usage over the last month, 2 months, years, whatever and compare with same month last year, current 12 months with previous 12 months etc. Could easily have additional criteria to limit this.

    The conversion factor is used to determine kw from the usage based on the meter reading

    The used value has an additional calculation adjustment due to the meter 'rolling over' from 100,000 back to zero.
    I actually use Excel for mine.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 4
    Last Post: 10-13-2021, 01:14 PM
  2. Replies: 4
    Last Post: 01-07-2019, 05:20 PM
  3. Replies: 3
    Last Post: 10-19-2015, 11:05 PM
  4. Replies: 2
    Last Post: 03-03-2015, 08:43 PM
  5. Replies: 3
    Last Post: 10-09-2014, 03:31 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