> 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/first.md).

# First

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

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 <mark style="color:green;">first</mark> 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" %}
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

`First([list] WHERE [LastModified] = Max([LastModified] of [List]))`
{% endhint %}

### Syntax

<details>

<summary><code>First(</code><mark style="color:blue;"><code>list</code></mark><code>)</code></summary>

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

`First([Products] where [Product.Price] > 10)`\
\=>*Result: returns the first row of products that cost more than 10 euro*

`First([Products] WHERE [LastModified] = Max([LastModified] of [Products]))`\
\=>*Result: returns the last modified item in products (first row of products that has been modified last)*

`First()`\
\=>*Result: unknown*

</details>

<details>

<summary><code>First(</code><mark style="color:blue;"><code>concept_set</code></mark><code>)</code></summary>

`First({ Color.Orange, Color.Blue, Color.Red })`\
\=>*Result: Color.Orange*

`First()`\
\=>*Result: unknown*

</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>list</code></mark></td><td>List of elements of the same type</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a list of values or elements of the same type. </td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>concept_set</code></mark></td><td>A list of concepts</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a list of concepts</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/first.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.
