Stay organized with collectionsSave and categorize content based on your preferences.
Thepivot_indexfunction can be used intable calculationsto extract and manipulate the value of a pivoted column based on its index (in other words, its position).
Syntax
pivot_index(expression, pivot_index)
Thepivot_indexfunction evaluatesexpressionin the context of the pivot column at the positionpivot_index(1 for first pivot, 2 second pivot, etc.) The function returns null for unpivoted results.
Examples
The following table shows a query that counts the number of orders made in each season of the year. The query includes a pivoted dimension,Products Category, which has the valuesSwimwearandCoats. To compute the total number of orders made in each season across all categories, create aTotal Orders Counttable calculation.
Products Category
Swimwear
Coats
Total Orders Count
Season
Orders Count
Orders Count
Winter
3
671
674
Spring
278
120
398
Summer
840
21
861
Fall
30
432
462
TheTotal Orders Counttable calculation adds the value of the first pivot column to the value of the second pivot column. The formula is:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-23 UTC."],[],[],null,["# pivot_index function\n\nThe `pivot_index` function can be used in [table calculations](/looker/docs/2510/table-calculations) to extract and manipulate the value of a pivoted column based on its index (in other words, its position).\n\nSyntax\n------\n\n**`pivot_index(expression, pivot_index)`**\n\nThe `pivot_index` function evaluates `expression` in the context of the pivot column at the position `pivot_index` (1 for first pivot, 2 second pivot, etc.) The function returns null for unpivoted results.\n\nExamples\n--------\n\nThe following table shows a query that counts the number of orders made in each season of the year. The query includes a pivoted dimension, **Products Category** , which has the values `Swimwear` and `Coats`. To compute the total number of orders made in each season across all categories, create a **Total Orders Count** table calculation.\n\nThe **Total Orders Count** table calculation adds the value of the first pivot column to the value of the second pivot column. The formula is: \n\n pivot_index(${orders.count}, 1) + pivot_index(${orders.count}, 2)\n\nThings to know\n--------------\n\n`pivot_index` cannot be used in a [custom filter](/looker/docs/2510/filtering-and-limiting#custom-filters)."]]