---
schema_version: "1"
id: 3d1543a70625c976af1d9b157126d605fae6ab5f4af4688c0da70f2da50713fe
title: sample
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/reference/bi-saql-statement-sample.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-statement-sample.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 67b04e76aefb3cf4d7de5e84b1fa8988ef605f8d2762e4a159d96d2935cb6570
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# sample

Returns a random sample from a large dataset, where each data point has an equal probability of being selected. This keyword uses the Bernoulli distribution.

## Syntax

```nolang
sample(percentage-size-of-dataset) repeatable(seed)
```

| Parameter    | Description                                                                                                                                                                                                    |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sample`     | Required. Specifies the percentage of the dataset that is returned as a random sample. The percentage size value can be any positive decimal.                                                                  |
| `repeatable` | Optional. To create a random sample deterministically, specify a seed. `sample` returns the same subset of data each time you pass repeatable the same seed value. The seed value can be any positive integer. |

## Usage

Use `sample` to project a query on a representative sample from your dataset, where each data point has an equal probability of being selected. `sample` runs pre-projection.

Add `sample` and `repeatable` after the `load` statement. Any operation performed on the query after the `load` statement affects only the random sample of data. Let’s look at an example.

```nolang
q = load "Opportunity" sample(10) repeatable(1);
q = group q by all;
q = foreach q generate count() as 'count';
q = limit q 2000;

```

| Count of Rows |
| ------------- |
| 453           |

Here, the query returns the row count of the sample, 453—around 10% of the dataset's 4.6k rows. The `repeatable` keyword guarantees that the query always returns the same result. Without the `repeatable` keyword, the query returns a sample of a slightly different size each time you run it. If you modify your dataset and add more data, then `repeatable` doesn’t return the same result.

## group-by Example

This query returns the counts of opportunities for each stage. Since the query operates on 10% of the dataset, the counts for each stage are approximately 1/10 of the original count.

```nolang
q = load "Opportunity" sample(10) repeatable(1);
q = group q by 'StageName';
q = foreach q generate 'StageName', count() as 'count';
q = limit q 2000;
```

| Stage                | Count of Rows |
| -------------------- | ------------- |
| Closed Lost          | 89            |
| Closed Won           | 254           |
| Id. Decision Makers  | 13            |
| Needs Analysis       | 15            |
| Negotiation/Review   | 6             |
| Perception Analysis  | 13            |
| Proposal/Price Quote | 9             |
| Prospecting          | 10            |
| Qualification        | 25            |
| Value Proposition    | 19            |

## filter Example

This query returns only the won opportunities for each stage. Since the query operates on 10% of the dataset, the count for each stage is approximately 1/10 of the original count.

```nolang
q = load "Opportunity" sample(10);
q = filter q by 'IsWon' == "true";
q = group q by 'StageName';
q = foreach q generate 'StageName', count() as 'count';
q = limit q 2000;
```

| Stage      | Count of Rows |
| ---------- | ------------- |
| Closed Won | 275           |

**See Also**

- [Keywords](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-keywords.md)
