Forum Discussion
Project of meterreadings and consumptioncalculation
Hi! I have for quite som time tried to learn Access. Im only at the base to create tables and so.
The project I have been trying on and off, for some years now is a database that will keep track of Estates, Persons (owning the estate), Every estate has a submeter wich is read 2 times/year, and there is one master meter.
Now I am trying to get a query to calculate the consumption of each estate by reading the last entry minus the second latest. And then take the mastermeter minus the sum of all submeters to calculate if there is a differens.
But I can't get it to work, tried some tips I've got but can't just make it.
The tables I got in my testbench is:
tblPerson
PersonID, ForName, LastName
1 John Doe
2 Lisa Niska
3 Gary Cooper
4 Austin Powers
tblEstate
EstateID, EstateName
1 Mastermeter
2 House001
3 House003
4 House004
tblEstatePerson
EstatePersonID, Estate ID(lookup from tblEstate), PersonID(lookup from tblPerson)
1 House001 John Doe
2 House003 Lisa Niska
3 House004 Gary Cooper
4 House003 Austin Powers
tblReading
ReadingID, ReadingDate, EstateID, Reading
1 2023-01-01 MasterMeter 230
2 2023-01-01 House001 10
3 2023-01-01 House002 100
4 2023-01-01 House003 115
5 2023-02-01 MasterMeter 260
6 2023-02-01 House001 20
7 2023-02-01 House002 110
8 2023-02-01 House003 120
....
I tried to follow a direction in NorthWind database to get de second latest date for an order and calculate the days between. But I havent been able to convert it for my needs.
The query consist of ReadingID, ReadingDate, Estate, Reading, Prior reading, Consumption.
Prior reading has this code:
Prior Reading: (SELECT MAX([Reading])
FROM [tblReading] AS [Old Reading]
WHERE [Old Reading].[Reading]<[tblReading].[Reading]
AND [Old Reading].[ReadingID]=[tblReading].[ReadingID])
And consumption has this code:
Consumption: [Reading]-[Prior Reading]
I got the fields but no values in the fields. Am I thinking totaly wrong?
I want to use theese numbers to be able to make an invoice to each house.
Hope you unde
3 Replies
- arnel_gpSteel Contributor
- andersammediaseCopper Contributor
Thanks a lot! Now I will try to read and understand what the different parts do.
And then start working on an invoice for each estate based on those numbers.
Another question. If I have waterprice in a table to take the cunsumption times waterprice, lets say it is£12 at this reading.
If we later raise the prise to £14 will that affekt the old invoices to, which are already billed?
Should I make a tblWaterPrice WaterpriceID, WaterPrice, FromDate, ToDate?
To be able to keep track and to have the old ones show the right price if someone asks for a copy?
Am I thinking wrong here?
- arnel_gpSteel Contributor
you can use FromDate and ToDate to your WaterPrice.
you can also use only one Date, EffectiveDate (see the tblWaterPrice on the demo).
see Query1 and Query4 on how to get the WaerPrice.