Showing posts with label SQL Server Analysis Service. Show all posts
Showing posts with label SQL Server Analysis Service. Show all posts

Thursday, February 13, 2014

What is MDX, DMX and XMLA - SSAS Languages

These are just definitions and very basic information. You might see that there are 3 kind of language available to work on SSAS via SQL Server Management Studio. They are DMX, MDX and XMLA.

MDX: Multidimensional Expressions, this language is useful to retrieve data from SSAS objects same as T-SQL or SQL in Relational Databases.


DMX: Data Mining Extensions, this language is used for SSAS object, but especially for data mining structure. DMX statements are used to create process, delete, copy, browse, and predict against data mining models.


XMLA: XML for Analysis is a Simple Object Access protocol (SOAP) - based XML protocol, designed specifically for universal data access to any standard multidimensional data source residing on the Web. Microsoft SQL Server Analysis Services implements XMLA per the XMLA 1.1 specification. XMLA is the native protocol for SSAS, used for all interaction between a client application and instance of Analysis Service. Both Analysis Management Objects (AMO) and ADOMD.NET use the XMLA protocol when communicating with an instance of Analysis Service. This XMLA Queries are mainly used for Administrative purposes such as taking backup, moving data, etc.

Cheers!

Tuesday, February 11, 2014

How to create Fact Dimension or Degenerate Dimension

Sometimes additional data in fact table might useful for users such as invoice number, purchase order numbers, some text fields like comments and complaints. When we define dimension based on a fact table item, the dimension is called a fact dimension and also known as degenerate dimension. The reason that we keep the data in fact table instead of having in separate dimension table is the dimension table would grow at the same rate as the fact table, and would just create duplicate data and unnecessary complexity.


For example: In adventure work data base FactInternetSales table has Sales Order Number. User might need to get the sales amount based on SalesOrderNumber.

Let see how to create Fact Dimension for this scenario. Create new dimension.

In Main table select InternetSales, and under key columns add “SalesOrderNumber” and “SalesOrderLineNumber”, under Name column Select SalesOrderLineNumber.

Unchecked all the Related tables

Select Sales Order Number, if you need some more details such as Customer PO Number.

One you create dimension, rename the attribute name as you want. Here I renamed Sales order Number as Item Details, and under name column select the EnglishProductName from product table.




Add the salesOrderNumber again into attribute panel, and set the name as Order Number and Order by Key.

You can choose the storage mode based on the requirement.

Add this new dimension in the cube .

Make sure that this dimension and the Measure Group relationship type as Fact under Dimension usage.

Now you can test the dimension as below.


Cheers!

You might see that parent level member duplicate under leaf level, for this there is a property called “MemberWithData” set as “NonLeafDataHidden” for parent member. By default it set as "NonLeafDataVissible".


Cheers!

Monday, February 10, 2014

Measure Aggregate Functions - SSAS 2012

In SQL Server Analysis Services Enterprise Edition, there are many Aggregate Functions
are available as shown below. In this blog I am going to explain one by one. All the aggregate functions are available only in SSAS Enterprise edition, for example “None” is only available in Enterprise Edition if you try to use in standard edition it will throw an error.


When you create new measure, first thing is you need to select the Aggregation Function that shows as Usage.

Sum: Calculates the sum of values for all child members. This is the default aggregation function.
Count: Retrieves the count of all the child members.
 
Min: Retrieves the lowest value for all child members.
Max: Retrieves the highest value for all child members.
Distinct Count: Retrieves the count of all child members. A few of the more typical application for DISTINCT COUNT analysis are:
  • Sales and Marketing, especially counting distinct number of customers.
  • Insurance claims relating policies to damages. One claim may have many damages.
  • Quality control data relating causes to defects. A defect can be caused by multiple factors.

The below example shows that how distinct count is different from other aggregation functions.


Product Dimension Members
Distinct Customers Count
All products
200
   Hardware
80
                    Computers
70
                    Monitors
60
                    Printers
30
Software
150
                    Home
100
                    Business
100
                    Games
80

In this example, 70 customers bought computers, 30 customers bought printers, and 60 customers bought monitors. However, the total number of customers who bought hardware, according to the result set, is not 160, or 70+60+30, as shown in the table. The query results display an actual count of 80 total hardware customers. The reason for this irregularity is simple: many customers bought more than one product. Some customers bought both computers and monitors, others bought the whole three-piece package, and some replaced just the monitor, and so on. The end result is that there is no way to infer directly from the lower level results what the customer subtotal really is. This discrepancy continues through the upper levels as well: 80 customers bought hardware, 150 bought software, and all together, All Products totals only 200 customers.


