Analysis Services Series on SQLShack

Please visit SQLShack.com for new articles on many facets of SQL Server. I have been trying my best to document how to create SQL Server Analysis Service databases with Multidimensional Cubes as well as Tabular Models.

word-image1

The start was a Best Practices article for Dimensional Modeling and other items that help with a smooth transition to creating an SSAS database. Here is a link to that article.

The flow of the articles starts with the multidimensional cube, then the next article shows tabular.

image

After the best practices, I move to connecting to a data source, then creating attributes and measures.

Even though people are using Power BI more than Analysis Services, eventually when their systems get to large, they are going to have to find an enterprise solution for modeling the data. I do not believe that modeling in Power BI is very sustainable.

word-image-108a

With the Microsoft push for Cloud First development, Analysis Services in Azure will be the next big item. If you have not already seen, you can import a Power BI Model into Azure Analyssi Services. Tabluar is in Power BI not Multidimensional Cubes. So, you better start learning tabular and maybe start new projects in Tabular Model Analysis Services.

Query Data Store–SQL Server 2016

SQL Server’s new Query Data Store is a brilliant option for databases if you are a DBA or have to do performance tuning on T-SQL queries. This new feature of SQL Server 2016 is contained within a database with configuration options for storage of history and query plans. The option has many benefits you can take advantage of today, but also this is an option for future upgrades to new SQL Server versions because of the history contained in the database rather than the instance.

image

 

To enable the Query Data Store, you have to be db_owner of the database or SysAdmin to the instance. Once you right-click the database in SQL Server Management Studio (SSMS), go to the Query Store menu choice on the left and change Operation Mode (Requested) to Read Write. There are other options to handle the time retention of data as well as how often it is collected.

image

 

This will enable the database to start storing query execution plans as well as statistics like IO, Read/Write and execution times in the database itself. There are new Data Management Objects (DMVs/DMFs) to use to manual retrieve this data.

image

 

There are also reports available at the database level in SSMS to view information about query statistics. If you drill into the database in SSMS, you will see an option for Query Store.

 

image

Here, you will see the four default reports that come with this Option.

  1. Regressed Queries – shows query history and changes in statistics
  2. Overall Resource Consumption – history of resources used in the database
  3. Top resource Consuming Queries – Top x of queries using the most resources
  4. Tracked Queries – enables you to see multiple query plans for a T-SQL statement and compare the plans or force a plan

The above is just a summary of what you are able to do, but just start using this feature and you will be amazed at what it enables DBAs and others to drill into. This drilling is just the history of queries on one database rather than you having to sort through all plans for an instance.

SQL Server 2016–Live Query Statistics

WOW!!! The next great update to Execution Plans is a way to watch the processing of rows through iterators while the query runs. Never saw that coming. And even a bonus, you can use SQL Server 2016 Management Studio (SSMS) to watch queries run on versions 2014, 2012 and 2008 R2.

SSMS 2016 can be installed by itself without the server installation. Go here for the installation. Once you install SSMS, you can start to view this addition in SSMS.like Figure 1.

 

image

Figure 1 – Live Query Statistics

After opening a New Query, go to the Query menu choice and select “Include Live Query Statistics.” You will need a long running query in order to see the processing happening at a slow pace.

image

Figure 2 – Include Live Query Statistics

Once you start a query, a new tab will show the Live Query Statistics like Figure 3. The dotted lne means the iterator has not finished or has not started.

 

image

Figure 3 – New Tab

The labeling of the iterators have the usually properties as an Execution Plan plus a running time clock of seconds that this iterator is using. In addition, you can see the “Actual Number of Row” of “Esitmated number of Rows” with a calculated Percent Done (Actual/Estimated). Figure 4 shows 144% for some iterators that have not even finished yet.

 

image

Figure 4 – Percent Greater Than 100

This is useful to see if estimate number of rows is the same or close to actual number of rows. The percentage will rise above 100 if there are more actual than estimated rows. The query in this case probably could use some performance tuning to get the estimate closer to the actual.

WOW!!!

PASS Summit 2016-Thursday Part II

The second half of the day was spent talking with various speakers and attendees. I got into a great conversation about trying to mentor developers at work places about how to write good T-SQL. It was interesting to here how some developers (or DBAs) are not open to new ways to write T-SQL like using CTEs or proper join syntax.

image

I meet Lance from the program committee and discussed the difficultly of having 800+ submissions and only about 140 slots for those submissions. To make sure you get a wide range of topics and not covering too little or too many of the same topic is not always easy. They do a great job with the volunteers to make sure Summit is a great learning opportunity for all.

