dimension writeback

10
DIMENSION WRITEBACK and CELL WRITEBACK in Analysis Services (Writing Back to the Cube) – Part 1 MSBI Cube pulls data from relational database on the basis of defined processing strategy (Process full, Process Incremental) and storage options (MOLAP, ROLAP and HOLAP). In few situations, we would like to write back directly to cube. This can be achieved by Writeback Functionality in SSAS. In SSAS, you can directly write data to cube dimension and measures which will be reflected in relation data source as well. There are two types of Writeback in SSAS. 1. Dimension Writeback 2. Cell Writeback When dimension data is updated then it is called Dimension Writeback and when measure/ fact data is updated, it is called Cell Writeback . Situations where Writeback will be useful? 1. (Dimension Writeback): For example, In Product dimension case: you want to add new product then it can be added by using Writeback feature or you are going to start new campaign in coming Christmas or want to promotional cost related to existing campaign. Writeback feature is good only for small number of updates because for each DML operation one request will be sent to relational database. It is better to change relation DB and then reprocess cube data. Writeback feature provides great flexibility to users who don’t have direct access to relation DB. 2. (Cell Writeback): Tuples value can be changed while viewing result set. Most prevailing example is budget or forecasting data. By cell Writeback, change budget or forecasting data and see effect on different matrices to analyze business. You can option to commit the change data or rollback it in cube. Dimension Writeback Dimension can be changed in SQL Server management studio as well as in business intelligence development studio. Dimension Writeback has some limitations: 1. Dimension table should be from single table. Snowflake dimension are not supported. 2. Named query and DB Views are not supported.

Upload: prasadnagireddy

Post on 30-Oct-2014

37 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Dimension Writeback

DIMENSION WRITEBACK and CELL WRITEBACK in Analysis Services (Writing Back to the Cube) – Part 1

MSBI Cube pulls data from relational database on the basis of defined processing strategy (Process full, Process Incremental) and storage options (MOLAP, ROLAP and HOLAP).  

In few situations, we would like to write back directly to cube. This can be achieved by Writeback Functionality in SSAS. In SSAS, you can directly write data to cube dimension and measures which will be reflected in relation data source as well. There are two types of Writeback in SSAS.

1. Dimension Writeback 2. Cell Writeback

When dimension data is updated then it is called Dimension Writeback and when measure/ fact data is updated, it is called Cell Writeback.

Situations where Writeback will be useful?

1. (Dimension Writeback): For example, In Product dimension case: you want to add new product then it can be added by using Writeback feature or you are going to start new campaign in coming Christmas or want to promotional cost related to existing campaign. Writeback feature is good only for small number of updates because for each DML operation one request will be sent to relational database. It is better to change relation DB and then reprocess cube data. Writeback feature provides great flexibility to users who don’t have direct access to relation DB. 

2. (Cell Writeback): Tuples value can be changed while viewing result set. Most prevailing example is budget or forecasting data. By cell Writeback, change budget or forecasting data and see effect on different matrices to analyze business. You can option to commit the change data or rollback it in cube.

  Dimension Writeback

Dimension can be changed in SQL Server management studio as well as in business intelligence development studio.  Dimension Writeback has some limitations:

1. Dimension table should be from single table. Snowflake dimension are not supported.2. Named query and DB Views are not supported. 3. In Cube Dimension, Dimension key and name columns properties should be same.

for using in the post , I am creating DimProduct_Writeback table by the help of Adventure Works DW table Dim Product. I can not directly Dim Product because of mentioned limitations.

view plain print ? 1. CREATE TABLE [dbo].[DimProduct_Writeback](  2.  [ProductKey] [int] NOT NULL,  3.  [Color] [nvarchar](15) COLLATE Latin1_General_CS_AS NOT NULL,  4.  [Size] [nvarchar](50) COLLATE Latin1_General_CS_AS NULL,  5.  [SizeRange] [nvarchar](50) COLLATE Latin1_General_CS_AS NULL  6.     )  

view plain print ? 1. Insert into [dbo].[DimProduct_Writeback]  

Page 2: Dimension Writeback

2.  ([ProductKey],  3.  [Color],  4.  [Size] ,  5.  [SizeRange])   6. select [ProductKey],  7.  [Color],  8.  [Size] ,  9.  [SizeRange]  10.   from [dbo].[DimProduct]  

Dimension Writeback cannot write back to identity column so I have created PRODUCTKEY[dbo].[DimProduct_Writeback] table into regular integer column. Let’s create dimension using [FactInternetSales] table will be used as Measure Group.

Cube SnapshotHow will you enable Writeback and How will you write back to cube as well as to   relation database?

