g_last(G;S;O;X)
Returns the last non-N/A value within a given group.
Function type
Vector only
Syntax
g_last(G;S;O;X)
t_last(X)
Input
| Argument | Type | Description |
|---|---|---|
G |
any | A space- or comma-separated list of column names Rows are in the same group
if their values for all of the columns listed in If If any of the columns listed in |
S |
integer | The name of a column in which every row evaluates to a 1 or 0, which determines
whether or not that row is selected to be included in the calculation If
If any of the values in
|
O |
integer | A space- or comma-separated list of column names that
determine the row order within a particular group If
If any of the values in |
X |
any simple type | A column name |
Return Value
For every row in each group defined by G and ordered by O
(and for those rows where S=1, if specified),
g_last returns the last non-N/A value in the column listed in
X. The result is the same data type as X.
If no rows have valid (non-N/A) values for X, the result is N/A.
g_
(and t_) functions.Sample Usage
<base table="pub.doc.samples.ref.func.g_func_time_series_sample_usage"/> <willbe name="g_last_1" value="g_last(state;include;order;value)"/> <willbe name="g_last_2" value="g_last(state city;include;order;value)"/>

Example
For this example, let's use the table pub.demo.retail.prod.

dept_na and
deptdesc_na column, which have the same
values as the dept and deptdesc
columns but with some N/A values in
them.<willbe name="dept_na" value="if(dept=20;NA;dept)"/>
<willbe name="deptdesc_na" value="if(dept=20;NA;deptdesc)"/><colord cols="dept,deptdesc,dept_na,deptdesc_na"/>
We might assume that g_last would return
29 for the
dept_na column and
"DISPOSABLES" for the
deptdesc_na column, since
g_last returns the last non-N/A value
within a given group. Let's see what we get if we run
g_last on each of these columns:
<willbe name="dept_last" value="g_last(;;;dept_na)"/>
<willbe name="deptdesc_last" value="g_last(;;;deptdesc_na)"/>

We can see from this example that g_last does indeed
return a 29 for the
dept_na column. However,
g_last returns the empty string for the
deptdesc_na column. This is because the
deptdesc_na column is a text column, and
the empty string is not considered to be an N/A value for the
purposes of g_ (and t_)
functions.
g_last to return the last value in
deptdesc_na that was not an empty string,
you could use the S argument with the
g_last(G;S;O;X) function. First, create a
computed column that contains a 1 for
those rows in deptdesc_na that are not
N/A:<willbe name="not_na" value="deptdesc_na<>NA"/>S argument to the
g_last function so that it only considers
those
rows:<willbe name="deptdesc_last_not_na" value="g_last(;not_na;;deptdesc_na)"/>You can see that g_last now returns
"DISPOSABLES" for the
deptdesc_na column:

Additional Information
- The
t_version of this function defaults theGargument and omits theSargument. The default forGis set at table load time based on the organization of the table.
