Code Generator | DAX

DAX GetDistinctValues Function

The 'GetDistinctValues' DAX function retrieves unique values from a specified column in a dataset. It requires the table name and column name parameters. An error is raised if the provided table or column does not exist.


Empty image or helper icon

Prompt

get distinct values from dataset

Answer

/*
Function: GetDistinctValues

This DAX function returns a table with distinct values from a specified column in a dataset.

Parameters:
- tableName: Name of the table containing the column with values
- columnName: Name of the column for which distinct values are to be retrieved

Return Type: Table

Exceptions: 
- If the tableName or columnName provided does not exist in the dataset, an error will be raised.

*/

GetDistinctValues = 
DISTINCT(SELECTCOLUMNS(tableName, "Distinct_Values", columnName))

Usage Example:

Suppose we have a table named 'Sales' with columns 'ProductID', 'Category', 'Quantity', and we want to get distinct values from the 'Category' column.

DistinctCategories = GetDistinctValues("Sales", "Category")

This will return a table with unique values from the 'Category' column in the 'Sales' table.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

The 'GetDistinctValues' DAX function retrieves unique values from a specified column in a dataset. It requires the table name and column name parameters. An error is raised if the provided table or column does not exist.