SSAS – make cube in 5 minutes

To support my current database team with additional database skills I decided to start some series focused on BI area. This POST describes quick start with Analysis Services – Multidimensional Databases.

I already wrote post regarding Analysis Services (Create SSAS database) and its settings for multidimensional mode. What should be prepared in advance are some relation data (Adventure Works) and Data Tools studio supporting Analysis Services. You can find in my previous post.

GOAL:

Let’s make a simple cube including 1 measure and 2 dimensions.

In short:

  1. Let’s create new project first – Multidimensional SSASCreate Analysis Services Database
  2. Create Data Sources
  3. Create Data Source View
  4. Create Dimensions
  5. Create CUBE
    1. Define measures
    2. Create dimension relationships
  6. Deploy solution to server
  7. To be continued

Create Analysis Services Multidimensional and Data Mining project first.

New project
New project

Define Data Sources. In our case, there is one Data Source to relation database. There could be defined more Data Sources from different connections. In Solution Explorer, right click on Data Sources section and click on New Data Source, define connection info in dialog box and confirm to create Data Source. Solution Explorer with defined Data Source should look like on picture bellow.

Solution explorer Data Source
Solution explorer Data Source

As next step we must define objects for logical database model. Right click on Data Source Views section in Solution explorer and click on new Data Source Views and Wizard to create Data Source Views appears. Select Data Source in next window, Adventure Works DW in our case and you should see dialog with list of objects form your Data Source on left side. Choose objects for your data model and continue with next.

Data Source Wizard
Data Source Wizard

After selection you should have chosen objects on the right side of Select Tables and Views window. We selected DimCustomer, FactInternetSales and DimDate in our case.

Data Source View Wizard
Data Source View Wizard

As last step name Data source View and Data Source View Wizard is finished.

Data Source View Wizard
Data Source View Wizard

In case you have relational layer defined with referential integrity, it should be transferred to the Data Source View. In case that primary and foreign keys are missing you can create logical relationships between tables in Data Source Views. It is possible to create more Data Source Views, in case you have lots of database objects it is good practice to split them according to their logical area.

When above mentioned steps are done you can see the same Solution Explorer as on picture bellow.

Solution explorer - Data Source View
Solution explorer – Data Source View

Let’s check data model in Data Source Views on picture bellow. You can see that relationships were created according to relation layer by default.

Data Source View - model
Data Source View – model

To create our cube, we use Cube Wizard where measures and dimensions are defined.

Cube Wizard
Cube Wizard

To speed up our process, check Use existing tables. In next window, select Fact table to define measures. You can click on Suggest button to check it automatically (based on defined Data Source View).

Cube Wizard - measure
Cube Wizard – measure

To finish Cube Wizard choose dimensions you use in the cube.

Cube Wizard - dimension
Cube Wizard – dimension

Now you should see created Cube and Dimensions in Solution explorer.

By double click on cube you see cube structure work space, with information regarding Measures, Dimensions, Data Source View etc.

Cube structure
Cube structure

On the top menu of the Cube Structure Workspace you can see menu yo can navigate to other sections, like Dimension usage, KPIs, Actions etc. What is interegsting now is to check Dimension usage you defined relationship between facts and dimensions. As you can see Cube Wizard did this task automatically.

Dimension usage
Dimension usage

Now we can deploy our solution to server. Go to Project -> Properties see Configuraion dialog as on picture bellow. In Deployment section set Target Server and Database name. In other options you can set for example Processing Option to specify whether Analysis Services objects should be processed with deployment of the project. Leave Default in our case to Process cube after deployment.

Project Configuration - Deployment
Project Configuration – Deployment

After you confirm above mentoned seting go to solution explorer, right click on project and click on Deploy in context menu on picture bellow.

Deploy
Deploy

After deployment we can Browse deployed and processed cube in Cube Browser – top right menu.

Cube Browser
Cube Browser

