By: Haroon Ashraf || Related Tips: > Analysis Services Development
ProblemAs a SQL Server business intelligence developer, I would like to work directly on a tabular analysis services project using a SQL database sample which must comply with data warehouse sample requirements. How can I prepare a database to be used for tabular analysis?
SolutionThe solution is to convert a SQL database sample into a tabular model sample by making changes in such a way that it looks as if the data model has gone through all the stages of a data warehouse and is ready to be used with a tabular analysis services project.
SQL Database Sample OverviewLet's have a look at the potential SQL database sample to be converted into tabular data model sample.
Sample Database Structure (OfficeSuppliesSampleV2)The sample database covers a common business scenario where customers can place orders using multiple options such as email, phone or in-store to buy products.
The database consists of the following database objects (tables):
Orders Table Product Table Customer Table OrderType Table
The sample database also contains OrdersView and some other database objects which are not important in the context of current article.
Setup Sample Database (OfficeSuppliesSampleV2)Create and populate sample database (OfficeSuppliesSampleV2) using thefollowing scripts.
Test Run Sample Database (OfficeSuppliesSampleV2)Once you have created the SQL database sample, it is worth doing a test run by running the following script:
-- View ordersSELECT
ov.OrderID
,ov.OrderType
,ov.OrderDate
,ov.Customer
,ov.Product
,ov.Quantity
,ov.TotalPrice
FROM OrdersView ov

Adding a Sample Database to Tabular Model Project
Once we have successfully created, populated and quick tested our sample database next thing is to add the sample database to a tabular model project using SQL Server Data Tools (SSDT).
Adding sample database to tabular model project consists of the following steps:
Steps Prerequisites/Supporting Information Creating Analysis Services Tabular Model Project in Visual Studio SQL Server Data Tools (SSDT) for Visual Studio is installed (which must match your Visual Studio version) Choosing Integrated Workspace Integrated Workspace server is available with the latest versions of Visual Studio (For example, Visual Studio 2015 and Visual Studio 2017 offer integrated workspace server) otherwise you have to install Tabular Analysis Server on your dev machine. Compatibility Level If you are using integrated workspace server then setting the compatibility level to SQL Server 2017 (provided your Visual Studio version offers that level of compatibility) makes your project compatible with Azure Analysis Services. Setting up Data Source Specify data source which is SQL Server Database in our case. Providing Credentials Server name followed by your windows account user name and password is provided which impersonates your account.If you are pointing to the (installed) default instance of SQL Server then your PC name is your SQL Server name For example if your pc name is “My-PC” then your server name is “My-PC”. Default instance can also be accessed by simply typing a dot “.”.
The desired database is connected after server and user credentials are validated. Loading Data into Date Model The data is loaded into the Data Model which can be one or more than one database tables (including views). Switching to Diagram View Diagram view shows the tables and the relationships between tables. Converting primary key columns (IDs) into alternate key(s) The primary key columns of SQL database sample is not important (if we are considering a data warehouse compliant sample) inside the data model so we change them into alternate keys so that we can refer to them if required later on. Create Tabular Model Project
This tip assumes you have already installed SQL Server Data Tools (SSDT) and have a basic understanding of creating and managing Analysis Services Tabular Projects.
Open Visual Studio and create a new Analysis Services Tabular Project and name it “OfficeSuppliesSampleV2Tabular” as follows:

Next choose “Integrated workspace” option and latest compatibility level (if possible) and click OK:

Tabular Project is ready as shown in Tabular Model Explorer:

Import SQL Server Sample Database
Click the Database icon on the toolbar and select SQL Server database from the Get Data window:

Next enter the server and database name:

Enter credentials accordingly and carry on without encryption when asked since this is a sample database:

Next select the desired database (OfficeSuppliesSampleV2) and click “OK”:

Loading Data into the Data Model
Select Orders, Customers and Product tables only and click Load button:

Clicking the Load button will load data into tabular data model:

If we look at the model, we can now see the tables loaded into it:

Switching to the Diagram View
From the Model menu Click Model View > Diagram View:

The Diagram View shows tables and their relationships:

Converting IDs into Alternate Keys
The database tables have been successfully loaded into the data model, but there are some key things missing from the model.
If we assume that we are creating a data (warehouse) model which has gone through all the basic stages of data warehouse creation, then we cannot