I also saw a new posting on SQLServerCentral.Com about learning SQL Server 2016. Try this Link – http://www.sqlservercentral.com/articles/SQL+Server+2016/127518/.

image

The only session I attended was on learning how to price and scale an Azure SQL Server Data Warehouse. So, now I understand DWUs and pricing is 3 fold: DWUs, Storage and GEO DR. It can be expensive, but you get Massive Parallel Processing in the cloud and easier scaling up or down the usage.image

The last 2 session time slots was spent co-presenting with Bill Anton on Performance Tuning Analysis Services. It was well attended but in a large room. There was about 2/3 of the people returning after the break for the 3 hour session. Bill did a great job getting people started with Profiler, PerfMon and some free tools and scripts. Lots of questions and even a Microsoft developer helping us answer questions. Thanks Microsoft.

Last stop of the day was dinner with some great guys from Atlanta at Rock Bottom. They went to a BIML party, I went to bed. Smile

PASS Summit 2016-Thursday Part 1

Today’s keynote was by David Dewitt. He did an excellent job explaining the architecture behind various Cloud Data Warehouse offerings. It was nice to get an explanation of the behind the scenes node and disk usage.

   image

One announcement that caught me off guard was next year’s Summit is Oct 31 thru Nov 3. That is Halloween and my kids come first on that day. Not sure that was a good idea. Better information shared was an increase in revenue of 10%, plus 100%+ increase in Global membership in some areas. There is a new logo and the updated website will be released early next year. Denise provided some slides on what the website will look like including mobile friendly.

image

Next, I am going to meet up with Bill and attend a session on Azure DW.

PASS Summit 2016-Wednesday

Media preview

As all Summits, the first Regular Session day in Seattle started with the Keynote. Well, really it starts with a great breakfast at the Seattle Convention Center, but I digressed. Microsoft released information about new features for its Microsoft Data Platforms. The Keynote provided Customer specific examples of some of the newer features being used plus Program Managers demoing great examples of what is to come. For a summary, go to watch the PASStv Recap. A feature I am looking forward to seeing in action is Analysis Services in the cloud.

Congratulations to Malathi Mahadevan as PASS Outstanding Volunteer of the Year. She is a great representative of the PASS community and people love her service and passion.

image

The Summit is an amazing trip.Wednesday, I spent time with Bill Anton rehearsing a 3 hour Analysis Service Performance Tuning session for Thursday he has put together. His knowledge of this subject is top tier so I learned a lot. I spent time in the Speaker Ready talking and practicing for a session on Excel Tips & Tricks With SSAS Cubes. This session takes all the technical work we IT people put together in a Cube and start to have some fun with it. What amazed me was half the people in the session (there was at least 100 attendees) were Cube builders. They were in the session to find out how people use cubes in Excel to develop better cubes. That is a lot of people still building cubes.

Before the Vendor Reception, I spent time after the Excel session talking to an attendee. He was very unique to me because he was not an IT person, but hired as a Financial/Accounting analyst. He was using data feeds from their hosted applications in PowerBI. It was difficult to explain to him the difference between a Cube, the Tabular Model, PowerPivot AND the modeling in PowerBI. Dimensional Modeling might be to advanced for him, he just wanted basic table design hints.

He was also concerned that there were not enough beginner T-SQL and database design sessions available for him at the Summit, so I spent time with him going through all the remaining session that were a fit for him plus vendors he should visit. He has never heard of Pluralsite or other online training like from PragmaticWorks. We exchanged business cards and wished each other a pleasant week as we walked past the Community Zone and into the Vender Reception.

PASS Summit 2016–Tuesday

For the first day at the Summit this year, I spent half my time in a Pre-Conference session with Idera as an outgoing Idera Ace. The session include a 45 minute presentation for me on a Customer Use-Case. The second half of the day was spent in #SQLPASS Community sessions.

The Customer Use-Case included screen captures of real-world diagnosis using Idera products. Diagnosis Manager provided most of the screens. I was able to show the forecasting reports for data file and table usage/growth. We were able to show a large table that indexes were occupying lots of space and investigated the Index Usage through Glenn Berry scripts on a historical level. Removing some large include indexes help alleviate the table growth in storage size.

image

The other slides were about Alerts/EMails, User T-SQL History, BI Manager and Free Tools like SQL Check and SQL Fragmentation Analyzer.

Media preview

The Community sessions were for #SQLSaturday and User Group/Virtual Chapters. The SQLSaturday session was a full house with many comments and questions. Money and Sponsorship was the hot topic. Growth is still being encouraged, but overall the session had a lot of good points with many thanks to such a great community event system. At the end, an emotional Karla talked about the end to her five reign as PASS Community leader for PASS. What a wonderful ending to the session!!! I won’t show any pictures of her crying (or Grant crying).

