# Calculation - Multiply

Multiplies each element by another element or a single numeric value. This tool multiplies the numbers in one table or output by those in another, or to multiply by a single number. If variables are selected, it creates new variable(s) which contain the multiplied values for each case.

## Usage

### Multiply Two Tables

To multiply two tables:

• Select the two tables on your page.
• Use Automate > Browse Online Library > Calculation > Multiply
• Change the Options to determine how to match rows and columns between the two tables, and choose which rows and columns are included in the multiplication (see below).

### Multiply Two Variables

To create a new variable which contains the result of multiplying the values from two variables for each case in the data set:

• Select the two variables under Data Sets.
• Use Automate > Browse Online Library > Calculation > Multiply.

### Multiply Two QuestionsVariable Sets

You can also mutiply one questionvariable set by another when those two questionvariable sets have variables which match. For example, you may have two questionvariable set that both contain scores for the same set of brands, and you wish to multiply the two scores for each brand to create a new metric. In this case, a new questionvariable set is created with one new variable for each matching item, and the values are multiplied for each case in the data set.

To do so:

• Select the two questionvariable sets under Data Sets.
• Use Automate > Browse Online Library > Calculation > Multiply.

Note: It is not possible to update the new variables when the matching between the two input questionvariable sets changes (for example if you merge the scores for two brands together). If you change the number of items in one or both of the questionvariable sets you should repeat the steps above to obtain new multiplied values.

## Examples

The first table shows the number of Google and Microsoft shares someone owns. The second table shows the stock price for both companies over the last four days.

Using Multiply produces a new table which contains the value of the shares over the last four days.

## Options

Multiply the Choose whether you wish the first term of the multiplication to be an output containing one or more numbers, or a single value. When Output is selected, you can choose an output in your document. When Single numeric value is selected you can then type in the desired value.

by the Choose whether you wish the second term of the multiplication to be an output containing one or more numbers, or a single value. When Output is selected, you can choose an output in your document. When Single numeric value is selected you can then type in the desired value.

Automatically match elements Only shown when there are multiple inputs to Input. This controls how and whether matching is done between the labels of the inputs. The default, "Yes - hide unmatched", will look for matching labels in the rows and columns of the inputs before proceeding with the calculation, and any rows/columns that are not contained in all the inputs will not be included in the output. See the Example. For a full description of the matching algorithm, see the Technical Details. "Yes - show unmatched" will also perform matching, but any unmatched rows (columns) will appear in the output as rows (columns) of all missing values. Selecting "No" for this option will cause any labels in the data to be ignored and not perform any matching. Selecting "Custom" will bring up two additional controls that allow for specifying the matching behavior for rows and columns separately.

Match rows Only shown if Automatically match elements is set to "Custom". Specifies the matching behavior when comparing row labels of the inputs. "Yes - show unmatched" and "Yes - hide unmatched" look for exact matches in the row labels in the inputs. "Fuzzy - show unmatched" and "Fuzzy - hide unmatched" perform fuzzy matching so that labels that differ only by a single character are considered to be a match.

Match columns Only shown if Automatically match elements is set to "Custom". The options are the same as Match rows, but control the matching between columns.

Rows to exclude Here you can type in row labels that should be excluded from the calculation.

Columns to exclude As above, but for columns.

## How to apply this QScript

• Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
• Click on the QScript when it appears in the QScripts and Rules section of the search results.

OR

• Select Automate > Browse Online Library.
• Select this QScript from the list.

## Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

• Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
• Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
• Press Edit a Copy (bottom-left corner of the preview).
• Modify the JavaScript (see QScripts for more detail on this).
• Either:
• Run the QScript, by pressing the blue triangle button.
• Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

### Customizing QScripts in older versions

includeWeb('QScript Functions for Calculations');