None:  No aggregation is performed, and all values for leaf and nonleaf members in a dimension are supplied directly from the fact table for the measure group .if no value can be read from the fact table for a member, the value for that member is set to null.


By Account: calculates the aggregation according to the aggregation function assigned to the account type for a member in an account dimension. If no account type dimension exists in the measure group, treated as the Non aggregation functions.
Account type can be defined by unary operations as below:

In here ~ operator meaning ignore aggregation and + operator meaning add to preceding sibling likewise aggregation will be based on particular column value. As this brought subject, I will cover these details of this on other blog.


Average of Children: (Average over time) this is only along a Time Dimension.
Example creates a measure using the sum aggregation type for Sales Amount; create a Non-Empty value or (count of Row) measure as Count, from these we can calculate a measure as
[Measures].[Sales Amount]/[Measures].[Count].


Another important consideration, which depends on the business scenario, is the type of the Count aggregate. It could be Count of rows (Row Bound) or Count of non-empty values. The difference is whether we want to include or exclude the empty values from our aggregate. Either way, the described technique will work equally well.
FirstChild: Retrieves the value of the first child member.
LastChild: Retrieves the values of the last child member.
FirstNonEmpty : Retrieves the value of the first non-empty child member.
 
LastNoneEpty:  Retrieves the value of the last non-empty child member.

Cheers!

Saturday, February 8, 2014

By Default, a year level was expected. No such level was found in the cube

When you use YTD function in KPI or calculated measures, you might get the error message as “By Default, a year level was expected. No such level was found in the cube”. The reason for this is most of the date dimensions are formed based on pre populated Date Dimension table, so the SSAS Engine itself not able to find the Field which is Year.


The solution for this, have to manually define which Filed is Year filed in Date Dimension table. Simply you can use Business Intelligence Wizard to define the Year filed as shown below.


If not we can define using the field properties “Type” set as relevant Type. The below image shows that a field in the date dimension is been set as Quarter Type.

Cheers!

How to insert Unknown record in Dimension Tables

The following query will be useful for insert Unknown values into Dimension table. here the value is inserting into Area Dimension table, which has identity column as Key Column.


SET IDENTITY_INSERT BusinessIntelligence.DimArea ON
insert into BusinessIntelligence.DimArea
(AreaKey,Area)
VALUES (-1,'Unknown')
SET IDENTITY_INSERT BusinessIntelligence.DimArea OFF

Hope this will help!.

How to update Fiscal / Reporting Period filed value in Date Dimension Table

This blog will help especially those who find difficulty to insert or update Fiscal Date values in Date Dimension table. Very hardly see the Data Warehouse design without Date dimension. In most cases Fiscal Date fields are very, very important to analysis the business data. Normally the Fiscal Date field’s values may vary company to company or country to country. Most cases, the fiscal date or reporting period are predefined in the relational table based on calendar date such as Fiscal Year, Fiscal Semester, Fiscal Quarter, Fiscal Bi-Month, Fiscal Month and Fiscal Week.

Here I have created 2 tables, one is Fiscal Source table which contains Fiscal data and other one is Date dimension table.

The following screen shot shows that the Date Dimension table with Empty Fiscal values. In this table is FullDate is defined as Date, the task is to identify the fiscal values for the particular date.




The following image shows that how the Fiscal Periods are defined based on calendar date. In here, you can see that Fiscal Period is defined by DateFrom and DateTo fields, sometime this field refer as StartDate and EndDate.

In here, I am using SSIS package to do this task. To find date between 2 dates, simple method is use Lookup with modify SQL Statement. Ole DB Source connection for DimDate table.





Use Lookup data flow task, and make it cache mode as partial cache or No cache, otherwise “Modify the SQL command” feature will not be enable.




Once you map the FullDate with DateFrom column, the SQL Command will be shown below.

Enable Modify the SQL Command feature and modify the command as below.

Make sure that Input Column makes it as FullDate and Param direction as Input.




One you have done this, this data flow will pick the appropriate Fiscal values for the particular FullDate.




The below screen shot shows that once you update the Dimension values with Fiscal Data.

Cheers!

Thursday, February 6, 2014

Build, Deploy and Process of SSAS cube

This blog is all about Build, Deploy and Process of SSAS cube.


