473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Normalizing a Database Table to make Data Queryable

I have inherited a database that is built mainly from imported excel spreadsheets. The purpose of the database is to replace a very old program we are using to track utility spending. The main problem right now is one of the excel sheets lists the meters used for each building, but not in a good format. This is the format:
Expand|Select|Wrap|Line Numbers
  1. Bldg____Electric_____Gas___Heat____Cool____Water___Sewer
  2. BLDG1___79E+231E_____40G___1H______1C______86W_____111S
  3. BLDG2___80E+232E_____39G___NULL____NULL____3W+2W___163S
  4. BLDG3___71E-72E+316E_168G__9H______20C+48C_77W_____138S
  5. BLDG4___332E_________187G__53H-52H_50C-49C_162W____183S
  6. **Notice how in bldg3 electric, it's 71E-72E+316E. 
That means the cost for this building is the cost of 71E minus the cost of 72E plus the cost of 316E. I have a separate table that has the costs of each meter every month, which we have been recording for several years.

I am trying to find the total cost for each building every month, by creating a query and doing some VBA, but nothing is working right now. I've been working with just the electric meters to try to get something to work, and I found this function

Expand|Select|Wrap|Line Numbers
  1. Public Function SplitMeters(sPackedValue As Variant, nPos As Long)
  2. Dim sElements() As StringsElements() = Split(Nz(sPackedValue, ""), "E")
  3. If UBound(sElements) < nPos Then
  4. SplitMeters = ""
  5. Else
  6. SplitMeters = sElements(nPos)
  7. End If
  8. End Function
I then grabbed the electric meters and applied this function to them to create a query that looks like

Expand|Select|Wrap|Line Numbers
  1. BLDG___METER1___METER2___METER3
  2. BLDG1__79_______+231_____NULL__
  3. BLDG2__80_______+232_____NULL__
  4. BLDG3__71_______-72______+316__
  5. BLDG4__332______NULL_____NULL__
This makes the data easier to look at, and if I filter the complete meter history table I've been looking at to just grab the electric meters I can match it against the first column. I don't know what to do about the plus and minus signs though, and I know that this isn't normalized data. I haven't really been able to find someone with a problem like mine, or a solution to get the data more normalized.

My idea right now is get all the meters in one field and have the building name repeat, then try to join on meter number and have another field with cost besides that, and then grab all the costs for each building to find the total. However I can't find a way to do this, so I am open to any ideas, especially regarding how to handle the plus and minus signs in the data. I know the data is in horrible shape, and that is a big part of why they have me replacing the old program. I'm just trying to cleanup the best I can. Thank you for all the help and please ask any questions you have!
Apr 28 '15 #1
4 1794
twinnyfo
3,653 Expert Mod 2GB
hypetech,

Welcome to Bytes!

As far as the E-meters go, since you have multiple values, but differing numbers of values, I would normalize that portion of your data by using a separate table. I don't see any date fields, but I would also add those. Thus, you would have this:

Expand|Select|Wrap|Line Numbers
  1. tblEMeters
  2.  
  3. Field        Description
  4. EMeterID     AutoNumber, PK -- you may or may not
  5.              need this, but it is a good habit
  6. Bldg         FK to your Various Buildings
  7. MeterDate    The date the meter was read
  8.              (or input into the DB)
  9. MeterValue   Integer; These are determined using
  10.              your SplitMeters Function
I would use the CInt() Function to determine the actual values of your meters, since you are beginning with text values. Thus:

Expand|Select|Wrap|Line Numbers
  1. CInt("+231") = 231
  2. CInt("-72") = -72
Using this setup for your tables, you can aggregate (sum) the values of your meters across buildings and dates, as 71 + (-72) + 316 = 315 when those values are added together.

Hope this makes sense. More importantly, hope this helps you out on your project!
Apr 29 '15 #2
jforbes
1,107 Expert 1GB
Nice work Twinnyfo!

hypetech, I'm a bit confused on the data. When you say:
**Notice how in bldg3 electric, it's 71E-72E+316E.
That means the cost for this building is the cost of 71E minus the cost of 72E plus the cost of 316E. I have a separate table that has the costs of each meter every month, which we have been recording for several years.
Does this mean the cost is $71 - $72 + $316? Or are 71E, 73E and 316E references to meters that have a monthly cost associated with them?
Apr 29 '15 #3
Hey guys, thanks for replying! Sorry jforbes, 71E, 73E and 316E are references to meters that have a monthly cost associated with them. We find out the monthly cost when we receive all our bills from the meter companies and then input them. The database I'm developing will be the new place we input all our bill readings into. We have a table that has all the meter history going back years, with each individual reading for every meter every month.
Apr 29 '15 #4
jforbes
1,107 Expert 1GB
Not trying to take over here Twinnyfo, actually, I'm glad to see you back. =)


hypetech, This is what I understand so far:

This spreadsheet that you are attempting to normalize into database tables defines what Meters are associated with which Buildings.

So there would be two Tables, one for Buildings and one for Meters.

From the looks of the spreadsheet, there is a sign associated with the relationship between Buildings and Meters. My guess is that there may be one electrical cable supplying multiple buildings and so a meter is put between each building and the difference between meters is the consumption of that building. It also looks like there may be multiple feeds to a building, so in the case of:
Expand|Select|Wrap|Line Numbers
  1. BLDG3___71E-72E+316E_168G__9H______20C+48C_77W_____138S
  2.  
the electrical consumption for BLDG3 is the formula of:
((Meter 71) - (Meter 72)) + (Meter 316)

Then you have a history table (that we haven't seen yet) with the Meter Readings that you hope to link back to the Meters and determine usage per building.

Sound about right?
Apr 29 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ester | last post by:
I would like to read data from a database table row by row and execute some codes based on the data retrieved from each row. For example, there are 4 fields on a table called Image_Tbl. Those...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
0
by: mebimathew | last post by:
hi i am working in java swing.i have a beginner.so pls help me to display the databasetable`s fields and data to the frontend.
3
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a...
0
by: dphill | last post by:
Hello all I am a beginner .Net programmer so please forgive my ignorance. In brief, I am trying to read from xml file stored in a SQL database table’s field. This is what I used to create...
4
by: Amar | last post by:
Hi All, I need to select data from a database table containing huge amount of data. Now I am storing data using one primary key and I am just using simple select statement, and this process...
5
by: fruityfreak | last post by:
I would like to know how to I retrieve information from another database table... Instead of keying in manually, I would like to retrieve data directly from the logged in user row. For the user...
0
by: mohaaron | last post by:
Has anyone else tried to save a GridView as a excel file and then use ado.net to read the excel sheet back into a database table? I'm having a terrible time trying to make this work. The normal...
2
by: Joe C. | last post by:
hello all, thanks for reading. i am trying to find a better way to keep track of changes in a ms sql database table. we have a ticketing system in the office, and a small app was written to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.