In real world SSAS Tabular projects, you need to run many different testing scenarios to prove your customer that the data in Tabular model is correct. If you are running a Tabular Model on top of a proper data warehouse then your life would be a bit easier than when you build your semantic model on top of an operational database. However it would be still a fairly time-consuming process to run many test cases on Tabular Model, then run similar tests on the data warehouse and compare the results. So your test cases always have two sides, one side is your source database that can be a data warehouse and the other side is the Tabular Model. There are many ways to test the system, you can browse your Tabular Model in Excel, connecting to your Data Warehouse in Excel and create pivot tables then compare the data coming from Tabular Model and the data coming from the Data Warehouse. But, for how many measures and dimensions you can do the above test in Excel?
The other way is to run DAX queries on Tabular Model side. If your source database is a SQL Server database, then you need to run T-SQL queries on the database side then match the results of both sides to prove the data in Tabular Model is correct.
In this post I’d like to share with you a way to automate the DAX queries to be run on a Tabular model.
Straight away, this is going to be a long post, so you can make or take a cup of coffee while enjoying your reading.
While I will not cover the other side, the source or the data warehouse side, it is worth to automate that part too as you can save heaps of times. I’m sure a similar process can be developed in SQL Server side, but, I leave that part for now. What I’m going to explain in this post is just one of many possible ways to generate and run DAX queries and store the results in SQL Server. Perhaps it is not perfect, but, it is a good starting point. If you have a better idea it would be great to share it with us in the comments section below this post.
- SQL Server Analysis Services Tabular 2016 and later (Compatibility Level 1200 and higher)
- An instance of SQL Server
- SQL Server Management Studio (SSMS)
How does it work
What I’m going to explain is very simple. I want to generate and run DAX queries and capture the results. The first step is to get all measures and their relevant dimensions, then I slice all the measures by all relevant dimensions and get the results. At the end I capture and store the results in a SQL Server temp table. Let’s think about a simple scenario:
- you have just one measure, [Internet Sales], from ‘Internet Sales’ table
- The measure is related to just one dimension, “Date” dimension
- The “Date” dimension has only four columns, Year, Month, Year-Month and Date
- you want to slice [Internet Sales] by Year, Month, Year-Month and Date
So you need to write four DAX queries as below:
EVALUATE SUMMARIZE( 'Internet Sales' , Date'[Calendar Year] , "Internet Sales", [Internet Total Sales] )
EVALUATE SUMMARIZE( 'Internet Sales' , 'Date'[Month Name] , "Internet Sales", [Internet Total Sales] )
EVALUATE SUMMARIZE( 'Internet Sales' , 'Date'[Year-Month] , "Internet Sales", [Internet Total Sales] )
EVALUATE SUMMARIZE( 'Internet Sales' , 'Date'[Date] , "Internet Sales", [Internet Total Sales] )
It is easy isn’t it? But, wait. What if you have 10 measures related to 4 dimension and each dimension has 10 columns? That sounds laborious doesn’t it? Well, in real world scenarios you won’t slice all measures by all relevant dimensions, but, you still need to do a lot. What we are going to do is to generate and run the DAX queries and store the results in a table in SQL Server. How cool is that?
OK, this is how it works…
- Creating a Linked Server for SSAS Tabular instance from SQL Server
- Generating DAX queries using Tabular DMVs
- Running the queries through Tabular model and getting/storing the results in a SQL Server temp table