Firstly, when we build the cube, the build process will create four XML files inside the bin folder. As the names hint at, the asdatabase file is the main object definition file and the three other files contain configuration and deployment metadata.




Secondly, the deployment process will attach the above files to running Server Analysis Service. This deployment can be done by many ways, but more appropriate option for production deployment is deploy by Deployment Wizard Tool, because this tool will allow doing many configuration settings.


The following screenshots show the steps of deployment via Deployment Wizard Tool.







If necessary we can create script as well. This will create XMLA file, which contains all the configurations and related data. The XMLA is stand for “XML for Analysis” open standard supports data access to data source that reside on the World Wide Web. Microsoft SQL Server Analysis Services implements XMLA per the XMLA 1.1 specification. XMLA is a Simple Object Access protocol (SOAP) – based XML protocol, designed for universal data access to any standard multidimensional data source residing on the web.



Finally, the Processing is the step, or series of steps, in which Analysis Service loads data from a relational data source into a multidimensional model. For objects that use MOLAP storage, data is saved on disk in the database file folder. For ROLAP storage, processing occur on demand, in response to MDX query on an object. For object that uses ROLAP storage, processing refers to updating the cache before returning query results.


Processing Objects: Processing affects the following Analysis Service objects: measure groups, partitions, dimensions, cubes, mining models, mining structure, and databases. When an object contains one or more objects, processing the highest-level object causes a cascade of processing all the lower-level objects. For example, a cube typically contains measure groups (each of which contains one or more partitions) and dimensions.  Processing a cube causes processing of all the measure groups within the cube and the constituent dimensions that are currently in an unprocessed state.

While the processing job is working, the affected Analysis Service Objects can be accessed for querying. The processing job works inside a transaction and the transaction can be committed, or rolled back. If the processing job fails, the transaction is rolled back. If the processing job succeeds, an exclusive lock is put on the object when changes are being committed, which means the object is temporarily unavailable for querying or processing. During the committed phase of the transaction, queries can still be sent to the object, but they will be queued until the commit is completed.
Processing stage can be check using the object properties, the below image show the Cube processing stage.





Likewise we can check object wise processing stage. For some object if properties option is not available, then we can use the report for this.






When you process objects in Analysis Services, you can select a processing option, or you can enable Analysis Services to determine the appropriate type of processing. The processing methods made available differ from one object to another, and are based on the type of object. Additionally, the methods are based on what changes have occurred to the object since it was last processed. If you enable Analysis Service to automatically select a process method (Default), it will use the method that returns the object to a fully processed stage in the least time.


Processing Mode: The following table describes the processing methods that are available in Analysis Services, and identifies the objects for which each method is supported.
Mode
Applies to
Description
Process Default
Cubes, databases, dimensions, measure groups, mining models, mining structures, and partitions.
Detects the process state of database objects, and performs processing necessary to deliver unprocessed or partially processed objects to a fully processed state. If you change a data binding, Process Default will do a Process Full on the affected object.
Process Full
Cubes, databases, dimensions, measure groups, mining models, mining structures, and partitions.
Processes an Analysis Services object and all the objects that it contains. When Process Full is executed against an object that has already been processed, Analysis Services drops all data in the object, and then processes the object. This kind of processing is required when a structural change has been made to an object, for example, when an attribute hierarchy is added, deleted, or renamed.
Process Clear
Cubes, databases, dimensions, measure groups, mining models, mining structures, and partitions.
Drops the data in the object specified and any lower-level constituent objects. After the data is dropped, it is not reloaded.
Process Data
Dimensions, cubes, measure groups, and partitions.
Processes data only without building aggregations or indexes. If there is data is in the partitions, it will be dropped before re-populating the partition with source data.
Process Add
Dimensions, measure groups, and partitions
For dimensions, adds new members and updates dimension attribute captions and descriptions.
For measure groups and partitions, adds newly available fact data and process only to the relevant partitions.
Process Update
Dimensions
Forces a re-read of data and an update of dimension attributes. Flexible aggregations and indexes on related partitions will be dropped.
Process Index
Cubes, dimensions, measure groups, and partitions
Creates or rebuilds indexes and aggregations for all processed partitions. For unprocessed objects, this option generates an error.
Processing with this option is needed if you turn off Lazy Processing.
Process Structure
Cubes and mining structures
If the cube is unprocessed, Analysis Services will process, if it is necessary, all the cube's dimensions. After that, Analysis Services will create only cube definitions. If this option is applied to a mining structure, it populates the mining structure with source data. The difference between this option and the Process Full option is that this option does not iterate the processing down to the mining models themselves.
Process Clear Structure
Mining structures
Removes all training data from a mining structure.
Processing Settings : The following table describes the processing settings that are available for use when you create a process operation.

