Tag Archives: SSAS

Add Linked Server to OLAP Cube in SQL Server

To use the OpenQuery() procedures within SQL Server to query a SQL Server Analysis Services Cube, you need to add a Linked Server with Credentials of a valid Domain User, as below:

USE [master]
GO

/****** Object:  LinkedServer [CUBE_FINANCEV2]    Script Date: 10/15/2019 11:53:16 AM ******/
EXEC master.dbo.sp_addlinkedserver @server = N'CUBE_FINANCEV2', @srvproduct=N'MSOLAP', @provider=N'MSOLAP', @datasrc=N'mp-bi', @catalog=N'Finance-v2'
 /* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'CUBE_FINANCEV2',@useself=N'False',@locallogin=NULL,@rmtuser=N'MUC\mp_BI_SQL_AS',@rmtpassword='########'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'CUBE_FINANCEV2',@useself=N'True',@locallogin=N'MUC\mp_BI_SQL_AS',@rmtuser=NULL,@rmtpassword=NULL
GO

EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'connect timeout', @optvalue=N'45'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'collation name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'use remote collation', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'CUBE_FINANCEV2', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO


To Query the Processing Status or the last date and time of processing of the Cube, you may create and execute the following Stored Procedure (that uses the created Linked Server from above):

USE [DWH]
GO
/****** Object:  StoredProcedure [etl].[GetCubeProcessingStatus]    Script Date: 14.10.2019 18:21:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cordt Bien
-- Create date:		29.05.2019
--
-- Last Modified:	Date, Name (short reason.)
--
-- Description:		Returns the date and time of the last processing of a cube or perspective. May return multiple rows.
--
-- Info:			EXEC etl.GetCubeProcessingStatus 'Finance-v2', NULL
--			OR		EXEC etl.GetCubeProcessingStatus 'Finance-v2', 'Datev-Finance'
-- =============================================
CREATE PROCEDURE [etl].[GetCubeProcessingStatus]
		@cubeDatabaseName sysname = 'Finance-v2',	-- must not be null!
		@cubeOrPerspectiveName sysname = NULL		-- optional to limit returned result to one row.
--WITH EXECUTE AS 'InternalExecutor' -- (IF YOU USE THE "WITH EXECUTE AS" clause, the Execution will fail due to Security Context Exceptions of the Linked Server)
AS
BEGIN
	SET NOCOUNT ON;

	-- Check Preconditions
	BEGIN TRY
		IF @cubeDatabaseName IS NULL RAISERROR('cubeDatabaseName must not be null!', 11, 1);

	END TRY
	BEGIN CATCH	
		EXEC internal.ReThrowError @@PROCID;
		RETURN -1;
	END CATCH

	-- Implementation
	BEGIN TRY

		IF @cubeDatabaseName = 'Finance-v2' BEGIN
			SELECT DatabaseName, CubeOrPerspectiveName, CubeOrPerspectiveDisplayName, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), GETDATE()), LastProcessDate) as LastProcessDate, BaseCubeName 
			FROM OpenQuery(CUBE_FINANCEV2
					, N'SELECT [CATALOG_NAME]  AS DatabaseName,[CUBE_NAME] AS  CubeOrPerspectiveName,[CUBE_CAPTION] AS CubeOrPerspectiveDisplayName,[LAST_DATA_UPDATE] AS LastProcessDate,[BASE_CUBE_NAME] AS BaseCubeName FROM $system.mdschema_cubes WHERE CUBE_SOURCE=1')
			WHERE (@cubeOrPerspectiveName IS NULL OR CAST(CubeOrPerspectiveName as nvarchar(128)) = @cubeOrPerspectiveName);

		END
		ELSE BEGIN
			RAISERROR('A cubeDatabaseName other than "Finance-v2" is currently not supported or implemented! DEV-Info: Add a new linked server to the requested cube and insert it to this stored procedure (etl.GetCubeProcessingStatus).', 11, 1);

			SELECT TOP 0 DatabaseName, CubeOrPerspectiveName, CubeOrPerspectiveDisplayName, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), GETDATE()), LastProcessDate) as LastProcessDate, BaseCubeName 
			FROM OpenQuery(CUBE_FINANCEV2
					, N'SELECT [CATALOG_NAME]  AS DatabaseName,[CUBE_NAME] AS  CubeOrPerspectiveName,[CUBE_CAPTION] AS CubeOrPerspectiveDisplayName,[LAST_DATA_UPDATE] AS LastProcessDate,[BASE_CUBE_NAME] AS BaseCubeName FROM $system.mdschema_cubes WHERE CUBE_SOURCE=1')
			WHERE (@cubeOrPerspectiveName IS NULL OR CAST(CubeOrPerspectiveName as nvarchar(128)) = @cubeOrPerspectiveName);
		END

	END TRY
	BEGIN CATCH	
		EXEC internal.ReThrowError @@PROCID;
		RETURN -2;
	END CATCH
END

SSAS: How to Sort parent Hierarchy Members of a Dimension by another Attribute

Scenario: You have a small Dimension containing a Hierarchy. You need all the child members as well as the parent members to be sorted.

Solution excerpt: Add the Sort Attribute by which the Parent Attribute should be ordered by as a new Attribute Relationship to the Dimension and then set the OrderBy property to Attribute Key and the OrderByAttribute to the Sort Attribute

Example

  • Parent Attribute: “PuL
  • Child Attribute: “BwaZeileKey
  • Child Sort Attribute: “Sortierung
  • Parent Sort Attribute: “PulSortierung
Extract of BwaZeileDim which is joined to PulDim that contains the PulSortierung

Result

See how the parent members are sorted by a userdefined key attribute and not by name

Fehler im OLAP-Speichermodul: Ein doppelter Attributschlüssel wurde bei der Verarbeitung gefunden

Fehler im OLAP-Speichermodul: Ein doppelter Attributschlüssel wurde bei der Verarbeitung gefunden:
Tabelle: TABELLE,
Spalte: SPALTENNAMEINTABELLE,
Wert: 0.
Das Attribut ist ‘ATTRIBUTENAMEINDIMENSION‘.

Mögliche Lösung:

Gehe zu ATTRIBUTENAMEINDIMENSION und entferne die Name-/ValueColumn-Einträge.

Ursache m.M.n: “Bug/Fehlverhalten” in SSAS

Weitere Hilfe, Warnungsfehler in Hierarchien hier:

https://social.msdn.microsoft.com/Forums/sqlserver/de-DE/91e6b21c-e9ad-43ea-8eb8-d6b5f543d27d/ssas-defaulteigenschaften-von-dimensionen-fhren-zu-warnungen

Analysis Services Tabular Project Dialogs in SSDT-BI

About

This tutorial gives you an overview of common dialogs and windows used to configure Analysis Services Tabular Projects.

Initial Dialogs

Create a New Project

New Analysis Services Tabular Project Dialog

The created file will be named TabularProject1.smproj.

Tabular Model Designer (Choose a Connection)

Tabular Model Designer

Further information on Compatibility Levels MSDN here.

Model.bim Properties window

Model.bim Properties

  • Build Action: Compile | None
  • Copy To Output Directory: Do not copy | Copy always | Copy if newer
  • Data Backup: Back up to disk | Do not back up to disk

If enabled: An ABF file is automatically created when a BIM file is saved. For further information on how to a restore a .abf file see mssqltips here. For contents of the backuped .abf file see MSDN here.

  • Direct Query Mode: On | Off

Benefits if enabled: Data will always be up-to-date. Data sets can be huge (larger than RAM of the SSAS instance). May be faster due to query acceleration in the data source (xVelocity column indexes for example). Security can be enforced (for example row-level security in RDBMS database). Complex formulas might be faster if the back-end can optimize the query plan. Restrictions: All your data in the Tabular Model must come from a single relational data source (either SQL Server, Oracle or Teradata). You must not use data from other sources. If you need data from elsewhere you first have to create a DWH that contains all data. Then you can use this DWH as the only source for your Tabular Model. Excel in DirectQuery mode: MDX queries from Excel to a Tabular Model is only supported in SQL Server 2016 (or above) and the compatibility level is set to 1200. For further information see MSDN here.

  • Workspace Retention: Keep in memory | Unload from memory | Delete workspace

Keep in memory: The workspace database (that includes the model metadata, imported data and credentials) will be kept in memory after closing a model. Your model will load faster but you might lose all of your memory. Unload from memory: The workspace database will be written to disk on closing and reloaded into memory on reload. Should be used on a remote workspace database or if you have a limited RAM amount. Delete workspace: The workspace database will be deleted on closing your model. Your model will always need more time to load as it must restore any settings. Use this option when you are rarely working with your model.

  • Workspace Server: This is the connection to a SSAS Tabular Mode Instance used for storing and editing temporary the current in-memory model. See Workspace Database property to examine the temporary database name created on this instance.

Import a new Data Model from Data Source

This section describes the steps to import related Fact and Dimension tables from Adventureworks DW 2014. Go to the menu bar in SSDT, click on MODEL and then Import From Data Source…

Import from Data Source Menu Item

The Table Import Wizard opens.

Table Import Wizard Step 1

Select the relational data source instance and Database to connect to.

Table Import Wizard Step 1

Table Import Wizard Step 2

Enter the credentials of a user specific to this project to connect to the data source. You should always try to create an Active Directory user for each Project you are creating to be able to give project specific permissions to this user in the data source. Don’t use a “sa” account.
Table Import Wizard Step 2

Table Import Wizard Step 3

Decide whether to select data from given tables or views or by specifying your own SQL Query.

Table Import Wizard Step 3

Table Import Wizard Step 4 (Select Tables and Views)

Select the Tables/Views. In this example I checked the FactInternetSales table and then used the handy Select Related Tables button.

Table Import Wizard Step 4

Preview & Filter dialog:

Table Import Wizard Data Preview

Table Import Wizard Step 5 (Finishing -> Importing)

The Data is transferred and the selected tables are imported into your model. Hit Close.

Table Import Wizard Final Step

Configure your Tabular Model

When you switch to Diagram View, you will see the following result:

Diagram View of FactInternetSales Tabular Model

Table Properties

Table Properties

  • Default Field Set: Determines which attributes are being displayed by default when a client connects to this table. See also MSDN here.
  • Hidden: True | False. Specifies if the table is hidden in client tools.
  • Partitions: Lets you define logical partitions for single processing. Can be very helpful on huge tables. They allow parallel processing. See also MSDN here.

Partition Manager

  • Source Data: View or edit the source data.

Source Data

  • Table Behavior: Only affects PowerView. Does not apply to Excel Pivot! You can define table behavior properties for tables of primary interest (for example: Customer, Employee, …). In most cases you do not need to set properties for these table types: Date, Category, Group, Department, Lookup and Summary tables… . For details and example of table behavior see MSDN here.

Table Behavior of DimCustomer

Column Properties

For an (currently in-)complete property overview see MSDN here.

Column Properties

  • Column Name: Name of the column stored in the model. Also referred to as Friendly Name. This property value is the name of a column displayed in client reporting tools.
  • Data Category: One of the following values:

Data Category Column Properties

  • Data Format: Lets you define the displayed format of this column in client tools. Options follow (Numeric and Date based columns). See also MSDN here.

Data Format NumericData Format Date

 

 

 

 

 

  • Data Type: Underlying Data Type used on Import. Do not change.
  • Default Label: True | False. Set to true to set a specific column as the Label column displayed in client tools for this table.
  • Hidden: True | False: Set to true to hide this column in client reporting tools.
  • Row Identifier: True | False: Set to true to set a specific column as the unique ID column. You will use a ID or surrogate key column.
  • Sort By Column: Specify another column to sort values in this column. You cannot specify a formula or measure.
  • Summarize By: By default a client reporting tool uses the SUM aggregation on values. If you need to set a specific calculation method use one of the following:

Summarize By Column Properties

  • Table Detail Position: If you have a Default Field Set defined, you may change the order of a column by setting this value.

Creating a Hierarchy

We will create a Hierarchy on the Date Dimension as follows. First you will have to click the “Create Hierarchy” button on the upper right of a table:

Create Hierarchy

Then you will give it a name: “Years and Parts”. After that you drag & drop the following three columns onto the Years and Parts hierarchy column:

Drag & Drop Columns on Hierarchy column

Analyze Results with Excel Pivot

We will now analyze the results and the effects of the created hierarchy in Excel. Go to the menu bar in VS2013, open the MODEL menu and click Analyze in Excel.

Analyze in Excel Menu Item

Leave the “Current Windows User” option set in the following dialog and hit OK.

Analyze in Excel Start Screen

Excel opens with the following result:

Excel starts with empty pivot table