FirstDiscreteByInvertedIndex
  • 1 Minute to read
  • Dark
    Light
  • PDF

FirstDiscreteByInvertedIndex

  • Dark
    Light
  • PDF

Article summary

General: FirstDiscreteByInvertedIndex

Creates a flag field where the first occurrence of each unique value in the specified field is set to 1 – but derived as if the table by in descending order of the sort field.

Purpose

Use this function to:
  • Reverse sort data before flagging first record that has a unique value
  • Flag the latest occurrence of a value in a Recordset

Return Value

PropertyValue
FieldTypeInteger
FieldSizeLow
DataTypeDiscrete
DataSizeByte


Example Return Value: 0 , 1, null


Parameters

ParameterJSONDescription
Table“targetTable”: “MyTableName”The target table on which the new field will be created
Filter“dataset”: {DataSet_JSON}Optional.   If a filter is applied, records not in the filter recordset will be returned as null.
Function"function":"firstdiscretebyinvertedindex"FirstDiscreteByInvertedIndex
Distinct Key“p1”: “DistinctKeyFieldName”Required.
Supports:
  • DataType: Must be a Discrete DataType from the target table - will not work with continuous fields.

Once the data has been “reverse sorted” by the Sort Field, the first occurrence of each unique value of Distinct Key will be flagged.

If a continuous field needs to be used, it may be possible to derive a discrete field from the continuous field using the CONCAT function. It may be necessary to apply a filter to reduce the number of discrete values. 

Sort Field“p2”:"SortFieldName"Required.
Supports:
  • DataType: Must be a Discrete DataType from the target table - will not work with continuous fields.
Field used to determine the reverse sort order of the Recordset. The first occurrence of Distinct Key in the sorted Recordset will be flagged. 

JSON Sample

{
  "method": "BuildBakedField",
  "project": "D3",
  "targetTable": "transactions",
  "overwrite": true,
  "name": "FD_LastProduct_ByDate",
  "function": "firstdiscretebyinvertedindex",
  "p1": "product",
  "p2": "date"
}

Usage Notes

See Also:   

  • Engineering | Expression Field
  • FirstDiscrete (General Functions)
  • FirstDiscreteByIndex (General Functions)

Example

ExampleDetails
Description
Input
  • Table: = [transactions]
  • Filter: = [No Filter]
  • Function: = FirstDiscreteByInvertedIndex
  • Distinct Key:= product
  • Sort Field:= date
  • Name: =FD_LastProduct_ByDate
Sample





Was this article helpful?