---
schema_version: "1"
id: 2bf84a2c13de4590b44bcc3dc1efb33a9f44aeebfc17088e4bec5327ad234688
title: last()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-fn-agg-last.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-fn-agg-last.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: fb699d05a8ad986e5d1b6fbcbeb0a8f25c5976c73ffe48d5e98b8a7be3409d4f
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# last()

Returns the last value in the tuple for the specified field.

Use `last()` to return the last value of a measure or dimension. You can also use `last()` to return the value of a field without grouping by that field.

**note:** If the values are not sorted, the 'last' value could be any value in the tuple.

## Example - Return the Last Industry for an Account Owner

Your reps own opportunities in several industries. You need a list of rep names with their last industry, where industry is sorted alphabetically. Group by account owner and industry, sort by industry, then use `first()` to get the last industry.

```nolang
q = load "DTC_Opportunity_SAMPLE";
q = group q by ('Account_Owner', 'Industry');
q = foreach q generate 'Account_Owner' as 'Account_Owner', 'Industry' as 'Industry';
q = order q by 'Industry';

q = foreach q generate 'Account_Owner' as 'Account_Owner', last('Industry') as 'One Industry';
```

![Diagram showing first function with sorted field.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_fn_agg_last_image.png)

**See Also**

- [first()](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-fn-agg-1st.md)
