SQL Server 2012 Tabular Models vs. PowerPivot

I recently installed SQL Server 2012 and began exploring the tabular models.  At first glance, they look very similar to PowerPivot and contain much of the same functionality.  In fact, both the tabular model and PowerPivot share the same engine and the DAX language. 

Although on the surface they appear very similar, several notable differences exist.

The following grid lists a few of the differences between the tabular model and PowerPivot:

  Tabular Model PowerPivot
Scalability
  • No specified upper size limit
  • Partitions to process large volumes of data
  • Supports Direct Query and VertiPaq
  • 2 GB Excel file size limit (for uploading to SharePoint)
  • No partitioning
  • VertiPaq only
Manageability SSMS, AMO, ADOMD, XMLA, Deployment Wizard, PowerShell, Integration Services
(Cathy Dumas’s Blog)
Excel / SharePoint
Securability Row level and dynamic security Excel workbook file security
Development Tool Visual Studio Excel

There are several new features common to both PowerPivot and Tabular Models:

  • Hierarchies
  • KPIs
  • Perspectives

If you’d like to see a list of the new features in PowerPivot 2012, check out this link (http://technet.microsoft.com/en-us/library/hh272053(SQL.110).aspx).

Posted in Database and BI, Technology | Tagged , , | Leave a comment

SSIS: Using the Script Component to Obtain an Error Description

In the SSIS data flow, many data flow components provide an ErrorOutput that allows you to route rows that generate errors or truncation to another component in the data flow.  The ErrorOutput path contains the following metadata: ErrorCode, ErrorColumn and Flat File Source Error Output Column.

SNAGHTML5b0de6

  • Flat File Source Error Output Column – The data row that generated the error.
  • ErrorCode – Code associated with the error that occurred.
  • ErrorColumn – Numeric ID of the column that caused the error.

Obtaining the ErrorDescription requires a bit more work, but can be easily accomplished using the data flow Script Component.

The first step is to add a  ‘Script Component’ to your data flow and connect the Error Output as an input to the script component as shown below.

image

Double click on the script component to edit.

Under the ‘Input Columns’ tab, check the ErrorCode column (you may also include additional columns if you wish to use them in subsequent data flow components).  This column is required to obtain the Error Description.  The ‘Usage Type’ should be set to ReadOnly.

image

Next, select the ‘Inputs and Outputs’ tab.  Expand ‘Output 0’ and select ‘Output Columns’. Click the ‘Add Column’ button.  In the ‘Name’ field, enter a descriptive name such as ErrorDescription.  Set the DataType field to string [DT_STR] and the length to 255.

SNAGHTML6dd200

Click on the ‘Script’ tab and then click the ‘Edit Script’ button.

SNAGHTML6f8e1d

Modify the Input0_ProcessInputRow function (this example uses C#)

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
      Row.ErrorDescription = this.ComponentMetaData.GetErrorDescription(Row.ErrorCode);
  }

Posted in Database and BI, Technology | Tagged | Leave a comment

SSIS: Handling Truncation and Data Errors

SSIS provides functionality to handle unexpected data in the data flow.  Data flow errors are often due to invalid data values (e.g. string instead of number) and data truncation. 

Many components in the data flow support error outputs that allow you to control how truncation and errors are handled.  The Error Outputs contain an ErrorCode and ErrorColumn in addition to the data columns in the row that caused the error.  Error outputs can be connected to another component in the data flow (e.g. a flat file destination to log the rows that generated errors).

You can control how data errors and truncation are handled:

1. Double click on the Data Flow component.

2. Select ‘Error Output’.

image

3. In the ‘Error’ and ‘Truncation’ columns, you specify how each scenario should be handled.  You may click in any cell to set the value or select multiple cells and then use the drop-down at the bottom of the window to set the value.

image

The options are:

  • Ignore Failure – The row is routed to the  ‘Success’ / Default output.
  • Redirect Row – The row is routed to the ‘Error’ output.
  • Fail Component – The data flow task fails (this is the default option).

In the example below, the error output is being routed to a script component.  The script component is used to obtain a description of the error based on the error code (this blog post provides more details).  The errors are then routed to a flat file destination.

image

The ‘Flat File Destination’ is configured so the file is overwritten (so it doesn’t grow uncontrollably).

image

Under the “Mappings” tab, the following columns are written to the file.

  • Flat File Source Error Output Column – The data row that generated the error.
  • ErrorCode – Code associated with the error that occurred.
  • ErrorColumn – Numeric ID of the column that caused the error.
  • ErrorDescription – Description of the error that occurred.  The ErrorDescription was obtained in the ‘Script Component’ using the GetErrorDescription function, more details are included in this blog post.

image

Posted in Database and BI, Technology | Tagged | Leave a comment

SSRS: Checking for Divide By Zero Using Custom Code

I encountered a divide-by-zero error while working on an SSRS report and thought the issue could easily be resolved using IIF with code similar to the following:

=IIF(Fields!Denominator.Value = 0, 0, Fields!Numerator.Value/Fields!Denominator.Value)

I soon realized that this does not resolve the issue.  It appears that all parameters  in the IIF function are evaluated regardless if the first parameter evaluates to true or false.  Therefore, the divide-by-zero was still occurring.

After doing some research, I decided that the best option to avoid the divide-by-zero error is to implement custom code.

Note: The following screen shots are from Report Builder 3.0

The first step is to open the Report Properties window.  You can access the report properties by clicking anywhere outside of the report body.

If you still cannot see the Report Properties window, make sure you have the ‘Properties’ option checked in the ‘View’ tab.

image

The Report Properties window is displayed below.  In the Code text box, click the ellipse […].  You may need to click on the Code text box first to see the ellipse button.

image

Next, select ‘Code’ in the left hand menu if it is not already selected.  Paste the code (displayed below screen shot) in the Custom code field.

SNAGHTML9a4f0b7

Function Divide(Numerator as Double, Denominator as Double)
If Denominator = 0 Then
Return 0
Else
Return Numerator/Denominator
End If
End Function

Now that you’ve created the custom code, you can begin to use the code in your report.  The following is an example of how you can use the Divide function in a text box expression:

=Code.Divide(Fields!CurrentYearSales.Value-Fields!PriorYearSales.Value,Fields!PriorYearSales.Value)*100

Posted in Database and BI, Technology | Tagged | Leave a comment

SSIS: Implementing IsNumeric( ) Logic Using the Data Flow Script Component

SSIS does not include an ‘out-of-the-box’ isNumeric( ) function.  Fortunately, this functionality can be implemented using the script component in the data flow.

I am going to make the assumption that readers are familiar with the SSIS script component.  If not, please feel free to read my prior blog post on the subject: SSIS Dataflow Script Component

To implement isNumeric( ) behavior, I used the C# Int32.TryParse method.

TryParse(String, Int32):  Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded.

Here’s a snippet of the code in C#:

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    int BatteryQuantity1Int;

    if (! int.TryParse(Row.BatteryQuantity1Input, out BatteryQuantity1Int))
       BatteryQuantity1Int = 0;   

    //Add an output row and set the column values
    Output0Buffer.AddRow();
    Output0Buffer.ModelNumber = Row.ModelNumberInput;
    Output0Buffer.ModelYear = Row.ModelYearInput;
    Output0Buffer.ModelName = Row.ModelNameInput;

I also came across a blog post by Dustin Ryan where he implements IsNumeric( ) functionality using the Derived Column Transform.  The post is found here.

Posted in Database and BI, Technology | Tagged | Leave a comment