Retrieving Tables and Columns Using EVALUATE and SELECT COLUMNS in DAX
In this article, we will learn how to retrieve an entire table,
a single column, and multiple columns using
EVALUATE and SELECTCOLUMNS in DAX.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Is EVALUATE in DAX?
EVALUATE is used in a DAX query to return a table as the result.
A DAX query must return a table, even if that table contains only one column
or one row.
The basic syntax is:
EVALUATE
<Table Expression>
Here, <Table Expression> can be an existing table,
a function that returns a table, or a more complex table expression.
1. Retrieving an Entire Table
Query
EVALUATE
Sales
Step-by-step explanation
Step 1: EVALUATE
EVALUATE tells DAX that we want to return
the result of a table expression.
Step 2: Sales
Sales is the table expression.
Since it is an existing table, DAX returns the table as it is.
What will you get?
The result contains all columns and rows from the
Sales table.
| CustomerKey | Order Quantity | ShipDateKey |
|---|---|---|
| 101 | 5 | 20240101 |
| 102 | 3 | 20240102 |
| 103 | 8 | 20240103 |
The example above is only for illustration.
Your actual result will contain the data available in your Sales table.
EVALUATE Sales returns the complete Sales table.
2. Retrieving a Single Column
Query
EVALUATE
SELECTCOLUMNS(
Sales,
"Customer", Sales[CustomerKey]
)
Step-by-step explanation
Step 1: EVALUATE
We want to return the result of a table expression.
Step 2: SELECTCOLUMNS
SELECTCOLUMNS creates a new table containing
only the columns we specify.
Step 3: Sales
This is the source table from which we want to retrieve data.
Step 4: “Customer”
This is the name we want to give to the output column.
Step 5: Sales[CustomerKey]
This is the column whose values will be returned.
What will you get?
The result contains only one column:
| Customer |
|---|
| 101 |
| 102 |
| 103 |
The output column is named Customer,
even though the original column is named CustomerKey.
Understanding the SELECTCOLUMNS syntax
The first argument of SELECTCOLUMNS is the source table.
The remaining arguments are written as:
"New Column Name", <Column Expression>
SELECTCOLUMNS allows you to select specific columns
and give them new names.
3. Retrieving Multiple Columns
Query
EVALUATE
SELECTCOLUMNS(
Sales,
"Customer", Sales[CustomerKey],
"Qty", Sales[Order Quantity],
"Ship Date", Sales[ShipDateKey]
)
Step-by-step explanation
Step 1: EVALUATE
Returns the result of the table expression.
Step 2: SELECTCOLUMNS
Creates a new table containing only the columns we specify.
Step 3: Sales
Specifies the source table.
Step 4: “Customer”, Sales[CustomerKey]
Creates an output column named Customer
using values from Sales[CustomerKey].
Step 5: “Qty”, Sales[Order Quantity]
Creates an output column named Qty
using values from Sales[Order Quantity].
Step 6: “Ship Date”, Sales[ShipDateKey]
Creates an output column named Ship Date
using values from Sales[ShipDateKey].
What will you get?
| Customer | Qty | Ship Date |
|---|---|---|
| 101 | 5 | 20240101 |
| 102 | 3 | 20240102 |
| 103 | 8 | 20240103 |
The output column names are different from the original column names.
You can retrieve multiple columns by adding more
“Column Name”, Column Expression pairs.
Understanding the Difference
| Query | Result |
|---|---|
| EVALUATE Sales | Returns the entire table |
| SELECTCOLUMNS(Sales, “Customer”, Sales[CustomerKey]) | Returns one selected column |
| SELECTCOLUMNS(Sales, “Customer”, Sales[CustomerKey], “Qty”, Sales[Order Quantity]) | Returns multiple selected columns |
Important Notes
1. EVALUATE returns a table
Even when you retrieve only one column, the result is still a table.
2. SELECTCOLUMNS does not modify the original table
It creates a new table expression for the query result.
The original Sales table remains unchanged.
3. Output column names are customizable
You can use names such as:
"Customer"
"Qty"
"Ship Date"
These names are only for the output of the query.
4. The order of columns follows the query
The columns appear in the same order in which you specify them inside
SELECTCOLUMNS.
📝 Practice Exercise
Try writing a query to retrieve the following columns from the
Sales table:
- CustomerKey
- Order Quantity
- ShipDateKey
Then rename them as:
- Customer
- Quantity
- Shipping Date
Expected Query
EVALUATE
SELECTCOLUMNS(
Sales,
"Customer", Sales[CustomerKey],
"Quantity", Sales[Order Quantity],
"Shipping Date", Sales[ShipDateKey]
)
Conclusion
In this article, we learned how to retrieve tables and columns using DAX.
- EVALUATE returns a table expression.
- EVALUATE Sales returns the complete table.
- SELECTCOLUMNS allows us to select specific columns.
-
We can rename output columns using
“New Name”, Column Expression. - We can retrieve one or multiple columns from a table.
These are the fundamental building blocks for writing DAX queries
and exploring data in tools such as DAX Studio.
Next: We can learn how to retrieve distinct values
using DISTINCT and VALUES.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist