![1_composite-models-1024x574.png](https://quantinsightsnetwork.com/wp-content/uploads/2024/02/1_composite-models-1024x574-678x381.png)
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](https://blog.enterprisedna.co/wp-content/uploads/2022/09/1_composite-models-1024x574.png)
You can see that it results in a simple Date table which has the Date, Month, and Calendar Year columns.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/2_composite-models-1024x350.png)
Next, publish the data model to the Power BI Service.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/3_composite-models-1024x538.png)
Go to Power BI. Click Get Data and then Power BI datasets.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/4_composite-models-1024x593.png)
Choose the Dates Table and then click Create.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/5_composite-models-1024x563.png)
Open the Relationships view.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/6_composite-models-1024x533.png)
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.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/7a_composite-models.png)
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/7b_composite-models.png)
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](https://blog.enterprisedna.co/wp-content/uploads/2022/09/8_composite-models.png)
Creating The Query For The Composite Model
Go to the Fields pane, open the Sales Table and create a New Column.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/9_composite-models-1024x557.png)
In this new column, write a simple measure. For this example, the new column shows the Order Year.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/10_composite-models-1024x556.png)
Once done, drag and drop the new column into the Power BI canvas.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/11_composite-models-1024x612.png)
Convert this into a table and make sure that the Order Year column is used as a row.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/12_composite-models-1024x612.png)
Next, drag and drop the Date from the Dates table. The Date should also be assigned as a row.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/13_composite-models-1024x393.png)
Click on the drop-down arrow for Date and select Count. This will count the number of values in a particular year.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/14_composite-models-1024x446.png)
Currently, the table shows the same count value for each year.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/15_composite-models.png)
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](https://blog.enterprisedna.co/wp-content/uploads/2022/09/16_composite-models.png)
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.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/17_composite-models.png)
Go to the View tab and click Performance Analyzer. Once the Performance Analyzer pane appears, click Start recording and then Refresh visual.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/18_composite-models-1024x558.png)
Copy the table’s query and go back to DAX Studio.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/19_composite-models.png)
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.
![](https://blog.enterprisedna.co/wp-content/uploads/2022/09/20_composite-models.png)
The code contains two sections. The top portion shows the DAX query executed because of the local model.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/21_composite-models-1024x474.png)
At the bottom, you can see the remote model in the Power BI Service which is executing the DirectQuery.
![composite model](https://blog.enterprisedna.co/wp-content/uploads/2022/09/22_composite-models-1024x348.png)
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
Conclusion
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
Be the first to comment