The User Group and Virtual Chapter session were a lot about speakers than money or sponsorship.

Truly amazed at the turn out and range of areas represented. I wonder how many User Groups use remote speakers and how often? Interesting discussion about getting a Microsoft TAM or related MS employee to help sponsor or host monthly meeting. You do not pay them but it helps them in their reviews/bonuses.

Ryan Adam announces new features in SQLPass hosted user group pages. There will be an option to send out event notifications for email, twitter, Facebook, LinkedIn, Matchup and other social media at one place, not manually doing many. Cheers from the crowd!!!

The evening end with a bite to eat at Welcome Reception and visiting with new and old friends, too many to list.

Live! 360–Speaking at SQL Server Live Orlando 2016

If you are looking for a great conference to attend, please look at Live! 360. This event combines 6 different areas of IT (including SQL Server) with some of the great experts presenting sessions for 5 days. The sessions are on December 5th thru the 9th in Orlando, FL at Royal Pacific Resort.

This is a link with a discount code for up to $500 dollars off – http://bit.ly/LSPK47_REG

Here are the three I am giving.

SQT07 New Performance Tuning and Security Features in SQL Server 2016

12/06/2016

2:00pm – 3:15pm

Level: Introductory to Intermediate

SQL Server 2016 has added and improved features to an already great product. To start, there is now a Query Store to retrieve history of a query’s execution plan and statistics used for that plan. You can compare them to see the changes. You can also see the Execution Plans “Live” to see where a long running query is spending lots of time. You can also compare plans side-by-side, which should make DBAs or anyone that performance tune queries very happy.

From there, you’ll go into some of the database design aspects of 2016 to improve table implementation. In-Memory has been half-baked in previous versions and now is enterprise ready with OLTP tables. The Column-store indexes include update-able clustered and non-clustered indexes. Temporal Tables remove the requirement of using triggers or custom code to find a point in time version of the data. You now can mask columns for limited viewing and casting of data to the end users by login permissions.

The T-SQL enhancements will help with better writing of set-based queries. The stretch database feature will assist in archiving data to the cloud with access in applications. Always Encrypted secures the database for abiding to regulations in health care and finance. The last feature will be row-level security, which has been a frequently requested option.

You will learn:

  • About T-SQL enhancements in SQL Server 2016
  • About Table design changes in SQL Server 2016
  • About Query Plan improvements in SQL Server 2016

 

SQW05 Master Data Management with Data Quality (DQS) and Master Data Services (MDS) in SQL Server 2016

12/07/2016

9:30am – 10:45am

Level: Intermediate

Is there data scattered all over your enterprise? Has your boss asked you to help your users create and manage one source of common data? Are there different spellings of values in the same column of a table? Can you use help from algorithms to find the best match? Is the Customer or Product table in multiple databases with different columns? Do you need help managing the Data Warehouse?

This session will jump into SQL Server 2016 with DQS and MDS. You use the Data Quality projects in Integration Services (SSIS) to rank values and help with misspelled data. You’ll help your users manage the DQS projects giving them management access to data quality and moving that responsibility to the business where it should be.

Next, you’ll use MDS to help consolidate dimensions scattered in multiple databases to form a true Conformed Dimension area. MDS will help your company move away from spreadsheets or flat files to manage critical information for analytics. These features were added to SQL Server in version 2012 and have been upgraded in 2014 and 2016 to help enterprises with the task of Master Data Management.

You will learn:

  • How to use Data Quality Services to cleanse data with DQS and SSIS
  • How to create a Master Data Management system with MDS in SQL Server 2016 to consolidate multiple data sources

 

SQW12 Improve Enterprise Reporting with SQL Server Analysis Services

12/07/2016

4:00pm – 5:15pm

Level: Intermediate

Have you been at a job where requests keep coming in for more and more reports? Does it seem like some are being used and other are not? Are some of the reports exactly the same except a different grouping or sorting request? Has your boss asked you to investigate a Business Intelligence or Data Warehouse solution? Well, it might be time to start using SQL Server 2016 Analysis Services.

Dimensional Modeling is one of the best starts for designing a system with flexible reporting. The database model fits perfectly into Analysis Service (SSAS) databases from Microsoft. There will be a use case for 3 fact tables to create various data marts. We will demonstrate a Multidimensional Cube and the Tabular Model to help you make the decision of which installation to use. Excel and PowerBI will be the focus for reporting.

Using a Lookup Component in SSIS for Surrogate Keys in a Fact table

