Using Database Functions

image with no caption

The database functions are particularly useful because they analyze data from tables with headings (field names) and data rows (data records). The block of information in rows and columns constitutes a database.

Using the database functions is made easier if the following rules are observed:

  • Make sure lists have column headings.

  • Make sure lists don’t contain empty rows or columns.

  • Make sure lists don’t contain linked cells.

In Excel 2003 and earlier, the usage of Excel as a database was stretched to its limits pretty quickly because a table was limited to 65,536 rows. In Excel 2007 this limit was extended: Now each table for data lists can have 1,048,576 rows. The same applies to columns: In Excel 2003, a table could have 256 columns, and in Excel 2007, up to 16,384 columns are allowed.

Dynamic Database Names

Dynamic names are an effective way to simplify working with data in Excel databases. If you specify a dynamic name, you can open a data template to view and capture data and then browse the data records, find data, or enter data.

When using dynamic names, it is important to remember to include an empty row below and an empty column next to the last entry. This avoids problems if you add new columns or rows at a later time.

See Also

The OFFSET() function used in the following example is explained in more detail in Chapter 13.

To assign a dynamic name to the Excel list, perform the following steps in Excel 2007 or Excel 2010:

  1. Click in cell A1 or the first cell of your database, and then click the Define Names button (see Figure 2-30) in the Defined Names group on the Formulas tab.

    Defining names in Excel 2007 or Excel 2010.

    Figure 2-30. Defining names in Excel 2007 or Excel 2010.

  2. Enter the name Start in the New Name dialog box, and click OK (see Figure 2-31).

    Specifying the starting point of the database.

    Figure 2-31. Specifying the starting point of the database.

    The starting point of the database is now set. Next you have to generate the dynamic name of the database with the OFFSET() function. First you have to find out how many entries exist in column A and row 1.

  3. Click the header of column A to select the entire column, and enter the name Row in the name box (see Figure 2-32). Press the Enter key to confirm.

    Assigning a name to column A.

    Figure 2-32. Assigning a name to column A.

    Note

    The name Row for column A makes sense because you want to calculate the entries in column A (in other words, the rows).

  4. To test the settings, calculate the number of rows in column A by using the COUNTA() function. Click any empty cell in the worksheet and enter the following formula:

    =COUNTA(row)

    Because column A has the name Row, you have to click only column A to select the argument for the function. Because the number of rows was calculated with the COUNTA() function, the content of all cells, including text and logical values, is taken into account.

  5. Press the Enter key to confirm.

    If you are working with the Excel table in the DBFunction empty.xlsx file from the sample files, the result is 7,008. Next you will calculate the number of entries in row 1. To do this you use the same procedure you used to calculate the number of entries in column A.

  6. Click the row header to select the entire row, and enter the name Column in the name box (see Figure 2-33).

    Assigning a name to row 1.

    Figure 2-33. Assigning a name to row 1.

  7. To test the settings, calculate the number of entries in row 1 by using the COUNTA() function. Click any empty cell in the worksheet and enter the following formula:

    =COUNTA(column)

If you are working with the Excel table in the DBFunction empty.xlsx file from the sample files, the result is 6.

Caution

Remember to delete the functions you used to calculate the entries in the row and column.

By naming the column and row and by calculating the entries within the column and row, you have already created the basis for the dynamic name of the matrix (database). If you add or delete columns or rows, the value within your formula cells will increase or decrease, respectively.

Now you can actually assign a dynamic name to the database in the following range: The database range starts at cell A1, to which you gave the name Start. This position is extended down by the number of rows calculated with the =COUNTA(row) function; in this case, 7,008 entries. At the same time, the position is extended six columns to the right, beginning at the Start cell, based on the result of the calculation

=COUNTA(column)

You then need to subtract one position in each dimension of the database range. The following function assigns the dynamic name and defines the database range:

=Start:OFFSET(start,COUNTA(row)-1,COUNTA(column)-1)

