---
title: "Sample rows from a table in Strata | Oplema"
description: "Take a random sample, the first or last rows or every Nth row with Sample. Set a row count or percentage, sample within groups or balance classes."
url: "https://oplema.com/docs/strata/prep/sample"
updated: "2026-11-04"
---

# Sample

Keep the first, last, random or every Nth rows, or specific row numbers, as a count or a percentage, optionally within each group. Or balance classes: Undersample reduces every class to the smallest, Oversample duplicates rows up to the largest and Target ratio grows one class to a chosen share. Set Seed to get the same result each time.

**Learn this in context:** [More data tools: when you'd use each one](https://oplema.com/learn/table-to-dashboard/more-data-tools) (Build and publish a dashboard)

## Take a few rows

Manual Input has five people in this order: Lin, Sam, Bea, Ada and Noor. Sample starts in First rows mode with Amount set to 3, keeping Lin, Sam and Bea.

Result
| name | score |
| --- | --- |
| Lin | 8 |
| Sam | 12 |
| Bea | 3 |

1. Change Amount to `2`. The output now contains Lin and Sam, the first two people in the input.
2. Change Mode to `Last rows`. The output now contains Ada and Noor, in that order. Noor's blank score stays NULL.
3. Change Mode to `Random rows`. Sample now selects two rows from anywhere in the table, and the Seed setting appears. Change Seed from `42` to `7` to try another selection.

## When to use

Use Sample to work with part of a table: the first rows, the last rows, a random selection or every Nth row. It can also balance classes for a model. To select rows by a condition, use Filter.

## Read the output

The example keeps three of the five input rows: Lin (`8`), Sam (`12`) and Bea (`3`). Both columns, `name` and `score`, keep their values and types. The other two rows are left out of Sample's output. The input table doesn't change.

Sample has one output. It doesn't give you a separate table of the rows it leaves out.

## First and last follow input order

**First rows** takes rows from the beginning of the input. **Last rows** takes them from the end and keeps their relative order. With Amount set to `2`, Last rows returns Ada followed by Noor, not Noor followed by Ada.

The score values don't decide which rows are kept. If the input order changes, First rows and Last rows can select different people.

## Use a seed for random selection

**Random rows** selects from the whole input table. Each input row can be selected at most once. Don't rely on the sample keeping the input's row order.

The seed makes a random selection repeatable for the same input and run conditions. Changing it can select different rows, but doesn't guarantee a completely different sample. Changes to the input can also change which rows are selected.

To choose rows by a condition instead of a count, use [Filter](https://oplema.com/docs/strata/prep/filter).

## Inputs and outputs

### Inputs

1 port

**In Required**

Accepts: Tables, Geospatial data.

Accepts one connection on this port.

### Outputs

1 port

**Out**

## Configure the block

**Sampling**

Row sampling keeps a subset of rows. Class balance resamples so classes are evenly represented.

Default: `Rows`

Options: Rows, Class balance.

**Mode**

First rows takes from the beginning of the input, Last rows takes from the end, Random rows selects from the whole table, Every Nth row keeps one row at a fixed interval and Row ranges keeps the row positions you list.

Default: `First rows`

Options: First rows, Last rows, Random rows, Every Nth row, Row ranges.

**Amount unit**

Interpret Amount as a row count or a percentage of rows.

Default: `Rows`

Options: Rows, Percent.

**Amount**

With Rows, enter a positive whole number; requests larger than the input return all available rows. With Percent, enter more than 0 and at most 100.

Default: `100`

**Step (N)**

Keep one of every N rows (the 1st, N+1th, 2N+1th,...).

Default: `2`

**Row ranges**

1-based row positions to keep, e.g. 1-10, 25, 50-60.

Default: `1-10`

**Class column**

Column whose values define the classes to balance.

**Method**

Undersample keeps each class down to the smallest class. Oversample duplicates rows so each class matches the largest class. Target ratio grows one class to a chosen share.

Default: `Undersample`

Options: Undersample, Oversample, Target ratio.

**Target class**

The class value to grow (matched as text against the class column).

**Target share (%)**

Desired share of the output made up by the target class (0-100, exclusive). Only grows the class; it's a no-op if the class already exceeds this share.

Default: `50`

**Seed**

Repeats a selection for unchanged input, row order and execution conditions. Changing the seed can select different rows, but samples may overlap.

Default: `42`

**Group By**

Optional columns that sample within each group (e.g. first 5 per customer, 10% per region). Leave empty to sample over all rows.

## Sample FAQs

**What if Amount is larger than the input table?**

Sample returns all available rows. It doesn't add rows or repeat them to reach the requested count.

**Can I set Amount to zero?**

No. With Rows, Amount must be a positive whole number. With Percent, it must be more than 0 and at most 100. Zero and negative values produce an error.

**Does Sample remove rows with missing values?**

No. Missing values don't affect whether a row is selected. For example, Last rows can include Noor even though Noor's score is NULL.

**Does Random rows remove duplicate records?**

No. It selects input rows without replacement, but different input rows can contain the same values. Sample doesn't deduplicate the data.

### Prepare your data. Build it in Strata.

Strata opens in your browser, with no account.

[Open Strata](https://oplema.com/editor?path=%2F%3Fopen%3Dstrata) [About Strata](https://oplema.com/strata)
