In this blog, we are going to discuss a live connection using a tabular model in Power BI, when to use a tabular model as a source and what the limitations are when we use a tabular model as a source in Power BI.
Power BI has limitations on importing data that is a maximum size of 1 GB. If the data is more than 1 GB, we have two options: One is Direct Query, and another is a live connection.
But, still, again, when we use direct query, we have to deal with performance issues. So, a better choice is creating a tabular model and creating relationships in the model itself using require tables.
If you use a tabular model, you can improve the performance of your report. We have a roles option in the tabular model. Using those roles, we can add some security to our data model.
SO, let’s get started with the tabular model.
Open Visual Studio -> Create New project -> Analysis Services -> Select Tabular -> Analysis Services Tabular Project. -> Model -> Import from Data Sources -> Microsoft SQL Server -> Enter the Server Name and Database Name and click on Test connection to check the connection and Click on Next -> Service account user name and Password-> Select from list of tables and Views to choose data to import:
Select Tables or views which are required in your model and click on Finish.
Now you have a model with all tables, and you can create a relationship between them by clicking on diagram.
Note: We have 3 relationships in the SSAS model. One is one-to-one, another one is one-to-many and the third one is many-to-many.
So, we are all set to deploy our Cube on the server to access it from Power BI.
Go to project, right-click on it and Click on “Process all” and then click on solution, right-click on Project and then click on Build and, once it gives you a success message, click on Deploy Model.
You cannot have a measure table in Power BI, so you have to manage all measures inside the folder using the “Display Folder” property.
You can check your deployed model using SSMS and you can add roles from there, also.
Let’s connect to the model using Power BI.
Open Power BI Desktop -> Click on Get Data -> Select Azure Analysis Services -> Enter the server and Select Model.
This is the first window you will see when you connect to Model. As you can see, there is only a report tab and Create new column, and the manage relationship option is disabled.
SO, all the things related to Column and relationship have to be managed at the model side only.
Above are some limitations using a tabular model as a source.
Now, we will check some tricky reports using a tabular model.
If you are familiar with SSRS you know about report criteria where we display all selected values inside a parameter.
The same thing can be done in Power BI using the below DAX.
Group Name Display = if(ISFILTERED('Sub Group'[Parent Group Name]),CONCATENATEX(ALLSELECTED('Sub Group'[Parent Group Name]),'Sub Group'[Parent Group Name],","),"All")
In the above DAX, we are displaying comma-separated slicer selected values.
I will take one example which is quite tricky and simple, and I have seen many questions related to this in the community.
So, the requirement is that a user wants to select a Date Type and date, and the report will show data according to the selected date and type.
(We have multiple dates from multiple tables, such as invoice date, received date, submit date.)
This is tricky because you can’t have an option to create a table or columns in Power BI when the source is a tabular model.
So, the solution is this: First, you need to create one date table in a model which is not connected with any another table in Tabular Model, and the date type parameter table with required values in the model.
Now, we can write a measure on this to get the required output.
This total will get changed with the selected Date Type and dates.
One more Scenario is this:
When we have only columns to show in table from different dimensions based on selected date type and dates.
Now, this date slicer will not work, as it is not connected to any table, so it will not filter our data.
To achieve such requirements, all we need to do is create a measure as below and add it to the visual level filter.
Date type filter =
SWITCH(SELECTEDVALUE('Parameter Claim Date Type'[Date Type]),"Date Paid",
SUMX('Fact Claim',IF(RELATED('Claim Original Paid Date'[Original Paid Date])>=MIN('Date'[CALENDAR_DATE]) && RELATED('Claim Original Paid Date'[Original Paid Date])<=MAX('Date'[CALENDAR_DATE]),1,0)),
"Date of Service",SUMX('Fact Claim',IF(RELATED('Claim Latest Service Date'[Latest Service Date])>=MIN('Date'[CALENDAR_DATE]) && RELATED('Claim Latest Service Date'[Latest Service Date])<=MAX('Date'[CALENDAR_DATE]),1,0)),