DISTINCT
A column's distinct values, or a table's distinct rows, without the blank row a relationship may add.
Group: Filter. Compatible with DAX.
Syntax
DISTINCT ( <column> )
DISTINCT ( <table> )
| Parameter | Type | Description |
|---|---|---|
column | Column | A column whose different values in the filter context are wanted. |
table | Table | A table expression whose repeated rows are dropped. |
Returns
Table. The column's different values, or the table's different rows.
Remarks
- For a column, it is
VALUESwithout the blank row a relationship adds for keys the other table lacks. A blank stored in the column itself is one of its values and stays. - It takes any table expression:
DISTINCT ( SELECTCOLUMNS ( ... ) ). Two rows are the same only when every one of their values is. - For a column, only the values the filter context leaves come back.
Examples
Counting the different rows
Pils from Oslo appears twice and counts once.
EVALUATE
VAR Lines =
DATATABLE (
"Product", STRING, "Plant", STRING,
{ { "Pils", "Oslo" }, { "Pils", "Oslo" }, { "IPA", "Bergen" }, { "Pils", "Bergen" } }
)
RETURN
ROW ( "Lines", COUNTROWS ( Lines ), "Different lines", COUNTROWS ( DISTINCT ( Lines ) ) )
| Lines | Different lines |
|---|---|
| 4 | 3 |
The different rows themselves
EVALUATE
VAR Lines =
DATATABLE (
"Product", STRING, "Plant", STRING,
{ { "Pils", "Oslo" }, { "Pils", "Oslo" }, { "IPA", "Bergen" }, { "Pils", "Bergen" } }
)
RETURN
DISTINCT ( Lines )
| Product | Plant |
|---|---|
| Pils | Oslo |
| IPA | Bergen |
| Pils | Bergen |
A column's values under a filter
Only IPA and Cider cost more than 50 a liter: one beer, one cider.
EVALUATE
CALCULATETABLE ( DISTINCT ( Products[Category] ), Products[Price per liter] > 50 )
ORDER BY Products[Category]
| Products[Category] |
|---|
| Beer |
| Cider |