Creating a selection column
All g_functions contain an optional S
parameter, or a selection
column, to tell the g_function whether to include or exclude a row in its
calculations.
A selection column provides a boolean value (1 or 0) for each row in the table. A 1 in a particular row of the selection column tells the g_function to include the row in the calculation. A 0 tells the g_function to omit the row from the calculation. If there is no selection column, the g_function considers all the current rows in the table.
To create a selection column, you need to create a computed column.
In the New operation panel, click Compute. Name and label your computed column, and use the Expression Editor to enter a value expression that returns a 1 or 0. A basic example of a value expression that returns a 1 or 0 is:
store=2
Alternatively, use the Query tab and enter Macro Language code for the new column into the editor. The query should have the following format:
<willbe name="include" value="store=2"/>
The above example returns a 1 for rows in which store
is equal to 2 and
returns a 0 for rows in which store
is not equal to 2.
store is then used for the G
parameter in a
g_function.
G
parameter. A
selection column may also be created for an X
parameter. For instance, the
following creates a selection column that only includes rows where the
sales column contains a value greater than
50.00:<willbe name="include" value="sales>50.00"/>
However, you can also create selection columns based on any column in a table. It doesn't matter if a column will be used as a parameter for a g_function; you can use it as a selection criterion.
<willbe name="firstvalflag" value="g_first1(store;;)"/>
The resulting table is below. Note that the first entry for each store is flagged with a 1 in the firstvalflag column.
You can then use the firstvalflag column as the S
parameter in another g_function.