# DAX HANDBOOK4. Table functions

If you wish to follow along, you can find PBIX/Excel files at the bottom of the article.

### Guide Topics (red is currently selected one)

#### Krešimir Ledinski

Microsoft certified expert in the field of Business Intelligence. His biggest passions are DAX, M, and data modeling.

Experienced data analyst. Advanced in SQL, PowerApps and M language.

## What are DAX Table Functions?

Up until now, we used only functions which return scalar values. What is a scalar value? That is a value that can be represented in a single point in a visual. Measures can only return scalar values. If you try to return a table or column with a measure, you will receive an error. But that doesn’t mean you cannot use table functions in measures.

Table functions cannot be used as the final result in a visual, unless in a specific situation where the table contains only a single column and row, therefore is automatically transformed into a scalar. But they play an important role in creating intermediate steps for most calculations. They are especially important for the proper use of the CALCULATE function. That’s why you should try to understand the most important concepts explained in this chapter, even though you might not see the real application for them in your calculations.

## Table Function Types

There are 3 most used types of Table functions.

1. Grouping functions: the family of ALL functions (ALL, ALLSELECTED, ALLEXCEPT, …), VALUES, CROSSJOIN, …
2. Iterative Functions: FILTER, ADDCOLUMNS, SELECTCOLUMNS, …
3. Mixed Functions: SUMMARIZE, GROUPBY, TOPN, …

This is not a general type of Table functions breakdown, but we find it most suitable for explaining the topic.

## DAX Studio

Results of table functions cannot be shown directly in a visual. Because table functions mostly return more than one row/column as result, you need to use an external tools which can query the data model and return table structures. The most widely used tool for querying data models is DAX Studio.
Once you install it, you can use it to connect to the model and write DAX expressions that return tables.

You will use DAX Studio for the following purposes:

• Querying the data model;
• Exporting data from the data model to csv, SQL tables;
• Optimizing measures speed;

DAX Studio is extremely versatile and robust tool used mostly for advanced measure modeling and measures optimization (Query Plan, Server Timings), but that topics are out of scope of this chapter.

We will explain only the basics of how to query the data model:

In the left pane you can see all the tables currently present in your data model (currently we have only one table called Sales)

• We can write queries to retrieve data from the Sales table using the middle window.
• EVALUATE is the required keyword that signals the start of the query.
• After EVALUATE we need to write an expression that returns the table. In the picture above, we used VALUES function to return the distinct list of all colors from Sales[Color] column. The result of the query is shown below the Query window.

Since DAX Studio is used to return table structures from the data model, it cannot directly return the result of a measure. Instead, we must add ROW(“Column”, [Measure]) syntax.

## Simulating Filter Context in DAX Studio

There is no filter context inside of a DAX Studio. If you need to simulate filter context, the easiest way is to use the CALCULATETABLE function.

Here we returned the list of available colors under filter context Sales[SizeRange]=”NA”. There are only 4 different colors with “NA” SizeRange.
We used VALUES function to show how DAX Studio can return tables. In the next article, we will explain the difference between VALUES and ALL functions, which are one of the most widely used grouping table functions.

## Materials

Show All DAX Guide Topics (click to expand)

### We wish to create the best possible content!

If you are a novice looking for a better explanation of any element of the topic, feel free to comment on the part you didn't quite understand!

If you are an expert in DAX and believe certain topic lacks important internals, your comments are more than welcomed!

Subscribe
Notify of
1 Comment
Inline Feedbacks

### OUR SERVICES

Prefer live training or consultations?

### DAX HANDBOOK7. VARIABLES

Variables are used in almost every measure you will create. The reason we introduce them last is that they use all other parts of DAX code to produce faster, more powerful and maintainable code. Variables are like containers of a part of the DAX code which can be used throughout...

### DAX HANDBOOK6.8 ALLSELECTED

Explanation ALLSELECTED is one of the most complex functions in DAX. When used improperly it can lead to unexpected results. As a rule of thumb, you should not use it in iterative functions. It is preferable to use it only as a CALCULATE filter remover, not as a table function....

### DAX HANDBOOK6.7 Lineage

What is Lineage? Lineage is a part of DAX mechanics that enables us to use tables as filter arguments for the CALCULATE function. It’s also used in row2filter context transition and other aspects of the data model that involve filter propagation throughout the model. We can state that lineage is...