As next steps we could extend dimensions by other attributes, try to create Hierarchy, add another dimension, etc.
Lots of scenarios you can try now, but to be continued in next posts.

Incremental Processing

I would like to dedicate this post to SSAS cube incremental processing since it is very interesting approach how proceed your data without a need to process all data in SSAS Cube or all even all data in SSAS database.

On large data volume systems, it could be very useful to do not re-process all data in cubes from the beginning, since with more data coming into your systems it could be very time consuming. Or there could be a request to display data in SSAS cubes more frequently and in production time could be problem to realize Full Processing.

Here I would like to demonstrate the incremental approach for data processing to SSAS cubes and some difficulties you can meet with and you should be aware of.

  • The main assumption is to have cube in processed state to have possibility to add data incrementally. There can be many reasons how to get cube to unprocessed state. Deploying new solution or Fully processed dimensions, when data changed (this will not be needed in scenarios that dimension does not change).
  • Another important thing is that the you should handle the data you are going to process on relation level to do not get duplicities. The data that were already processed in past should not be processed again by incremental processing.

In my simple example I created

  1. Relation database and SSAS database (see post here)
  2. SSIS package for processing data (see post here)

All scripts could be downloadable here.

In processing option of fact table select Process Add for incremental processing (check it in SSAS package or if you are using Management Studio set it there). The other options will be explained and demonstrated in one of next post to complete an overview of SSAS processing options.

Picture 01 - SSIS - Analysis Services processing task - Process Options
Picture 01 – SSIS – Analysis Services processing task – Process Options

Process database with empty data source. See bellow that SSAS dimension is empty.

Picture 02 - Browsing dimension data in Visual studio
Picture 02 – Browsing dimension data in Visual studio

Now put data to dimension table and process it.

INSERT INTO dbo.DIMTest(name)
SELECT 'Test'

Change Process Options to Process Full because. If you leave Process Default it would not add the data to SSAS dimension, since Process Default cause the data processing when there was a change in dimension structures.

Picture 03 - Management Studio - Process Dimension -  Process Options
Picture 03 – Management Studio – Process Dimension – Process Options

You should see some data in your dimension by Browse Dimension using Management Studio.

Picture 04 - Visual Studio - Browsing dimension data
Picture 04 – Visual Studio – Browsing dimension data

Change it in the SSIS package too.

Picture 05 - Visual Studio - Analysis Services processing task
Picture 05 – Visual Studio – Analysis Services processing task

Now let’s try our incremental processing. Put some data to our fact table.

TRUNCATE TABLE dbo.FactTest__Delta
INSERT INTO dbo.FactTest__Delta (dimtest_id)
SELECT 1
INSERT INTO dbo.FactTest(dimtest_id,InsertDateTime)
SELECT dimtest_id,GETDATE()
FROM dbo.FactTest__Delta

Process partition using Process add option. Now you  see error.

Error: 0xC1140017 at Processing Fact, Analysis Services Execute DDL Task: Errors in the metadata manager. The process type specified for the Fact Test partition is not valid since it is not processed.–

From message you can see that our cube partition is in some invalid state and we are not able to process it. Go to Management Studio, right click on partition or cube click on Properties.

Picture 06 - SQL Management studio - object property - Status - State
Picture 06 – SQL Management studio – object property – Status – State

See that cube State property has Unprocessed state assigned. This can happen when you for example deploy new cube solution to the server. In our cases we did not manage any deployment. Another reason could be Full processing of dimensions. When you have changing data in dimensions like we have in our example you should process it, but with Process update options. It will not bring cube to Unprocessed state. Change this option in Management Studio and reprocess the cube/partitions.

Picture 07 - Visual Studio - Analysis Services Processing Task - Dimension - Process Update
Picture 07 – Visual Studio – Analysis Services Processing Task – Dimension – Process Update

Clean the data and repeat previous steps again with Process Options changed to Process Update.

Reprocessing partition with Process Add option you should see data in cube. (Mangament studio -> Right click on Cube object -> Browse cube)

