> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemreference/functions/aggregation/last.md).

# Last

{% hint style="info" %}
The **`Last()`** function returns the <mark style="color:green;">last item</mark> in a <mark style="color:blue;">list</mark> or <mark style="color:blue;">concept set</mark>.

For (persistent) lists it now also accepts a list as parameter - only to be used in Kubernetes Runtime 4.2 (not in Shared Europe, Shared APAC or any private runtime 4.1.xxx).

This function is NOT SQL compatible. For more information about SQL compatibility, see our [documentation](/platform/wemreference/sql-compatibility.md).
{% endhint %}

{% hint style="success" %}
Returns the last item in the given <mark style="color:blue;">`list`</mark> or <mark style="color:blue;">`concept_set`</mark>.

Returns <mark style="color:red;">**`Unknown`**</mark> if one of the parameter values is unknown or outside the common valid date boundaries.
{% endhint %}

{% hint style="info" %}
Possible fault message in expression editor: \ <mark style="color:red;">Invalid call to a function: parameter mismatch at position(x,y): Last</mark>

This could mean that there is no field of list used, but only the (reference to a) list.

**For Runtimes Shared EUR, Shared APAC and Private Clouds v4.1.xx**, the Last function needs a **field from list where filter** construction, or if you only want to get the last row of a list, use **`RowId([list]) of [list] where [filter]`**.&#x20;

For Runtimes 4.2, the Last function now also accepts a List as parameter - no longer requiring a specific field.
{% endhint %}

{% hint style="info" %}
First() and Last() on a database list use the RowID for standard sorting - so:\
`First([Name] of [Products])` will get the name-fieldvalue of the **first** item created, and \
`Last([Name] of [Products])` will get the name-fieldvalue of the **last** item created.&#x20;

You can limit/specify the resultlist using the WHERE options, and within that resultlist, the lowest or highest RowID will be returned.

*In future we will add the \[Order By] syntax to WEM Expressions, so you can specify the order yourself in the expression, and then the First and Last will use that sorting.*

In some specific cases if you want the First/Last item based on another fieldvalue, like LastModified, you could use something like

`Last([name] of [List] WHERE [LastModified] = Max([LastModified] of [List]))`
{% endhint %}

### Syntax

<details>

<summary><code>Last(</code><mark style="color:blue;"><code>List(values) or [field] of [list] or [List]</code></mark><code>)</code></summary>

`Last(List("A", "B", "C"))`\
\=>*Result: "C"*

`Last(RowId([list]) of [list] where HasValue([field in list]))`\
\=>*Result: last row in the indicated list where a certain field has a value*

`Last([DateModified] of [list] where HasValue([field in list]))`\
\=>*Result: last DateModified value in the indicated list where a certain field has a value*

`Last([Name] of [Products] WHERE [LastModified] = Max([LastModified] of [Products]))`\
\=>*Result: returns the name of the last modified item in products*

`Last([list] where HasValue([field in list]))`\
\=>*Result: last row in the indicated list where a certain field has a value - **ONLY Runtimes 4.2 and up!***

</details>

### Parameters

<table><thead><tr><th width="180.20869378712746">Name</th><th width="150">Type</th><th width="150" align="center">Required</th><th width="248.15953250810662">Description</th><th data-hidden>Required?</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>values</code></mark></td><td>list or a concept_set</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a collection of values or elements of the same type, or a list of fields from a (persistent) list. </td><td>yes</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wem.io/platform/wemreference/functions/aggregation/last.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
