home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / spread / xe0186.zip / XE0186.TXT
Text File  |  1993-05-11  |  25KB  |  576 lines

  1. ======================================================================
  2.   Microsoft(R) Product Support Services Application Note (Text File)
  3.                          XE0186: DATABASE TIPS
  4. ======================================================================
  5.                                               Revision Date: 5/93
  6.  
  7. The following information applies to Microsoft Excel, version See
  8. Below.
  9.  
  10.  --------------------------------------------------------------------
  11. | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY    |
  12. | ACCOMPANY THIS DOCUMENT (collectively referred to as an            |
  13. | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      |
  14. | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO    |
  15. | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A     |
  16. | PARTICULAR PURPOSE. The user assumes the entire risk as to the     |
  17. | accuracy and the use of this Application Note. This Application    |
  18. | Note may be copied and distributed subject to the following        |
  19. | conditions: 1) All text must be copied without modification and    |
  20. | all pages must be included; 2) If software is included, all files  |
  21. | on the disk(s) must be copied without modification [the MS-DOS(R)  |
  22. | utility DISKCOPY is appropriate for this purpose]; 3) All          |
  23. | components of this Application Note must be distributed together;  |
  24. | and 4) This Application Note may not be distributed for profit.    |
  25. |                                                                    |
  26. | Copyright 1988-1993 Microsoft Corporation. All Rights Reserved.    |
  27. | Microsoft and MS-DOS are registered trademarks and Windows         |
  28. | is a trademark of Microsoft Corporation.                           |
  29.  --------------------------------------------------------------------
  30.  
  31. This application note applies to Microsoft Excel versions 2.x, 3.0,
  32. and 4.0 for Windows(TM), and to Microsoft Excel versions 2.2, 3.0, and
  33. 4.0 for the Macintosh(R).
  34.  
  35.                                    
  36.                           GENERAL INFORMATION
  37.                           ===================
  38.  
  39. A database is a structured table of information. When information is
  40. stored in a database, you can quickly and easily locate and retrieve
  41. individual pieces of information. This Application Note describes how
  42. you can more productively use the database features of Microsoft
  43. Excel.
  44.                                    
  45.                                    
  46.                           SORTING A DATABASE
  47.                           ==================
  48.  
  49. To keep records intact when you sort a database, select the entire
  50. cell range to be sorted (excluding the field names) before you choose
  51. Sort from the Data menu. Selecting the entire cell range allows you to
  52. sort using a column as a sort key while keeping the information in
  53. each row intact. For example, if your database is in cells A1:D25 with
  54. your field names in A1:D1, select cells A2:D25 to sort your records.
  55.  
  56. In Microsoft Excel versions 2.x, if you sort your database frequently,
  57. define a separate name (for example, Data_Sort) to refer to the
  58. records alone, omitting the field names. After you define Data_Sort,
  59. you can quickly select the records you want to sort by choosing Go To
  60. from the Formula menu and typing "DATA_SORT" (without the quotation
  61. marks). As you add new records to your database, you will need to
  62. redefine Data_Sort to include additional rows.
  63.  
  64. You can also use this method in Microsoft Excel versions 3.0 and 4.0.
  65. However, there is another method that is more efficient. When you
  66. define Data_Sort, type the following formula in the Refers To box in
  67. the Define Name dialog box:
  68.  
  69. =OFFSET(Database,1,0,ROWS(Database)-1)
  70.  
  71. This formula sets the Data_Sort range to be offset one row from the
  72. first row of your database, thereby omitting field names. Also, the
  73. size of the range will be automatically adjusted when your database
  74. range changes due to record additions and deletions.
  75.  
  76.  
  77. Sort Order
  78. ==========
  79.  
  80. Microsoft Excel always places any blank cells at the bottom of a
  81. selection, regardless of whether Ascending or Descending sort order is
  82. selected. The sort order for text entries, from left to right and top
  83. to bottom, is as follows:
  84.  
  85.  
  86. Microsoft Excel versions 2.2, 3.0, and 4.0 for Macintosh and versions
  87. -2.x and 3.0 for Windows:
  88. ----------------------------------------------------------------------
  89.    
  90.    0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ' ( ) * + , - . / : ; < = >
  91.    ? @ A B C D E F G H I J K L M N O P Q R S T W U V W X Y Z [ \ ] ^ _
  92.    ` { | } ~
  93.    
  94.  
  95. Microsoft Excel version 4.0 for Windows:
  96. ----------------------------------------
  97.    
  98.    0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ' ( ) * + , - . / : ; < = >
  99.    ? @ [ \ ] ^ _ ` { | } ~ A B C D E F G H I J K L M N O P Q R S T W U
  100.    V W X Y Z
  101.    
  102.   NOTE: The sort order is not case sensitive. (For example, "A" and
  103.   "a" are treated the same and will appear in the same order as they
  104.   did in the original selection. If "a", "A", and "a" appear in three
  105.   separate cells, choosing Sort will have no effect.)
  106.  
  107.  
  108. Sorting on More Than Three Fields
  109. =================================
  110.  
  111. To perform a sort on more than three fields (keys) at one time, you
  112. must do multiple sorts, working backwards from the least-significant
  113. sort key. For example, assume you want to sort the range A2:E25 with
  114. the data in column E sorted within the data in column D, which is
  115. sorted within the data in column C and so on, back to column A. To
  116. perform this type of sort, do the following:
  117.  
  118. 1. Select cells A2:E25.
  119.  
  120. 2. From the Data menu, choose Sort. For the 1st Key, enter $D$2, and
  121.    for the 2nd Key, enter $E$2. Choose OK. The data in column E will
  122.    now be sorted within the data in column D.
  123.  
  124. 3. With the range still selected, from the Data menu, choose Sort. For
  125.    the 1st Key, enter $A$2, enter $B$2 for the 2nd Key, and $C$2 for
  126.    the 3rd Key. Choose OK.
  127.  
  128. This last sort will keep the sorted order of columns D and E while
  129. sorting column C within column B within column A. Using this technique
  130. (starting with the least significant and working back to the most
  131. significant), you can sort using any number of keys.
  132.  
  133.                                    
  134.                                    
  135.                    MAINTAINING DATABASE INFORMATION
  136.                    ================================
  137.  
  138. You can insert and delete records in a database either manually or
  139. with a form. To access a data form, choose Form from the Data menu.
  140.  
  141.  
  142. Inserting Records
  143. =================
  144.  
  145. If you are not using a data form (which automatically redefines the
  146. database range when a new record of information is entered), you
  147. should define the database to include a blank row at the bottom of
  148. your data. Then, before you add a new record to the database, insert a
  149. new row by selecting the blank row after your last record and choosing
  150. Insert from the Edit menu. Using this method, you will not have to
  151. redefine the database every time a record is added. Note that if you
  152. have data to the right or the left of your database range, this
  153. procedure may displace it. Alternatively, rather than select the
  154. entire row, you can limit your selection to only those cells below
  155. your last record. When you choose Insert from the Edit menu, select
  156. the Shift Cells Down option.
  157.  
  158.  
  159. Deleting Records
  160. ================
  161.  
  162. To delete the records that match your criteria, choose Delete from the
  163. Data menu (there is no keyboard command equivalent for this command).
  164. Microsoft Excel will erase the entries in every field of each record
  165. that matches the criteria.
  166.  
  167.   Warning: Using the Delete command when your criteria range contains
  168.   a totally blank row will erase the entire database because a blank
  169.   criterion matches every record.
  170.                                    
  171.                                    
  172.              ANALYZING AND REPORTING DATABASE INFORMATION
  173.              ============================================
  174.  
  175. To find and extract database information, you must have a valid
  176. criteria and extract range outside your database range.
  177.  
  178.  
  179. Setting Your Criteria Range
  180. ===========================
  181.  
  182. A valid criteria range must contain at least two cells (two rows by
  183. one column):
  184.  
  185.  - If you are using comparison criteria, the top row will contain your
  186.    database field labels. The field labels used in your criteria range
  187.    must be identical to the labels in your database range. To ensure
  188.    that these labels are identical, copy the desired field labels from
  189.    your database range and paste them in your criteria range.
  190.  
  191.  - If you are using computed criteria, the top row must contain a name
  192.    other than a database field label.
  193.  
  194. In the cells directly beneath the labels or names, enter the data you
  195. want to match or the formula you want to compute. To set your criteria
  196. range, select the top row containing your labels or names and the
  197. cells beneath them, and choose Set Criteria from the Data menu.
  198.  
  199.  
  200. Entering Multiple Criteria
  201. ==========================
  202.  
  203. You can specify "and" and "or" relationships based on where you
  204. position different criteria within a criteria range. You can also use
  205. the AND() and OR() functions for computed criteria.
  206.  
  207.  
  208. Finding Records That Match Criteria X and Criteria Y
  209. -----------------------------------------------------
  210.  
  211. When two or more entries are on the same row of a criteria range,
  212. Microsoft Excel selects the records that meet all the criteria. To
  213. specify two criteria for the same field, duplicate the field label in
  214. the criteria range. For example, suppose you want to select those
  215. records with entries in the Income field that fall between $18,000 and
  216. $32,000. To do this, you must specify two criteria that relate to the
  217. Income field, one to look for data that is greater than $18,000 and
  218. the other to look for data that is less than $32,000. In this case,
  219. two criteria are placed under separate instances of the Income field
  220. heading. Since both entries are on the same row of the criteria range
  221. and both are beneath an Income field heading, Microsoft Excel combines
  222. them and finds only those records with an income that is both greater
  223. than $18,000 and less than $32,000.
  224.  
  225. In the following worksheet, the database is defined as A1:C5, the
  226. criteria range is defined as E1:H2, and the extract range is defined
  227. as E4:G4. When you choose Find from the Data menu, the records for
  228. Green and Simpson will be highlighted because each has an income
  229. greater than $18,000 but less than $32,000. Similarly, when you choose
  230. Extract from the Data menu, the records for Green and Simpson will be
  231. extracted to the extract range.
  232.  
  233. Alternatively, you can use a computed criterion to find and extract
  234. the records. In cell D1, type the name SALARY. In cell D2, enter the
  235. formula:
  236.  
  237.    =AND(B2>18000,B2<32000)
  238.  
  239. The first cell reference in the Income field must be used in the
  240. formula and it must be relative. If you then select cells D1:D2 and
  241. choose Set Criteria from the Data menu, when you find or extract data,
  242. the formula will be applied to each individual record, and only the
  243. records in the database that return TRUE for both conditions will be
  244. found or extracted.
  245.  
  246.    A         B        C            D   E     F       G      H
  247. ----------------------------------------------------------------------
  248. 1  Name      Income   Department       Name  Income  Income Department
  249. 2  Green     $23,000  Programming            >18000  <32000
  250. 3  Black     $8,000   Tech Support
  251. 4  Simpson   $25,000  Programming      Name  Income  Department
  252. 5  Thompson  $35,000  Tester
  253.  
  254. Finding Records That Match Criteria X or Criteria Y
  255. ---------------------------------------------------
  256.  
  257. When you want to find records that meet one of two or more criteria,
  258. place your criterion entries into separate rows and then include those
  259. rows in the criteria range. Microsoft Excel treats entries in separate
  260. rows as an "or" clause, finding or extracting records that match one
  261. condition or another.
  262.  
  263. Using the following sample database (the database is defined as A1:C5,
  264. the criteria range is defined as E1:G3, and the extract range is
  265. E4:G4), suppose you want to select those records where either the
  266. Income field is greater than $24,000 or the Department field is equal
  267. to Tech Support. The criteria range is set up such that you will find
  268. or extract the records Black, Simpson, and Thompson; the latter two
  269. have an income greater than $24,000 and Black's Department is Tech
  270. Support.
  271.  
  272. Alternatively, you can use a computed criterion to find and extract
  273. the records. In cell D1, enter the name INCDEPT. In cell D2, enter the
  274. formula:
  275.  
  276. =OR(B2>24000,C2="Tech Support")
  277.  
  278. Since you are testing two separate fields, the first cell reference
  279. within both fields must be used in the formula and they must be
  280. relative references. If you then select cells D1:D2 and choose Set
  281. Criteria from the Data menu, when you find or extract data, the
  282. formula will be applied to each individual record, and only the
  283. records in the database that return TRUE for either one of the
  284. conditions will be found or extracted.
  285.  
  286.   A        B        C             D  E     F       G
  287. -------------------------------------------------------------
  288. 1 Name     Income   Department       Name  Income  Department
  289. 2 Green    $23,000  Programming            >24000
  290. 3 Black    $8,000   Tech Support                   Tech Support
  291. 4 Simpson  $25,000  Programming      Name  Income  Department
  292. 5 Thompson $35,000  Testing
  293.  
  294.  
  295. Specifying Dates as Criteria
  296. ============================
  297.  
  298. If you want to extract all records in a database that match a specific
  299. date, enter that date in the criteria range under the appropriate
  300. field label. If you want to extract all records that are earlier than
  301. or later than a specific date, or if you want to extract all records
  302. that fall within a specified date range, the method to use varies
  303. according to the version of Microsoft Excel you are using.
  304.  
  305.  
  306. Microsoft Excel Version 4.0
  307. ---------------------------
  308.  
  309. In Microsoft Excel version 4.0, use the comparison operators such as
  310. the less than (<) and greater than (>) symbols, followed by the date.
  311. For example, the following criteria in cells F1:F2 will extract all
  312. records in a database with an entry in the Date field earlier than
  313. 3/1/93:
  314.  
  315.      F
  316.    1 Date
  317.    2 <3/1/93
  318.  
  319. Microsoft Excel Versions 3.0 and Earlier
  320. ----------------------------------------
  321.  
  322. In Microsoft Excel versions 3.0 and earlier, when you enter a date
  323. with a comparison operator, the date is evaluated as text rather than
  324. as its underlying serial value. As a result, an attempt to find or
  325. extract records that are greater than or less than a specified date
  326. will result in no records being found or extracted. To use a
  327. comparison operator with a date, the date must either be the serial
  328. value,
  329.  
  330.      F
  331. -------------
  332. 1    Date
  333. 2    <3/1/93
  334.  
  335. a formula that evaluates to a serial value,
  336.  
  337.      F
  338. -------------
  339. 1    Date
  340. 2    "<"&DATE(93,3,1)
  341.  
  342. or a cell reference that contains a date:
  343.  
  344.      F         G
  345.    1 Date      3/1/93
  346.    2 ="<"&G1
  347.  
  348. NOTE: When you use a formula or cell reference, the comparison
  349. operator is entered as text with the formula or reference concatenated
  350. to the end.
  351.  
  352. If you are using the 1900 date system (the default date system for
  353. Microsoft Excel for Windows), when you enter the formula and cell
  354. references, <34029 will be displayed in the cell. The formula,
  355. DATE(93,3,1) evaluates to 34029, as does the cell reference, G1. If
  356. you are using the 1904 date system (the default date system for
  357. Microsoft Excel for the Macintosh), the serial value for 3/1/93 is
  358. 32567. In each of these cases, the criteria range is defined as F1:F2.
  359.  
  360.  
  361. Setting Your Extract Range
  362. ==========================
  363.  
  364. When you extract information from a database, your extract range must
  365. be separate from your database and criteria ranges. The field names in
  366. the extract range must be in a single row (as must the field names at
  367. the top of the database and criteria ranges). To ensure that field
  368. names are identical, use the Copy and Paste commands. Microsoft Excel
  369. will not recognize the extract range if a field name does not exactly
  370. match a field name in the database.
  371.  
  372. When you extract information from a database in Microsoft Excel
  373. versions 2.x, in your extract range, select the field names for the
  374. fields you want to extract, and choose Extract from the Data menu.
  375.  
  376. You can also use this method in Microsoft Excel versions 3.0 and 4.0,
  377. although in these versions of Microsoft Excel you have the option of
  378. setting the extract range from the Data menu. Because this method
  379. creates the reserved defined name "Extract" on the spreadsheet, you do
  380. not have to select the extract field names prior to extracting
  381. records. If you select only the field names when you extract
  382. information, or if you set an extract range in version 3.0 or 4.0 that
  383. refers to the field names alone, each record that matches the current criteria will be extracted and displayed on the
  384. document after you choose Extract from the Data menu.
  385.  
  386. Caution: When you select the field names and choose Extract from the
  387. Data menu or when you've set your extract range by selecting only the
  388. field names and choosing Set Extract from the Data menu, any data
  389. between the field names in your extract range and the last row in your
  390. worksheet will be cleared. This will occur even when no data records
  391. are extracted. To avoid erasing your data, either create your extract
  392. range below or to the right of your data, or restrict the size of your
  393. extract range.
  394.  
  395.  
  396. Restricting the Extract Range
  397. -----------------------------
  398.  
  399. You can restrict the amount of extracted information in several ways.
  400.  
  401. In Microsoft Excel versions 2.x, selecting a range that extends below
  402. the extract field names will restrict the possible number of extracted
  403. records to the selected area. Selecting the field names and the five
  404. rows beneath them, for example, will restrict any extraction to five
  405. records.
  406.  
  407. NOTE: If more records meet the criteria but cannot be displayed due to
  408. this restriction, Microsoft Excel will display an alert message
  409. stating that the extract range is full.
  410.  
  411. In Microsoft Excel versions 3.0 and 4.0, you can use the method above
  412. to select the extract range or, once you select your restricted range,
  413. you can choose Set Extract from the Data menu. This command will
  414. define the selected range with the reserved name "Extract." When you
  415. define the extract range with Set Extract, you can extract records
  416. without first having to select an extract range (because the extract
  417. range is already defined).
  418.  
  419. NOTE: If you set an extract range that includes, for example, five
  420. additional rows beneath the field names, an extraction will produce a
  421. maximum of five retrieved records. If more records meet the criteria
  422. than fit in the selected area, Microsoft Excel will display an alert
  423. message stating that the extract range is full.
  424.  
  425.  
  426. Setting an External Extract Range
  427. ---------------------------------
  428.  
  429. In Microsoft Excel versions 2.x, 3.0, and 4.0, to extract database
  430. information to an external worksheet, do the following:
  431.  
  432. 1. Select your database and choose the Set Database command from the
  433.    Data menu.
  434.  
  435. 2. Copy the field names from the database, and paste them in the
  436.    desired external worksheet.
  437.  
  438. 3. On this external sheet, select the field names and one row beneath
  439.    the field names.
  440.  
  441. 4. From the Data menu, choose Set Criteria.
  442.  
  443. 5. Copy the field names again and paste them in another location in
  444.    the external worksheet. This area will be called the extract range
  445.    and is where the extracted information will be returned. If you are
  446.    using Microsoft Excel version 3.0 or 4.0, select these field names
  447.    and choose Set Extract from the Data menu.
  448.  
  449. 6. From the Formula menu, choose Define Name. In the Name box, type
  450.    DATABASE. In the Refers To box, type the name of the worksheet
  451.    within single quotation marks, and type an exclamation point
  452.    followed by the word "Database." For example:
  453.  
  454.       ='Worksheet1'!Database
  455.  
  456. 7. When you are ready to extract the information:
  457.  
  458. If you are using Microsoft Excel versions 2.x, select the field names
  459.    and choose Extract from the Data menu.
  460.  
  461. If you are using Microsoft Excel versions 3.0 or 4.0, choose Extract
  462.    from the Data menu.
  463.  
  464.        NOTE: You do not need to select the field names if you have set
  465.        them as the extract range as mentioned in step 5 above.
  466.  
  467.   Important: When you extract information to an external worksheet,
  468.   both the worksheet containing the database and the external
  469.   worksheet must be open. If the worksheet containing the database is
  470.   not open, an error message will appear stating that the database
  471.   range is not valid.
  472.  
  473.  
  474. Database Functions
  475. ==================
  476.  
  477. When you use database functions such as DSUM() and DCOUNT(), you can
  478. use any range that has a defined name for the criteria argument. To
  479. specify a range other than the defined criteria range, follow the same
  480. rules for setting the criteria range in a database (as specified in
  481. the "Setting Your Criteria Range" section in this Application Note).
  482. Instead of choosing Set Criteria from the Data menu to define the
  483. criteria, choose Define Name from the Formula menu. Assign a unique
  484. name to the range and use this name for the criteria argument in your
  485. database function.
  486.  
  487. The second argument in a database function, the field argument, can be
  488. an index number. For example, if you want to find the sum of the
  489. entries in the Salary field, and if this field is the second field or
  490. column in your database, you could use either of  the following
  491. formulas:
  492.  
  493. =DSUM(database,"salary",criteria)
  494.  
  495. -or-
  496.  
  497. =DSUM(database,2,criteria)
  498.  
  499. NOTE: For the Find and Extract commands to work correctly, you must
  500. choose Set Criteria to set a criteria range.
  501.  
  502.  
  503. Summarizing a Database with a Table
  504. ===================================
  505.  
  506. You can use a table to create a summary of totals for a database on a
  507. worksheet. Microsoft Excel includes functions that operate on a
  508. database and restricts their operation to the records that meet the
  509. criteria you enter in the worksheet. To use the same database
  510. functions repeatedly on a database, but with different criteria each
  511. time, use the Table command on the Data menu to create a data table.
  512. The data table input values are substituted into the criteria range,
  513. and the results of performing the database function with the different
  514. criteria are displayed in the table.
  515.  
  516. The following sample worksheet uses the DSUM() function in a two-input
  517. table. In the worksheet below, the range A1:C2 is defined as
  518. "Criteria", A4:C15 is defined as "Database", and E4:H8 is the area
  519. occupied by the table. The purpose of this table is to simultaneously
  520. determine gross sales by sales-person and by region.
  521.  
  522.    A      B           C       D    E       F       G       H
  523. ------------------------------------------------------------------
  524. 1  Region Salesperson Sales
  525. 2
  526. 3
  527. 4  Region Salesperson Sales        618     MW      NW      SW
  528. 5  NW     Jones       $50.00       Brown   $80.00  $75.00  $45.00
  529. 6  SW     Smith       $75.00       Jones   $25.00  $50.00  $65.00
  530. 7  SW     Smith       $33.00       Owen    $70.00  $0.00   $90.00
  531. 8  SW     Brown       $45.00       Smith   $10.00  $0.00   $108.00
  532. 9  NW     Brown       $75.00
  533. 10 MW     Brown       $80.00
  534. 11 MW     Jones       $25.00
  535. 12 SW     Jones       $65.00
  536. 13 MW     Smith       $10.00
  537. 14 SW     Owen        $90.00
  538. 15 MW     Owen        $70.00
  539.                                    
  540.                                    
  541. To create a table similar to the previous table:
  542.  
  543. 1. Type the data in columns A, B, and C.
  544.  
  545. 2. Set the database to the range A4:C15, and set the criteria to the
  546.    range A1:C2.
  547.  
  548. 3. To create the table, in cell E4, type the formula
  549.    =DSUM(Database,3,Criteria).
  550.  
  551. 4. In cells E5:E8, type the names, and type the regions in cells
  552.    F4:H4.
  553.  
  554. 5. Select the range of your table, E4:H8, and choose Table from the
  555.    Data menu.
  556.    
  557.    This will bring up a dialog box asking for the Row and Column Input
  558.    Cell. Because the different regions are listed in the top row of
  559.    the table, and the cell in the criteria range in which these
  560.    regions should be entered is $A$2, $A$2 must be the Row Input Cell.
  561.    Following the same reasoning, the Column Input Cell must be $B$2.
  562.    Enter these cell references in the appropriate boxes in the Table
  563.    dialog box and choose OK.
  564.     
  565.     NOTE: If you do not want the value of the formula (618) in cell E4
  566.     to show, select cell E4, choose Number from the Format menu, and
  567.     type the format ;;; (this will hide all values returned by the
  568.     DSUM() function in that cell).
  569.  
  570. For additional information on data tables, please see the Application
  571. Note "Creating and Using Tables," (XE0210). To obtain this Application
  572. Note, call Microsoft Product Support Services at (206) 454-2030. Or,
  573. if you have a modem, you can download this and other Application Notes
  574. by calling the Microsoft Download Service at (206) 936-MSDL.
  575.  
  576.