Built-in Functions → index

index() is an analytic function that returns the index of each row based on the order of the grouped values. For identical values, the index order is not guaranteed.

The following table illustrates the behavior of the index() analytic function:

CategoryProductMin List Priceindex()
FruitApple0.251
FruitOrange0.352
FruitBanana0.403
FruitLemon0.404
FruitKiwi0.755
FruitPlum0.756
FruitApricot0.757
FruitYellow Melon3.508
FruitCantaloupe3.509
FruitPineapple5.0010

Signature

index(groupBy, orderBy)

index(groupBy(Dimension,...), orderBy(aggregation_function(measure), true/false,...))

The following table illustrates the index() function parameters:

ParameterDescription
groupBy(Dimension,...)Grouping function that specifies which group of data to operate over based on a dimension column, such as Product Category or Subcategory
orderBy()Sorting function that specifies the order of rows based on an aggregation and a boolean value
aggregation_function(measure)Aggregation function, such as min or max, that performs a calculation on a set of values for a measure, such as List Price or Cost, and returns a single value for each set
TrueEnables an ascending order
FalseEnables a descending order

Returns

int representing the index of each value in the column.

Example

Find the index of a product within a product category based on the minimum list price.

index(
groupBy(Prod_Category),
orderBy(
min(list_price),
true
)
)

Use the following steps for detailed instructions on how to use the index() function to create the above query:

Note

In the Cluster Management Console (CMC), you can create a tenant that includes Sample Data. The Sample Data includes the SALES schema.

  • In the Navigation bar, select the Content tab, and then select + New → Add Dashboard.
  • In the Add Dashboard dialog, for Name, enter Product Dashboard, and then select Add.
  • In the Action bar, select + (add icon), or select + Add Insight.
  • In the Insight panel, select Listing Table or V.
  • In Tables, select Aggregated Table.
  • In the Data panel, select Manage Dataset (+).
  • In the Manage Data Sets panel, in Tables, select SALES. Close the panel.
  • From the Data panel, drag and drop the following columns from the PRODUCTS table to the Grouping Dimension tray:
    • Category
    • Product
  • Drag and drop the List Price column from the PRODUCTS table to the Measure tray.
    • If the Properties panel is not already open, select > to the right of the List Price pill to open the panel.
    • In Format, select Dollar Rounded.
  • From the Data panel, drag and drop Add Formula to the Measure tray.
  • The Formula Builder automatically opens:
    • In Search Functions, select the down arrow, and then select Analytic Functions.
    • Double-click the index function, index(groupBy, orderBy), to add the formula to the editor.
    • In the Formula Editor,
      • Replace dimension, ... with Category from the Data panel
      • Replace aggregation_function with min from the Functions panel
      • Replace measure with List Price from the Data panel
      • Replace true/false, ... with true
index(groupBy(SALES.PRODUCTS.PROD_CATEGORY),orderBy(min(SALES.PRODUCTS.PROD_LIST_PRICE),true))
  • Select Validate & Save.
  • In the Measure tray, double-click the New Formula pill and rename it to Index (Min List Price).
  • Name the insight Product List Price and Index.
  • In the Action bar, select Save.