There are many suggestions for loading a data warehouse using SQL Server integration Services (SSIS). Once you get started, you find a pattern to repeat for facts and dimensions. This might be because the consistency Dimensional Modeling suggests for the design of fact and dimension tables. The SSIS Lookup component provides options to divert handling of non-conformed data or you can use your T-SQL skills up front where a diversion is not necessary.

The most common use of a Lookup component is to find the Dimension surrogate key for one or more rows in a fact table. The CustomerKey from the Customer dimension will be used in the Sales Fact table in order to join to customer hierarchies and attributes like the following T-SQL:

 

SELECT c.CommuteDistance, Sum([OrderQuantity]) AS OrdQty , Sum([SalesAmount]) AS SalesAmt

FROM [dbo].[FactInternetSales] fis

INNER JOIN dbo.DimCustomer c ON c.CustomerKey = fis.CustomerKey

GROUP BY c.CommuteDistance

 

CommuteDistance

OrdQty

SalesAmt

5-10 Miles

10615

4893148.0413

2-5 Miles

10084

4965514.4362

1-2 Miles

10170

4541608.1498

0-1 Miles

21307

11207592.2248

10+ Miles

8222

3750814.3686

Table 1: Sales Amount and Order Qty sums for Commute Distance

 

Once you get the source data for the Sales fact in an SSIS package, the Lookup component can be used to get the surrogate from the customer dimension. In Figure 1, the object LU – Customer Key lookup in the flow of populating this fact table.

 

clip_image003

Figure 1: Loading the FactInternetSales table from the AdventureWorksDW Database

 

The options for Lookups vary based on some properties. In Figure 2, we can see some of these options.

 

clip_image005

Figure 2: General Lookup properties

 

Most lookups for dimensions can use the Full Cache mode because there is not a lot of dimension rows. But, if you come across large dimensions in a data warehouse, sometime should be spent seeing if a Partial Cache or No Cache will help with loading speed as well as using a Cache connection manager. The Full Cache option will load all the data from the dimension table into memory before any flow starts in the package. This is why it is good not to SELECT all the columns in the dimension table for a lookup.

 

clip_image007

Figure 3: Connection properties

 

Figure 3 shows the connection using a T-SQL statement to only get the CustomerKey and CustomerAlternateKey from the DimCustomer table. The CustomerAlternateKey is the business key that matches customer to rows in the source data for FactInternetSales. If you use the option “Use a table or a view”, the generated query will select all columns from the source.

Let’s go back to the General properties to look at “Specify how to handle rows with no matching entries”. Figure 4 shows the different options available.

 

clip_image009

Figure 4: General properties

 

The “Fail component” option will stop processing of the import if no match is found in the lookup table. This is not a good option for loading data into a fact table. Most systems would want the import to continue for the customer surrogate keys that are found.

  1. Ignore Failure – Null will replace lookup values selected. Those rows with no match are streamed to the normal flow in package with the Null value in match columns selected.
  2. Redirect rows to error output – red line output will show a failure but can pipe the data to any component. Those rows with no match are not streamed to the normal flow in package.
  3. Fail component – the package stops with a failure if no match exists, if all match there is no failure
  4. Redirect rows to no match output – output can be piped to another component and processing continues. Those rows with no match are not streamed to the normal flow in package.

So, the two other options I use most are “Redirect rows to no match output” or “Ignore Failure”. The redirect rows… option can be used to stage the rows that have problems and get someone to look at them before the next import. The Ignore Failure option can be used to substitute a Null value in the CustomerKey column.

Now, this will not work if importing to a fact table with foreign keys and a Not Null property on the CustomerKey column, but what I do most often is change the Null value to -1 and have an entry in the DimCustomer table for the Unknown possibility like this example.

 

CustomerKey

GeographyKey

CustomerAlternateKey

FirstName

LastName

MaritalStatus

Gender

-1

-1

-1

Unknown

Unknown

U

U

 

clip_image011

Figure 5: Derived Column component

 

Figure 5 shows what can been done to convert the Null value in the CustomerKey column to -1. This way with the -1 row in the customer dimension table, we will be able to insert the row into the fact table without having to process the rows outside of this package.

 

clip_image013

Figure 6: Selected Lookup Columns and names

 

Figure 6 shows the Columns tab Properties. Here is where we match the Source fact column for customer to the Business Key in the Customer Dimension. We also select the CustomerKey from the Available Lookup Columns list in order to get the surrogate key for the fact table. The selected CustomerKey is where the Null value will be located if no match if found.

This process also indicates that another process needs to be implement to determine why existing fact rows have business keys for the customer source table that are not imported into the Customer dimension. This one tip can go a long way and patterns developed to help with this situation. It also indicates the power and flexibility SSIS provides data warehouse architects in implementing an ETL solution for its business.