In Dimension Properties, set “WriteEnabled” property to True.

Page 3: Dimension Writeback

Once you make "WriteEnabled" Property to TRUE then in browser tab, “Writeback” icon will be enabled.

  Now Dimension can be updated in Dimension Browser tab or by using SQL Server Management Studio Dimension Browser tab.  In this post, We will use BIDS Dimension Browser tab.

Now take key attribute in Hierarchy Menu (“Dim Product Writeback” key attribute in example) and click on Member properties and then on “”Show All)”: 

Result will show all attributes related to key attribute:

Page 4: Dimension Writeback

Now we are ready to Writeback in Cube as well as in relation database. Lets click on “Writeback” icon in menu bar near “Member Properties” and right click on any row in data:

1. CREATE SIBLING: Now We can insert record in dimension. In the example, New product can be inserted by this option.

2. CREATE CHILD: For my example, this option is disabled but if you use “Parent Child Relationship” in your dimension then this will be enabled to insert new child for the parent.

3. DELETE: Record can be deleted from dimension as well as underlying relation table.4. UPDATE: You can directly modify value of any cell by just selecting the cell and entering new

data.

Example of New row insertion:

Page 5: Dimension Writeback

It will create new row in the dimension as well as in the [DimProduct_Writeback] table. 

Let’s understand how events have happened at server level:1. MDX INSERT/DELETE/Update statement to analysis server in form to XMLA2. SQL DML Statement to relational DB3. Processing Dimension and incremental Cube Processing

MDX INSERT/DELETE/Update statement to analysis server in form to XMLA

SQL DML Statement to relational DB  

It sends DML operation to relational database in parametrized query:

Page 6: Dimension Writeback

view plain print ? 1. INSERT INTO [dbo].[DimProduct_Writeback]  2.         ([ProductKey],[Color],[Size],[SizeRange])  3.     VALUES (?,?,?,?)  

Processing Dimension and incremental Cube Processing  Once data has been written back to relational table and cube dimension then it process cube to bring in consistent form and reflects changed data. These events can be observed by SQL Server profiler.

DIMENSION WRITEBACK and CELL WRITEBACK in Analysis Services (Writing Back to the Cube) – Part 2

As I explained in my last post, when you write back to measures then it is called Cell Writeback. Like Dimension Writeback, there are limitations with Cell Writeback also. For enabling Cell Writeback, all measures should have aggregation as SUM in measure group. If measure group contains other aggregations like count, distinct count, max etc. then move them to separate measure group.

Page 7: Dimension Writeback

Cell Writeback is not possible using graphical user interface like we have for dimension Writeback using SQL Server Management Studio (SSMS) or Business intelligence studio (BIDS). It can only be done by writing MDX queries through SSMS. However you can built your own front end application and pass right XMLA script to analysis server.

Let’s understand “how can we implement cell Writeback?”

There are two major steps:1. Enable Cell Writeback for measure group/partition2. Execute MDX queries for changing cell/tuple values for same measure group/partition

1. Enable Cell Writeback for measure group/partition

Go to cube’ Partition tab, right click on measure group partition and select “Writeback Settings…”.

It will open new pop up window, where your changes will be recorded. By default, table name will be WriteTable_.  You can change table name and data source if you want to record in some other table or data source.

Page 8: Dimension Writeback

Once you click "OK", it will create one extra partition (Writeback Partition) for recording changes.  Once you deploy solution, same SQL Server table will be created in Specified data source.

So now Cell Writeback has been enabled. Now let’s change some data in cube.

2. Execute MDX queries for changing cell/tuple values values for same measure group/partition

MSDN Document provides syntax definition for updating cube data.

In example, we have data from 2001 to 2004 in our cube: view plain print ?

1. select  [Dim Product Writeback].[Dim Product Writeback].MEMBERS on 1  2.       ,[Order Date].[Calendar Year].members on 0  3.   from  [Adventure Writeback Cube]  4.    where ([Measures].[Sales Amount])  

If business user has to enter data for 2005 then it can be done by writing UPDATE CUBE statement in SSMS:

view plain print ? 1. Update [Adventure Writeback Cube]     

Page 9: Dimension Writeback

2.    set ([Order Date].[Hierarchy].[Calendar Year].&[2005]  3.         ,[Measures].[Sales Amount]) = 10,000,000  

One more important aspect, whenever user execute UPDATE statement server internally start new session for user with New BEGIN TRANSACTION. These changes will be visible to same user. Only when user COMMIT TRANSACTION by executing COMMIT Statement, it will be visible to others. User can ROLLBACK transactions using ROLLBACK.