NOS : Certificate in Computer Applications
| Home | Table of Contents |
LESSON 18
DATABASE FUNCTIONS IN LOTUS 1-2-3
18.1 INTRODUCTION
Lotus 1-2-3 provides very powerful database functions under the data command. It permits you to sort, query or parse the data, construct frequency distributions and perform matrix operations. Another very powerful feature of data command is its ability to carry out regression and sensitivity analysis with only a few keystrokes. We shall now see how all this can be done in 1-2-3.
18.2 OBJECTIVES
In this lesson, we will discuss the data command of 1-2-3. By the end of this lesson, you should be able to:
18.3 DATA BASE FUNCTIONS IN 1-2-3
The data command of 1-2-3 permits the user to perform some data base functions on the worksheet created by 1-2-3. When you invoke /Data command, the following options are given to you:
Data
Fill Table Sort Query Distribution Matrix Regression Parse
We shall now discuss the usage of each one of these options.
(a) Fill and Table
/Data Fill command is used to fill a range in the worksheet with numbers having a constant skip factor. This command finds its use in /Data Distribution and /Data Table commands, which we shall study in this lesson. /Data Fill command also finds its use in the preparation of values for the X-range for a graph or for numbering rows and columns.
When you invoke /DF, you are required to mark the range to be filled with numbers and the start, step value and stop for the numbers with which the marked range is to be filled. For example, if you want to fill a range with 5,10, 15, 20------- 65, then . Start = 5, step = 5 and stop = 65.
/Data Table command can be used to create a table of different values a formula takes each time the value of one or two variables occurring in the formula are changed. This command is very useful when performing sensitivity analysis. Because the table constructed by this command typically answer your what-if queries. When you invoke /DT the following menu is presented.
1 2 Reset
We will explain the usage of the above three options with examples.
/DT1: Consider a situation, where a company accepts fixed deposits for the amounts Rs.5000, Rs.10,000 and Rs.20,000. The company wants to make a policy for the interest rate for these amounts. For this purpose the company wishes to calculate the interest payable at 12%, 12.5%, 13% 13.5% and 14% for each of these amounts.
Interest payable = rate of interest ´ amount deposited. To construct a table giving the various amounts of interest payable, the following steps have to be followed:
| A | B | C | D | E | F | |
| 1 | ||||||
| 2 | 5000*A1 | 10000*A1 | 20000*A1 | |||
| 3 | 12% | |||||
| 4 | 12.5% | |||||
| 5 | 13% | |||||
| 6 | 13.5% | |||||
| 7 | 14% | |||||
| 8 | ||||||
| 9 |
Fig. 18.2
The worksheet display changes to:
| A | B | C | D | E | F | |
| 1 | ||||||
| 2 | 5000*A1 | 10000*A1 | 20000*A1 | |||
| 3 | 12% | 600 | 1200 | 2400 | ||
| 4 | 12.5% | 625 | 1250 | 2500 | ||
| 5 | 13% | 650 | 1300 | 2600 | ||
| 6 | 13.5% | 675 | 1350 | 2700 | ||
| 7 | 14% | 700 | 1400 | 2800 | ||
| 8 | ||||||
| 9 |
Fig. 18.3
/DT2: We shall now describe the steps involved in constructing a table where there is one formula dependent on two variables. A table of values, that the formula would take, has to be prepared when corresponding to each value in a set of values for variable 1, variable 2 takes a value from its set of values. The steps are:
IN-TEXT QUESTION 18.1
Fill in the blanks.
(b) Sort
Sorting of data is an important capability of Lotus 1-2-3. /Data Sort command allows the user to sort the data in a specified range of the worksheet up to maximum two levels in either ascending or descending order. You can sort in either alphabetical or numeric order. When you invoke /DS, you will see the following menu.
Sort
Data-Range Primary-Key Secondary Key Reset Go Quit
/Data Sort Data-Range is used to specify the range of data to be sorted.
/Data Sort Primary-Key is used to specify the primary key (i.e., the range of cells) on which the data is to be sorted.
/ Data Sort Secondary-Key is used to specify the secondary key (i.e., the range of cells to be sorted within a particular cell of primary key) for sorting.
/Data Sort Reset resets all the sorting parameters set by /Data Sort command.
/Data Sort Go is used to instruct 1-2-3 to start sorting the data as specified by /DSD and on the primary and secondary (optional) keys as specified by /DSP and /DSS respectively.
/Data Sort Quit quits the sort menu.
We will use the following worksheet as the basis to explain each one of these options:
| A | B | C | D | E | |
| 1 | SALES | ||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | ITEM | SUB-ITEM | UNITS SOLD | PROFIT/UNIT | PROFIT |
| 6 | MEDICINES | FEFOL | 500 | 0.20 | 100 |
| 7 | MEDICINES | CAL-DE-CE | 250 | 0.10 | 25 |
| 8 | MEDICINES | CEBAXIN | 100 | 0.50 | 50 |
| 9 | MEDICINES | DEXORANGE | 8 | 2.00 | 16 |
| 10 | COSMETICS | NAIL-POLISH | 20 | 2.00 | 40 |
| 11 | COSMETICS | LIPSTICK | 15 | 2.00 | 30 |
| 12 | COSMETICS | EYE-LINER | 10 | 1.00 | 10 |
| 13 | COSMETICS | SOAPS | 100 | 0.50 | 50 |
| 14 15 16 |
TOTAL | 1003 | 321 |
Fig. 18.5: Sample Worksheet - 1
Suppose, you want to present all the items in a sorted manner while making sure that the medicinal items occur under the head MEDICINES and cosmetic items under the head COSMETICS. While sorting the data, you would obviously want the data associated with each item (i.e., units sold, profit/unit, profit) to occur with the name of the item. In this example, therefore, the data-range to be sorted, primary key and secondary key will be A6..E13 and B6..B13 respectively. When you specify ranges for primary or secondary key, you are prompted to enter the order of sorting - A or D where A is for ascending and D for descending.
(c) Query
/Data Query is a very useful command of Lotus 1-2-3 whenever you are using 1-2-3 worksheet as database file. /DQ permits the user to find records meeting a specified criterion, copy them to another part of the worksheet and delete them from the current database. When you invoke /DQ, you will see the following menu.
Query
Input Criterion Output Find Extract Unique Delete Reset Quit
We will explain each one of these options using the sample worksheet given in Fig. 18.5.
/Data Query Input permits you to specify the range that has to be searched to answer the queries. In our example, you could specify the range as A6..E13.
/Data Query Criterion command is used to specify the range of cells where the criterion for the query is written. For specifying the criterion, you need to copy the field names (i.e., the description of the columns) to an unused part of the worksheet. You may copy only the field names on which you wish to build a criterion. Suppose that you copy the range A5..E5 to A20..E20 and that you wish to write the criterion for the UNITS SOLD>= 100. To set up the criterion under the cell in which UNITS SOLD is written (i.e., C20) write the formula +C6>=100. Therefore, this formula has to be written in the cell C21. The value of this formula, i.e., 1 (which represents true) appears in C21. You could format the criterion range to present the formulas rather than their values (by /RFT) to make the criterion more readable. Though the formula only specified cell C6, when you execute the query, all cells in the column C of input range are tested. A little later we shall learn how to construct more complicated queries. Therefore, when you invoke /DQC, you will specify the criterion range as A20..E21.
/Data Query Output is the output range where the answers to your queries shall be placed. Before specifying the range for output, you must copy the data fields to an unused part of the worksheet say to G1. If you don't copy all the data fields, to the output range, the data pertaining to the copied fields and satisfying the criterion would appear in the output range. When you invoke /DQO while specifying the output range, include the field names in the range and include enough number of rows and columns to accommodate the data meeting the criterion, say G1..K8.
/Data Query Find finds and highlights the first record that meets the specified criterion in the input range. You can use the down arrow key to highlight the next record which meets the criterion and so on.
/Data Query Extract command copies all the records that meet the criterion, i.e., the output range. Here data in the records with row numbers 6,7,8 and 13 are copied to the range G2..K5.
/Data Query Unique is the same as /DQE but does not copy duplicate records.
/Data Query Delete, when invoked, puts a safety check by giving options Cancel Delete. As the name suggests, this command deletes the records meeting the criterion.
/Data Query Reset resets the input, criterion and output range of the data query.
/Data Query Quit quits the query menu.
We will now discuss the criterion building in a little more detail. Suppose, you want to extract records for which UNITS SOLD>=100 and PRICE>0.25. Then, in addition to writing +C6>=100 in C21, enter the formula +D6>0.25 in D21. Lotus 1-2-3 treats two or more conditions written in the same row with AND between them and the ones in different rows as having OR between them.
It should be noted that
IN-TEXT QUESTION 18.2
(d) Distribution
/Data Distribution command is used to create a frequency distribution of the specified data range. Here you are also required to specify a range of cells in which for constructing the frequency distribution table is located.
For those who are not familiar with frequency distributions, we would briefly explain the term. Suppose you have a number of values. Then frequency distribution tells you precisely how many values fall in each of the specified intervals. Consider the worksheet in Fig 18.5. Suppose that for the number of units sold (i.e., for the range C6..C13 ), we want to know how many items fall between the range 0 to 50, 50 to 100, 100 to 150, 150 to 200, 200 to 250 and above 250. In other words we want to know how many such items are there, for which the number of units sold is less than 50, between 50 and 100 and so on. Let us specify the intervals for frequency distribution in column G. Position the cursor at G1 and invoke /Data Fill. Specify start = 50, step = 50, stop 250. G column appers like this:
| Column | G |
| 1 | 50 |
| 2 | 100 |
| 3 | 150 |
| 4 | 200 |
| 5 | 300 |
Now, invoke /Data Distribution and specify data range as C6..C13, and interval range as G1..G6. Columns G and H of the worksheet will appear like this:
| Column | G | H |
| 1 | 50 | 4 |
| 2 | 100 | 2 |
| 3 | 150 | 0 |
| 4 | 200 | 0 |
| 5 | 300 | 1 |
| 6 | 0 |
Thus the number of items for which the units sold were less than equal to 50 is 4, more than 50 and less than equal to 100 is 2, more than 100 and less than equal to 150 is nil, more than 150 and less than equal to 200 is nil, more than 200 and less than equal to 250 is 1 and more than 250 is also 1.
You must have noticed that the frequencies appear in the cells immediately to the right of the interval range.
(e) Matrix
Matrix, as most of us would know, is a set of numbers arranged in a group of rows and columns. Two matrices can be multiplied provided the number of columns of the first matrix is the same as the number of rows of the second. Also a matrix can be inverted provided it is a square matrix. Also, if one were to multiply a matrix with its inverse, the result would be an identity matrix (i.e., a matrix that has 1 along the principal diagonal and 0's elsewhere). You can multiply two matrices or find the inverse of a matrix using /Data Matrix command. When you invoke /DM, you will see the following menu.
Invert Multiply
/Data Matrix Invert command requires as a parameter a square matrix to be inverted. A square matrix is one where number of rows is equal to the number of columns. You also need to specify the output range for the resulting inverted matrix. In fact specifying the upper left corner of the output range would be sufficed.
/Data Matrix Multiply is used to multiply two matrices. You are required to specify a data range as the first matrix and another data range as the second matrix for multiplication. Also, you have to mark the output range. The largest matrix that can be used for any of these two operations can have 90 rows ´ 90 columns.
IN-TEXT QUESTION 18.3
1. Consider the following worksheet.
| A | B | C | D | E | |
| 1 | 5 | 0 | |||
| 2 | 4 | 5 | |||
| 3 | |||||
| 4 | |||||
| 5 |
(f) Regression
In the business world, Regression analysis is one of the most powerful and widely used analytic methods. It analyses relationship between two sets of data based on a hypothesis.
For example, how your investment on the advertisements affects the sales of your company. You may like to work out the relationship between the two to forecast for your company. Consider the following data:
| A | B | C | D | E | |
| 1 | SALES (Rs.) | AD COSTS(Rs.) | |||
| 2 | 42,000 | 2,100 | |||
| 3 | 30,000 | 1,200 | |||
| 4 | 12,000 | 600 | |||
| 5 | 60,000 | 5,300 | |||
| 6 | 97,000 | 4,960 | |||
| 7 | 48,000 | 2,390 | |||
| 8 | 19,500 | 1,000 | |||
| 9 | 86,000 | 4,800 | |||
| 10 | |||||
| 11 |
Fig. 18.7: Sample Worksheet - 2
We shall use this sample worksheet to explain the various options available under /Data Regression command. When you invoke /DR the following options appear:
Regression
X-Range Y-Range Output-Range Intercept Reset Go Quit
/DRX is used to mark the X-Range, i.e., the independent variable. In our case, we will mark the range B2..B9.
/DRY is used to mark the Y-Range, i.e., range of dependent variable. A2..A9 in this case.
/DRO is used to specify the output range. Move the cursor to A11 and press ENTER
/DRI gives the following two options: Compute Zero
Compute: This option computes the intercept. (see Output in Fig. 18.9)
Zero: The option keeps the intercept at the origin. (see Output in Fig. 18.10)
/DRR may be used to reset the ranges and the intercept marked by /DR.
/DRG instructs 1-2-3 to perform regression analysis and presents the result at the range specified.
/DRQ quits the regression menu.
With the above-mentioned X-Range, Y-Range, Output-Range and Compute Intercept the following results are displayed when /DRG is invoked.
| A | B | C | D | E | F | |
| 1 | SALES (Rs.) | AD COST(Rs.) | ||||
| 2 | 42000 | 2100 | ||||
| 3 | 30000 | 1200 | ||||
| 4 | 12000 | 600 | ||||
| 5 | 60000 | 5300 | ||||
| 6 | 97000 | 4960 | ||||
| 7 | 48000 | 2390 | ||||
| 8 | 19500 | 1000 | ||||
| 9 | 86000 | 4800 | ||||
| 10 | ||||||
| 1112 | REGRESSION OUTPUT: | |||||
| 13 | Constant | 9302.811 | ||||
| 14 | Std Err of Y est | 13336.86 | ||||
| 15 | R squared | 0.834369 | ||||
| 16 | Number of Observations Degrees of Freedom |
8 | ||||
| 17 | 6 | |||||
| 18 | ||||||
| 19 | X Coefficient(s) Std Err of Coefficient(s) |
14.32114 | ||||
| 20 | 2.604906 | |||||
| 21 | ||||||
| 22 | ||||||
Fig. 18.9: Sample Worksheet - 3
When we give the X, Y and Output ranges and Zero intercept, the following results are displayed when /DRG is invoked.
| A | B | C | D | E | F | |
| 1 | SALES (Rs.) | AD COST(Rs.) | ||||
| 2 | 42000 | 2100 | ||||
| 3 | 30000 | 1200 | ||||
| 4 | 12000 | 600 | ||||
| 5 | 60000 | 5300 | ||||
| 6 | 97000 | 4960 | ||||
| 7 | 48000 | 2390 | ||||
| 8 | 19500 | 1000 | ||||
| 9 | 86000 | 4800 | ||||
| 10 | ||||||
| 1112 | REGRESSION OUTPUT: | |||||
| 13 | Constant | 0 | ||||
| 14 | Std Err of Y est | 13479.84 | ||||
| 15 | R squared | 0.802599 | ||||
| 16 | Number of Observations Degrees of Freedom |
8 | ||||
| 17 | 7 | |||||
| 18 | ||||||
| 19 | X Coefficient(s) Std Err of Coefficient(s) |
16.66642 | ||||
| 20 | 1.431649 | |||||
| 21 | ||||||
| 22 | ||||||
Fig. 18.10: Sample Worksheet - 4
Remember that you have to give the Go command to display the result.
(g) Parse
When you import a text file using /File Import command, each row is one single label and hence cannot be manipulated by any of the 1-2-3 commands. /Data Parse command can be used to break the information in each row into 1-2-3 command useable columns. Thus a parsed file contains all the information of the imported text file but broken into columns that can be manipulated by the commands available in 1-2-3.
When you invoke /DP you will see the following menu:
Parse
Format-Line Input-Column Output-Range Reset Go Quit
We will explain the use of each of these options using imported text file in Fig. 18.12..
| A | B | C | D | E | F | |
| 1 | ||||||
| 2 | ||||||
| 3 | This is a .PRN file | |||||
| 4 | ||||||
| 5 | ||||||
| 6 | SALES | JAN 98 | SALES | FEB 98 | ||
| 7 | ***** | ***** | ||||
| 8 | COMMD | UNITS | COMMD | UNITS | ||
| 9 | ||||||
| 10 | C1 | 450 | C1 | 200 | ||
| 11 | C2 | 100 | C2 | 200 | ||
| 12 | C3 | 90 | C3 | 200 | ||
| 13 | C4 | 789 | C4 | 200 | ||
| 14 | 1429 | 800 | ||||
| 15 | ||||||
| 16 | ||||||
| 17 | ||||||
| 18 | ||||||
| 19 | ||||||
| 20 | ||||||
| 21 | ||||||
Fig. 18.12: Sample Worksheet - 5
Format-Line: When you invoke /DPF you will see the options: Create and Edit.
Create: This option creates a format line at the current cell.
Edit: This option edits the format line at the current cell.
A format line is parse spilt indicating the labels, values, etc. In the worksheet under consideration, position the cursor at A10 and invoke /DPFC. The resultant worksheet is displayed in Fig. 18.13.
| A | B | C | D | E | F | |
| 1 | ||||||
| 2 | ||||||
| 3 | This is a .PRN file | |||||
| 4 | ||||||
| 5 | ||||||
| 6 | SALES | JAN 98 | SALES | FEB 98 | ||
| 7 | ***** | ***** | ||||
| 8 | COMMD | UNITS | COMMD | UNITS | ||
| 9 | ||||||
| 10 | *****L >**********V>>**********L>***************V>> | |||||
| 11 | C1 | 450C1 | 200 | |||
| 12 | C2 | 100C2 | 200 | |||
| 13 | C3 | 90C3 | 200 | |||
| 14 | C4 | 789C4 | 200 | |||
| 15 | 1429 | 800 | ||||
| 16 | ||||||
| 17 | ||||||
| 18 | ||||||
| 19 | ||||||
| 20 | ||||||
| 21 | ||||||
Fig. 18.13: Sample Worksheet - 6
Lotus 1-2-3 has made a guess on the kind of information available in the columns and hence how the file should be parsed. In the format line:
L indicates the beginning of label block
V indicates the beginning of value block
> Indicates that continuation of block marked by L, V, D, T or S
* Indicates that blank space is currently not defined but could become a part of the information in the next cell
Input-Column: Having created the format line, you are to specify the data to be parsed. Refer to worksheet in Fig. 18.13. The input data would be A10..F15. Make sure that the format line is included in the input-column.
Output-Range: It is the range where the parsed output should appear. Position the cursor at A10 and press ENTER.
Reset: May be invoked if you want to reset or cancel all the parameters (i.e., format line input-column and output-range).
Go: Parse the specified range.
Quit: Return to READY mode.
After creating the format line and specifying input-column and output-range, if you select Go, you will notice that the information in the rows 10, 11, 12, 13, & 14 is no more single label but labels and values spilt in 1-2-3 readable form.
18.4 WHAT YOU HAVE LEARNT
In this lesson, we learnt the database functions available in 1-2-3. The main points observed were:
/Data Table command of 1-2-3 enables us to carry out sensitivity analysis for the data in the worksheet.
Data in the worksheet can be sorted on two keys: primary and secondary.
Data meeting specified criteria can be formed, extracted or deleted from the database.
Matrix operations and regression analysis can be carried out with only few keystrokes.
18.5 TERMINAL QUESTIONS
18.6 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTION 18.1
1. i. one or more
one
one
two
the first column of the table range below the dependent formula
the first row of the table range to the right of the dependent formula
A2: 5
A3: 9
A4:
A5:
The cells A4 and A5 will remain blank as stop value = 10.
IN-TEXT QUESTION 18.2
1 ITEM UNITS SOLD PROFIT/ UNIT
+C6 >100 +D6>1.00
IN-TEXT QUESTION 18.3
1.
2.