# LastValue - Script function

LastValue() returns the value that was loaded last from the records defined by the expression, sorted by a group by clause.

Information noteThis function is only available as a script function.

Syntax:

LastValue (LastValue ( expr expr ))

Return data type: dual

Arguments:

Arguments

| Argument | Description |
| --- | --- |
| expr | The expression or field containing the data to be measured. |

Limitations:

If no text value is found, NULL is returned.

Examples and results:

Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in our app to see the result.

To get the same look as in the result column below, in the properties panel, under Sorting, switch from Auto to Custom, then deselect numerical and alphabetical sorting.

| Example | Result | Result with custom sorting |
| --- | --- | --- |
| `TeamData:<br>`<br>`LOAD * inline [`<br>`SalesGroup\|Team\|Date\|Amount<br>`<br>`East\|Gamma\|01/05/2013\|20000<br>`<br>`East\|Gamma\|02/05/2013\|20000<br>`<br>`West\|Zeta\|01/06/2013\|19000<br>`<br>`East\|Alpha\|01/07/2013\|25000<br>`<br>`East\|Delta\|01/08/2013\|14000<br>`<br>`West\|Epsilon\|01/09/2013\|17000<br>`<br>`West\|Eta\|01/10/2013\|14000<br>`<br>`East\|Beta\|01/11/2013\|20000<br>`<br>`West\|Theta\|01/12/2013\|23000<br>`<br>`] (delimiter is '\|');`<br>` `<br>`LastValue1:`<br>`LOAD SalesGroup,LastValue(Team) as LastTeamLoaded  Resident TeamData Group By SalesGroup;` | SalesGroup<br><br>East<br><br>West | LastTeamLoaded<br><br>Beta<br><br>Theta |