---
title: tail() function
description: tail() limits each output table to the last n rows.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/tail/
estimated_tokens: 1987
product: Flux
version: v0
---

# tail() function

-   Flux 0.39.0+
-   View InfluxDB support

`tail()` limits each output table to the last `n` rows.

`tail()` produces one output table for each input table. Each output table contains the last `n` records before the `offset`. If the input table has less than `offset + n` records, `tail()` outputs all records before the `offset`.

##### Function type signature

```js
(<-tables: stream[A], n: int, ?offset: int) => stream[A]
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### n

(Required) Maximum number of rows to output.

### offset

Number of records to skip at the end of a table table before limiting to `n`. Default is 0.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

-   [Output the last three rows in each input table](#output-the-last-three-rows-in-each-input-table)
-   [Output the last three rows before the last row in each input table](#output-the-last-three-rows-before-the-last-row-in-each-input-table)

### Output the last three rows in each input table

```js
import "sampledata"

sampledata.int()
    |> tail(n: 3)
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

#### Output data

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

### Output the last three rows before the last row in each input table

```js
import "sampledata"

sampledata.int()
    |> tail(n: 3, offset: 1)
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

#### Output data

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |

#### Related

-   [limit() function](/flux/v0/stdlib/universe/limit/)

[transformations](/flux/v0/tags/transformations/)
