18
Exercise 3.B.3-Using Access to Select Data Using Access to Select the Data You Want (exercise 3.B.3—the third situation) The data that we want to analyze is on the sheet CrnPtTeomMet of the Exercise 3 spreadsheet. As you can see, it will be problematic to use Excel to calculate average values over sub time periods, while excluding flagged records from the calculations. Instead, we will use MS Access to calculate averages over months, years, quarters, etc. and will then chart these values. Open a new blank MS Access database. Save this database on your jump drive, named Exercise 3 with your initials. Click External Data > Excel: Click Browse and navigate to the Exercise 3 spreadsheet. Pg. 1 of 18 Exercise 3.B.3-Using Access to Select Data

Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

  • Upload
    vannhan

  • View
    213

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Using Access to Select the Data You Want (exercise 3.B.3—the third situation)

The data that we want to analyze is on the sheet CrnPtTeomMet of the Exercise 3 spreadsheet. As you can see, it will be problematic to use Excel to calculate average values over sub time periods, while excluding flagged records from the calculations. Instead, we will use MS Access to calculate averages over months, years, quarters, etc. and will then chart these values.

Open a new blank MS Access database. Save this database on your jump drive, named Exercise 3 with your initials.

Click External Data > Excel:

Click Browse and navigate to the Exercise 3 spreadsheet.

Pg. 1 of 15Exercise 3.B.3-Using Access to Select Data

Page 2: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Click Open, then OK, to open the import dialog box (note that not all columns may be displayed in the import screen; you can scroll right to view the additional columns):

Select the sheet “CrnPtTeomMet” and click Next.

Pg. 2 of 15Exercise 3.B.3-Using Access to Select Data

Page 3: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Tell Access to put the data in a new table, click Next, and tell Access to index (duplicates ok) the date and time fields, as follows, with the other fields not indexed:

Click Next, and tell Access to add its own primary key:

Pg. 3 of 15Exercise 3.B.3-Using Access to Select Data

Page 4: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Let Access name the table, and click Finish. Now the table will appear in the list of tables:

You may get an error message about import errors. If this happens, Access will create a separate table (or tables) with specific information about where the errors occurred. For instance, in the above situation, the CrnPtTeomMet$_ImportErrors table shows this information, which means that the field BarometricPressure, Row 15 had an unacceptable data value.

When you open up the Excel sheet to find the value, you can see that there is a text value entry in the field that should be numbers. This also means that that value was not imported and instead is null in the Access table. It appears that this text was inadvertently typed by a user into the Excel sheet; you should take corrective action accordingly by reviewing the raw data file or data sheets, etc and correct it in both the Excel sheet and Access table.

Pg. 4 of 15Exercise 3.B.3-Using Access to Select Data

Page 5: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Open the table to make sure all the data is there, and verify that there are the same number of records in the Excel table and the access table. (9220)

Close the table, and create a new query using the wizard. Click the Create tab and then Query Wizard. Select “Simple Query Wizard” and click OK.

Select the newly imported table (“CrnPtTeomMet”) from the list. Click on the double chevron (>>) to select all the fields, then click the single back chevron (<) to de-select the ID field.

Pg. 5 of 15Exercise 3.B.3-Using Access to Select Data

Page 6: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Click Next, then select Summary:

Click on Summary Options, and select Average for all parameters except precipitation for which you need to select Sum. Also check the Count records in CrnPtTeomMet box. Click OK.

Pg. 6 of 15Exercise 3.B.3-Using Access to Select Data

Page 7: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Select Month for Group Dates In Query. Click Next. Select Open query and then Finish.

The results of the query will open. Scroll to the right to see the values and you can see it is very ugly, with negative values, and too many significant figures:

Pg. 7 of 15Exercise 3.B.3-Using Access to Select Data

Page 8: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

The negative values are due to the inclusion of the values that were rejected, so to fix this, open the query in Design View which opens up the query design pane.

Pg. 8 of 15Exercise 3.B.3-Using Access to Select Data

Page 9: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Select the Time, and delete it, and add “Is Null” to all the code and qualifier fields, so that the averages are calculated only for those records that have not been flagged:

There are a total of 10 qualifier fields to add Is Null to, and also since their values will be null, uncheck the Show box. Run the query by clicking the ! sign:

Pg. 9 of 15Exercise 3.B.3-Using Access to Select Data

Page 10: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

You will see the results of the query, looking something like:

Ignore the significant figures (that is easy to fix in the query design by changing each column’s Properties, Format, Fixed, and set it to 1 or 2 digits) but for now check that the values make sense. Save the query.

NOTE THAT, like Excel, text values are left-aligned, and our dates have become text, which will not help us chart these values by date in an Excel XY chart! To keep a field that is a date and have it exportable as a date (rather than a text) field, open the query in design view. Select any column and click Insert Column on the toolbar.

Pg. 10 of 15Exercise 3.B.3-Using Access to Select Data

Page 11: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

In the new blank column, click on Field, which gives you a drop-down list, and select date

Then in the Group By row change Group By to Min:

This will show us the Minimum date in each quarter, but we could have chosen First as well, it will just return the first of the month, or we could have chosen Max or Last and it would have returned the last day. We just want the date formatted as date (not text) for when we export into Excel.

You can see that Access put the dates in a weird alphabetical order, but that is okay. All we are interested in is getting this into Excel where we can graph it. (You can sort on any column in datasheet view.)

Pg. 11 of 15Exercise 3.B.3-Using Access to Select Data

Page 12: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Click the External Data tab, and from the Export Menu select Excel.

Select “Browse…” and tell Access to export it as an Excel file, onto your USB drive. Change the file name to end in “_by_month_initials”:

Pg. 12 of 15Exercise 3.B.3-Using Access to Select Data

Page 13: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

Now open that Excel file and graph the data, using the chart wizard and setting each parameter as a different series in an XY chart, starting with following similar steps as we did previously.

It may look pretty bad at first:

Pg. 13 of 15Exercise 3.B.3-Using Access to Select Data

Page 14: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

But put the dates in order by clicking on Sort in the date column and it will improve, by selecting the entire table, then clicking on Sort Ascending:

Now the chart, with one series, should look something like this:

Add relative humidity as a 2nd series:Select the RH data, click Copy, then select the chart, then click Paste Special, Add cells as new series, values (Y) in columns, and if you included the header in your Copy selection, labels in first row, and make sure categories in first column is Unselected (this is an XY chart and we don’t want the dates charted as categories, but as values.)

After adding humidity, you should see a fascinating graph like this. What does it tell you?

Pg. 14 of 15Exercise 3.B.3-Using Access to Select Data

Page 15: Using Access to Select the Data You Want (exercise 3itepsrv1.itep.nau.edu/itep_course_downloads... · Web viewUsing Access to Select the Data You Want (exercise 3.B.3—the third

Exercise 3.B.3-Using Access to Select Data

You can add each series as you just did, evaluating whether the new series helps you understand your data or not. Just click the series to remove it if it doesn’t give you insights about your data.

Pg. 15 of 15Exercise 3.B.3-Using Access to Select Data