Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

Extracts the ranked unique value from the values in a column, where where k=1 returns  returns the maximum value, when a specified condition is met. The value for for k must  must be between 1 and 1000, inclusive. Inputs can be Integer or Decimal.

KTHLARGESTUNIQUEIF calculations are filtered by a conditional applied to the group.  

For purposes of this calculation, two instances of the same value are treated as the same value of of k. So, if your dataset contains four rows with column values values 10 , 9 , 9 , and and 8, then KTHLARGEST returns 9 for the the function returns 9 for k=2 and  and 8 for  for k=3.

When used in a pivot transform, the function is computed for each instance of the value specified in the group parameter. See Pivot Transform.

Input column can be of Integer or Decimal type. Non-numeric data in the column is Other values column are ignored. If a row contains a missing or null value, it is not factored into the calculation.

Info

NOTE: When added to a transformation, this function is applied to the current sample. If you change your sample or run the job, the computed values for this function are updated. Transformations that change the number of rows in subsequent recipe steps do not affect the values computed for this step.

To perform a simple kth largest unique calculation without conditionals, use the KTHLARGESTUNIQUE function. See KTHLARGESTUNIQUE Function.

D s-lang-vs-sql

D s
snippetBasic

D code

pivot value:KTHLARGESTUNIQUE(myRating, 3kthlargestuniqueif(POS_Sales, 2, DayOfWeek == 'Saturday') group:postal_code limit:1

Output:

...

 Returns the secondmost value (rank=2) from the POS_Sales column when the DayOfWeek value is Saturday.

D s
snippetSyntax

D code

pivot value:KTHLARGESTUNIQUEkthlargestuniqueif(function_col_ref, limit, ktest_integerexpression) [group:group_col_ref] [limit:limit_count]


ArgumentRequired?Data TypeDescription
function_
col_refYstring
Name of column to which to apply the function
Reference to the column you wish to evaluate.
k_integerYinteger
(positive)
The ranking of the
unique
value to extract from the source column
test_expressionYstringExpression that is evaluated. Must resolve to true or false

D s lang notes

For more information on the the group and  and limit parameters parameter, see see Pivot Transform.d-s-lang-notes

...

col_ref

Name of the column the whose values of which you want wish to calculate use in the meancalculation. Column  Inputs must contain be Integer or Decimal valuesDecimal values.

  • Literal values are not supported as inputs.
  • Multiple columns and wildcards are not supported.

D s
snippetusage

Required?Data TypeExample Value
YesString
(column reference)
that corresponds to the name of the columnmyValues

k_integer

Integer representing the unique ranking of the unique value to extract from the source column. Duplicate values are treated as a single value for purposes of this function's calculation.

Info

NOTE: The value for k must be an integer between 1 and 1,000 inclusive.

  • k=1 represents  represents the maximum value in the column. 
  • If k is greater than or equal to the number of values in the column, the minimum value is returned.
  • Missing and null values are not factored into the ranking of of k.

test_expression

This parameter contains the expression to evaluate. This expression must resolve to a Boolean (true or false) value.

D s
snippetusage

Required?Data TypeExample Value
Yes
Integer (positive)4
String expression that evaluates to true or false(LastName == 'Mouse' && FirstName == 'Mickey')


D s
snippetExamples

Example - Second-most measurements for a specific city

Include Page
EXAMPLE -
KTHLARGEST
KTHLARGESTIF Function
EXAMPLE -
KTHLARGEST
KTHLARGESTIF Function

D s also
labelaggregate