How To Create A Composite Model In DAX Studio

by | Power BI

In this tutorial, you’ll learn how to create a composite model and use DirectQuery on a Power BI dataset or in Azure Analysis Services.

The previous tutorials have discussed the MEASURE, COLUMN, and TABLE keywords. In some specific cases, the DAX engine automatically writes these keywords even if you didn’t explicitly use them. You’ll learn how to mimic this scenario and understand what’s happening behind the scenes.

Creating A Composite Model: Getting Started

In this demonstration, a view is already created for the Date table. Select the code and execute it.

composite model

You can see that it results in a simple Date table which has the Date, Month, and Calendar Year columns.

Next, publish the data model to the Power BI Service.

composite model

Go to Power BI. Click Get Data and then Power BI datasets.

Choose the Dates Table and then click Create.

Open the Relationships view.

composite model

Create a relationship between the Sales table and the Dates table based on the Sales’ Order Date and the Dates table’s Date. You can do this by dragging Date to the Order Date. Wait for Power BI to create the relationship. Once done, click OK.

You can see that a limited relationship between the Sales Table and Dates Table has been created. A limited relationship is denoted by the symbol below.

composite model

Creating The Query For The Composite Model

Go to the Fields pane, open the Sales Table and create a New Column.

In this new column, write a simple measure. For this example, the new column shows the Order Year.

composite model

Once done, drag and drop the new column into the Power BI canvas.

Convert this into a table and make sure that the Order Year column is used as a row.

composite model

Next, drag and drop the Date from the Dates table. The Date should also be assigned as a row.

composite model

Click on the drop-down arrow for Date and select Count. This will count the number of values in a particular year.

Currently, the table shows the same count value for each year.

This is because the relationship between the Sales table and the Dates table is unidirectional. So, a filter from the Sales Table isn’t applied to the Dates Table.

To fix this, create a new measure.

composite model

This measure will CALCULATE the number of counts in the Dates Table. It will then modify the nature of the relationship using the CROSSFILTER function. The BOTH function ensures that the filter travels both ways.

Drag and drop this new measure onto the table and delete the Date column.

Go to the View tab and click Performance Analyzer. Once the Performance Analyzer pane appears, click Start recording and then Refresh visual.

composite model

Copy the table’s query and go back to DAX Studio.

Viewing The DAX Query & DirectQuery

When you paste the code, a dialogue box will appear asking which queries you want to paste.

Since this is connecting to the Power BI data set using the DirectQuery option, click the Both DAX and Direct Query option.

The code contains two sections. The top portion shows the DAX query executed because of the local model.

composite model

At the bottom, you can see the remote model in the Power BI Service which is executing the DirectQuery.

composite model

This gives you a visual of what’s happening with your DAX code. The engine is trying to create a table using the TABLE keyword. So even if you didn’t use the TABLE and COLUMN keywords to create queries, the engine uses them behind the scenes.

***** Related Links *****
Format DAX Codes Using DAX Studio’s Special Features
Configure Query Settings In Power BI DAX Studio
Connect DAX Studio To Power BI And SSAS


This tutorial shows a basic example of how composite models work in DAX Studio. This is a good representation of what happens behind the scenes.

In this example, the DAX engine uses the TABLE and COLUMN keywords to populate the result of the matrix or visual. So even if you didn’t explicitly use these keywords, the engine is using them behind the scenes to give you the result you need.

All the best,

Enterprise DNA Experts

Related Posts