Processing Option
Description
Parallel
Used for batch processing. This setting causes Analysis Services to fork off processing tasks to run in parallel inside a single transaction. If there is a failure, the result is a roll-back of all changes. You can set the maximum number of parallel tasks explicitly, or let the server decide the optimal distribution. The Parallel option is useful for speeding up processing.
Sequential (Transaction Mode)
Controls the execution behavior of the processing job. Two options are available:
· One Transaction. The processing job runs as a transaction. If all processes inside the processing job succeed, all changes by the processing job are committed. If one process fails, all changes by the processing job are rolled back. One Transaction is the default value.
· Separate Transactions. Each process in the processing job runs as a stand-alone job. If one process fails, only that process is rolled back and the processing job continues. Each job commits all process changes at the end of the job.
When you process using One Transaction, all changes are committed after the processing job succeeds. This means that all Analysis Services objects affected by a particular processing job remain available for queries until the commit process. This makes the objects temporarily unavailable. Using Separate Transactionscauses all objects that are affected by a process in processing job to be taken unavailable for queries as soon as that process succeeds.
Writeback Table Option
Controls how writeback tables are handled during processing. This option applies to writeback partitions in a cube, and uses the following options:
· Use Existing. Uses the existing writeback table. This is default value.
· Create. Creates a new writeback table and causes the process to fail if one already exists.
· Create Always. Creates a new writeback table even if one already exists. An existing table is deleted and replaced.
Process Affected Objects
Controls the object scope of the processing job. An affected object is defined by object dependency. For example, partitions are dependent on the dimensions that determine aggregation, but dimensions are not dependent on partitions. You can use the following options:
· False. The job processes the objects explicitly named in the job and all dependent objects. For example, if the processing job contains only dimensions, Analysis Services processes just those objects explicitly identified in the job. If the processing job contains partitions, partition processing automatically invokes processing of affected dimensions. False is the default setting.
· True. The job processes the objects explicitly named in the job, all dependent objects, and all objects affected by the objects being processed without changing the state of the affected objects. For example, if the processing job contains only dimensions, Analysis Services also processes all partitions affected by the dimension processing for partitions that are currently in a processed state. Affected partitions that are currently in an unprocessed state are not processed. However, because partitions are dependent on dimensions, if the processing job contains only partitions, partition processing automatically invokes processing of affected dimensions, even when the dimension is currently in an unprocessed state.
Dimension Key Errors
Determines the action taken by Analysis Services when errors occur during processing. When you select Use custom error configuration, you can select values for the following actions to control error-handling behavior:
· Key error action. If a key value does not yet exist in a record, one of these actions is selected to occur:
o  Convert to unknown. The key is interpreted as an unknown member. This is the default setting.
o  Discard record. The record is discarded.
· Processing error limit. Controls the number of errors processed by selecting one of these options:
o  Ignore errors count. This will enable processing to continue regardless of the number of errors.
o  Stop on error. With this option, you control two additional settings. Number of errors lets you limit processing to the occurrence of a specific number of errors. On error action lets you determine the action when Number of errors is reached. You can select Stop processing, which causes the processing job to fail and roll back any changes, or Stop logging, which enables processing to continue without logging errors. Stop on erroris the default setting with Number of errors set to 0 and On error action set to Stop processing.
· Specific error conditions. You can set the following options to control specific error-handling behavior:
o  Key not found. Occurs when a key value exists in a partition but does not exist in the corresponding dimension. The default setting is Report and continue. Other settings are Ignore error and Report and stop.
o  Duplicate key. Occurs when more than one key value exists in a dimension. The default setting is Ignore error. Other settings are Report and continue and Report and stop.
o  Null key converted to unknown. Occurs when a key value is null and the Key error action is set to Convert to unknown. The default setting isIgnore error. Other settings are Report and continue and Report and stop.
o  Null key not allowed. Occurs when Key error action is set to Discard record. The default setting is Report and continue. Other settings areIgnore error and Report and stop.
When you select Use default error configuration, Analysis Services uses the error configuration that is set for each object being processed. If an object is set to use default configuration settings, Analysis Services uses the default settings that are listed for each option.
Cheers!