DAX Statistical - SAMPLE function



Description

Returns a sample of N rows from the specified table.

Syntax

SAMPLE (<n_value>, <table>, <orderBy_expression>, [<order>], [<orderBy_expression>, 
   [<order>]] …) 

Parameters

Sr.No. Parameter & Description
1

n_value

The number of rows to return as a sample.

It is any DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times (for each row/context).

If a non-integer value (or expression) is entered, the result is cast as an integer.

2

table

Any DAX expression that returns a table of data from where to extract the n_value number of rows.

3

orderBy_expression

Optional.

Any scalar DAX expression where the result value is evaluated for each row of table.

4

order

Optional.

A value that specifies how to sort orderBy_expression values.

0/FALSE: Sorts in descending order of values of orderBy_expression.

1/TRUE: Sorts in ascending order of values of orderBy_expression.

If omitted, default is 0.

Return Value

  • A table consisting of a sample of n_value number of rows, if n_value > 0.
  • An empty table if n_value <= 0.

Remarks

In order to avoid duplicate values in the sample, the table provided as the second parameter should be grouped by the column used for sorting.

In order to avoid duplicate values in the sample, the table provided as the second parameter should be grouped by the column used for sorting.

If no ordering is specified, the sample will be random, not stable, and not deterministic.

Example

= SUMX (SAMPLE (DISTINCTCOUNT (Sales[Month]), Sales,Sales[Salesperson],ASC),
   [Sales Amount]) 
dax_functions_statistical.htm
Advertisements