Picture 08 - Visual Studio - Browse cube
Picture 08 – Visual Studio – Browse cube

You can see that now the cube State stayed in Processed state.

Picture 09 - SQL Management Studio - Cube properties - Status State
Picture 09 – SQL Management Studio – Cube properties – Status State

Put another data to dimension and fact table and processed it by created package. Everything works fine, the data were proceeded to the SSAS database.

INSERT INTO dbo.DIMTest (name)
SELECT 'Test 2'
TRUNCATE TABLE dbo.FactTest__Delta
INSERT INTO dbo.FactTest__Delta (dimtest_id)
SELECT 2
INSERT INTO dbo.FactTest(dimtest_id,InsertDateTime)
SELECT dimtest_id,GETDATE()
FROM dbo.FactTest__Delta
Picture 10 - Visual Studio - browse cube data
Picture 10 – Visual Studio – browse cube data
Picture 11 - Visual Studio - browse cube data
Picture 11 – Visual Studio – browse cube data

You can try to comment cleaning delta table to see what happened. You can see that the data were doubled. It is very important to handle delta table with data that were not proceed to cube.

Picture 12 - Visual Studio - browse cube data - duplicity
Picture 12 – Visual Studio – browse cube data – duplicity

Incremental processing is very nice and effective way to proceed data to your Data Warehouse and SSAS database. Of course it depends on your data characteristics, if it can be implemented or it there is a better way how to get data to your cubes. But here I would like to show you simple example how you can manage it trough SSIS package. And remember, you should take care of handling already proceed data and status of your SSAS cube.

Create SSAS database

Here I would like to quickly describe how to easily create
simple SSAS database. If you don’t have Data tools in your studio you can download it here https://bit.ly/32etQGG.

Here are described steps in short:

  1. Create relation database
  2. Create Analysis Services project
  3. Create connection to Data Source
  4. Create Data Source view and put Data Source objects in there
  5. Create dimensions
  6. Create cube, measures and dimensions usage
  7. Process and deploy created SSAS database

Let’s create database structure first. I created one test dimension and one test table for simplicity.

