> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Resource: Items # Type: GroupStage # Action: last # Link: https://dev.wix.com/docs/sdk/business-solutions/data/items/group-stage/last.md ## Description: Finds the last item in the group. The `last()` method refines the aggregation pipeline to find the last item in the group. ## Schema: ```json Method: last(expression, resultFieldName) Description: Finds the last item in the group. The `last()` method refines the aggregation pipeline to find the last item in the group. Method parameters: param name: expression | type: Expression | description: Expression to find the last item in the group. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: avg(expression, resultFieldName) Description: Calculates the average value across all items in the group based on the specified expression. The `avg()` method refines the aggregation pipeline to calculate the average value of the specified expression across all items in the group. Method parameters: param name: expression | type: Expression | description: Expression to calculate the group's average value. The expression must resolve to a number. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: by(expression, key) Description: Specifies how to group items in the result. The `by()` method configures the aggregation pipeline to group items for which the specified `expression` resolves to the same value. The `key` and resolved `expression` determine the result item's unique `_id` property. > **Note**: When `by()` is not called or when it is called with no parameters, all items are placed in a single group. Method parameters: param name: expression | type: Expression | description: Expression to determine the grouping value. Items with matching values are grouped together. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: key | type: string | description: Name of the field in the result that contains the grouping value. Return type: REFERENCE Method: count(resultFieldName) Description: Counts the number of items in the group. The `count()` method refines the aggregation pipeline to count the number of items in the group. Method parameters: param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: first(expression, resultFieldName) Description: Finds the first item in the group. The `first()` method refines the aggregation pipeline to find the first item in the group. Method parameters: param name: expression | type: Expression | description: Expression to find the first item in the group. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: last(expression, resultFieldName) Description: Finds the last item in the group. The `last()` method refines the aggregation pipeline to find the last item in the group. Method parameters: param name: expression | type: Expression | description: Expression to find the last item in the group. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: max(expression, resultFieldName) Description: Finds the maximum value across all items in the group. The `max()` method refines the aggregation pipeline to find the maximum value of the specified field across all the items in the group. Method parameters: param name: expression | type: Expression | description: Expression to find the group's maximum value. Expression must resolve to a comparable value, such as a number or string. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: min(expression, resultFieldName) Description: Finds the minimum value across all items in the group. The `min()` method refines the aggregation pipeline to find the minimum value of the specified field across all the items in the group. Method parameters: param name: expression | type: Expression | description: Expression to find the group's minimum value. Expression must resolve to a comparable value, such as a number or string. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: push(expression, resultFieldName) Description: Collects values from all items in the group into an array. The `push()` method refines the aggregation pipeline to collect values from all items in the group into an array. Method parameters: param name: expression | type: Expression | description: Expression to collect items into an array. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE Method: sum(expression, resultFieldName) Description: Calculates the sum of the specified expression across all items in the group. The `sum()` method refines the aggregation pipeline to calculate the sum of the specified expression across all items in the group. Method parameters: param name: expression | type: Expression | description: Expression to calculate the group's total sum. Expression must resolve to a number. Learn more about using [expressions in aggregation pipelines](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate-pipeline-expressions/introduction.md). param name: resultFieldName | type: string | description: Field to store the result in. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only). Return type: REFERENCE ```