Perform the following steps:

  1. On the Formulas tab, click the Define Name button in the Defined Names group.

  2. In the New Name dialog box, enter the name Database.

  3. Enter in the Refers To field the formula shown just before these steps, as shown in Figure 2-34. If you aren’t using the worksheet in the Chapter02 sample files folder, adjust the entry accordingly.

    Specifying the database range.

    Figure 2-34. Specifying the database range.

  4. Click the OK button.

To check the name, press the F5 key and enter the name Database in the Reference field in the Go To dialog box (see Figure 2-35) that appears. Click OK.

Searching for and showing specific database areas.

Figure 2-35. Searching for and showing specific database areas.

If the dynamic name was assigned properly and the database range is correct, the entire database range between cell A1 and cell F7008 should be selected (see Figure 2-36, but note that only a portion of the range is shown).

The entire database is selected, but only a portion is shown here.

Figure 2-36. The entire database is selected, but only a portion is shown here.

Excel 2003, Excel 2007, and Excel 2010 offer an alternative way to assign your own dynamic names: You can define the list range to be evaluated as a list (Excel 2003) or a table (Excel 2007 or Excel 2010). Perform the following steps in Excel 2003:

  1. Place the insertion point in the list.

  2. Select the Date/List/Create list menu option.

  3. If necessary, correct the suggested list range reference and specify whether the list has a header.

  4. Click OK to confirm.

In Excel 2007 and Excel 2010, the list is called a table. To create the table range in Excel 2007 or Excel 2010, perform the following steps:

  1. Place the insertion point in the list.

  2. On the Insert tab in the Tables group, click the Table button.

  3. If necessary, correct the suggested table range reference and specify whether the list has headings.

  4. Click OK to confirm.

In both cases, you get a qualified list range. Excel extends all references in this list range as soon as the range is extended.

Database Functions in Practice

The following practice examples show typical calculations that use the database functions of Excel.

A training center has created a database to capture information about seminars conducted by the trainer. This data needs to be evaluated. The database has the dynamic name CourseInfo. The following database fields are available (see Figure 2-37):

  • Date

  • Training

  • Coach

  • Male/Female

  • Company

  • Rating

  • Revenue

The results in the database.

Figure 2-37. The results in the database.

The training center wants to know how many Excel seminars were conducted since it started to collect information. The DCOUNTA() function returns the result.

How Many Excel Seminars Took Place?

The DCOUNTA() function counts the number of cells in a column, list, or database that are not empty and that meet the specified conditions (see Figure 2-38).

Calculating the number of Excel seminars in the database.

Figure 2-38. Calculating the number of Excel seminars in the database.

Define the criteria range for the filter. The criteria range consists of the column heading and the filter criterion in the cell below. To do this, copy the range B1:B2 into cells L1:L2. The formula =DCOUNTA(CourseInfo,B1,L1:L2) returns 23 Excel seminars.

You can find the number of other seminars by changing the filter in L2, for example, to Microsoft Word.

Calculating Revenue

Next, the training center wants to know how much revenue the Excel seminars generated. You can use the DSUM() function to find this answer. This function adds the numbers in a column in a database that meet the specified conditions (Figure 2-39).

Calculating the revenue generated by Excel seminars.

Figure 2-39. Calculating the revenue generated by Excel seminars.

The formula =DSUM(CourseInfo,G1,L1:L2) returns a revenue of $ 22,522 generated from Excel seminars.

Finding the Average Rating of the Seminars

The training center is also interested in the average rating for the trainers and the seminars. You find this by using the DAVERAGE() function. This function provides the average of the ratings that meet the specified conditions (see Figure 2-40).

Calculating the average values from the database values in the Rating column.

Figure 2-40. Calculating the average values from the database values in the Rating column.

In this case, you don’t need the criteria range L1:L2, because no filter is required. The formula =DAVERAGE (CourseInfo,F1,F:F) returns an average rating of 1.88.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.201.217