CREATE DATABASE [Test]
CONTAINMENT = NONE ON PRIMARY
( NAME = N'Test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\Test.mdf' , SIZE = 512000KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON ( NAME = N'Test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\Test_log.ldf' , SIZE = 512000KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
USE [Test]
GO
SET ANSI_NULLS ON
GO 
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TABLE [dbo].[FactTest](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [dimtest_id] [int] NULL,
    [InsertDateTime] [datetime] NULL
)
ON [PRIMARY]
GO
 
ALTER TABLE [dbo].[FactTest] WITH CHECK ADD CONSTRAINT [FK__DIMTest_id] FOREIGN KEY([dimtest_id]) REFERENCES [dbo].[DIMTest] ([id])
GO
 
ALTER TABLE [dbo].[FactTest] CHECK CONSTRAINT [FK__DIMTest_id]
GO
SET ANSI_NULLS ON
GO
 
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TABLE [dbo].[DIMTest](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [sysname] NOT NULL,
CONSTRAINT [PK__DIMTest_id] PRIMARY KEY CLUSTERED
(   [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
)
ON [PRIMARY]
 
GO

Now open Microsoft Visual Studio and create New Analysis Services Project.On picture bellow you see Solution Explorer with final solution. I tried to figure out individual steps you should do to create your SSAS database in defined order.

Picture 01 - Visual Studio - Solution Explorer
Picture 01 – Visual Studio – Solution Explorer

First create connection to your Data Source which is SQL Server database in our case. By right clicking mouse on Data Sources section, add New Data Source from context menu.

Picture 02 - Visual Studio - Data source
Picture 02 – Visual Studio – Data source

As next step we have to create Data Source view to get objects we would like to work with. By right clicking mouse on Data Source Views section, add New Data Source View from context menu. Right click on Data Source View surface and select Add/Remove tables from the context menu. Here we select tables we created at the begging. As you can see from menu you can create queries too. Visual studio tries to create relationships between objects you put into Data Source View. It comes from your referential integrity set on your object’s. In case you are missing constraints on your tables or Studio didn’t create from some reasons this relationship you can create or modify it manually (by dragging mouse between objects, or by context menu form Data Source View surface).

Picture 03 - Visual Studio - Data source view
Picture 03 – Visual Studio – Data source view

In next step create dimension DIMTest, and then create dimension usage – create relationship between cube and dimension. By right click on dimension and New dimension from context menu. Dimension Wizard appears. It will navigate you through process of dimension creation. You can choose you would like to create dimension from existing table you have in Data Source View or you generate the dimension. In next steps you are advised to select attributes will be present in the Dimension. Let’s click next on following Dialog windows .

Picture 04 - Visual Studio -Dimension Wizard
Picture 04 – Visual Studio -Dimension Wizard
Picture 05 - Visual Studio -Dimension Wizard - Attributes
Picture 05 – Visual Studio -Dimension Wizard – Attributes

When you are finished, you should see something similar on picture bellow. I will not show other sections like Attribute Relationships etc. Let’s go with simple dimension structure and its attributes.

Picture 06 - Visual Studio -Dimension structure
Picture 06 – Visual Studio -Dimension structure

If we would have another dimension, we would add them in similar way. Because I have only one dimension in my example, I can move to the next step, creating cube – define Measures and Dimension usage. Right click on Cubes section and select New cube.

As in creating dimension scenario we get Cube Wizard helping user to create cube with its attributes. Set Use existing tables option in the next window. Select table, will be used for measure attributes. FactTest table in our scenario.

Picture 07 - Visual Studio - Cube Wizard - Measure Group
Picture 07 – Visual Studio – Cube Wizard – Measure Group

Set Measures we can get from our SSAS cube.

Picture 08 - Visual Studio - Cube Wizard - Measures
Picture 08 – Visual Studio – Cube Wizard – Measures

Select Existing Dimensions we created in one of previous steps.

Picture 09 - Visual Studio - Cube Wizard - Selecting dimension
Picture 09 – Visual Studio – Cube Wizard – Selecting dimension

Finally put a name for our new cube.

Picture 10 - Visual Studio - Cube Wizard - Cube name
Picture 10 – Visual Studio – Cube Wizard – Cube name

Now you should see cube designer window. On the left side Cube structure section there are cube Measures we set. 

Picture 11- Visual Studio - Cube structure - Measures
Picture 11- Visual Studio – Cube structure – Measures

By right click on measure we can get its properties to check operator used for aggregation function of measured data.

Picture 12- Visual Studio - New Measure
Picture 12- Visual Studio – New Measure

In the next section – Dimension usage we set dimension used to work with our cube and its relationships. Our scenario is very simple we add our DIM Test dimension and set Regular relationship with Fact table which is typical for star schema of multidimensional model of SSAS cube.

Picture 13 - Dimension usage- Relationship
Picture 13 – Dimension usage- Relationship

Finally, we should see settings on picture bellow.

Picture 14 - Dimension usage
Picture 14 – Dimension usage

Processing or Deployment settings on picture bellow, by right mouse click in Database section in Solution explorer. Deployment settings are situated in Visual Studio, top menu, Project -> Properties -> Deployment section. Here you set the Destination server and name of SSAS database you deploy.

Picture 15 - Deploy SSAS project
Picture 15 – Deploy SSAS project

I have to notice that it was the easiest and fastest way to create simple SSAS database from scratch. I skipped lots of settings and possibilities which analysis services offers. As you can see on picture bellow there are options to set Calculations, Aggregations, Partitions etc.

Picture 16 - Cube menu
Picture 16 – Cube menu

You can download solution here: ProcessingIncrement.

I would like to describe all settings and features of Analysis Services from more perspectives and used with more scenarios, step by step, in next posts. So, stay tunned!.