A blog about designing and developing Business Intelligence solutions using Microsoft SQL Server
Header

In some cases we need to bring comments or descriptions into a dimension in SSAS for detail reporting. For example the comment from a maintenance worker against a machine breakdown, or a geological survey description. These fields are typically free text in the source system and as such don’t contain restrictions or constraints on data entry (e.g. upper and lower case, empty values, white-space, uniqueness). When you try and process these attributes you’ll run into a couple of issues.

To demonstrate this I’ve knocked up a few rows with variations in case of the same text, a null value and an empty string.

Free Text Sample Data

Creating a dimension based on this table in SSAS gives the following error when we try to process it – “Errors in the OLAP storage engine: A duplicate attribute key has been found when processing: Table: ‘dbo_FreeText’, Column: ‘Comment’, Value: ”. The attribute is ‘Comment’”.

SSAS Duplicate Key - Empty and NULL Values

This is due to the NullProcessing property on the dimension attribute, for which the default setting is Automatic. This specifies that the Null value is converted to zero (for numeric data items) or in this case a blank string (for string data items). This means that we’ve now got a null value which is converted to an empty string and an empty string, resulting in duplicate key values. If we set NullProcessing to Preserve this will fix this, giving us two distinct key values. If your database or this particular field is case sensitive you’ll then likely run into a second issue with a very similar error message – “Errors in the OLAP storage engine: A duplicate attribute key has been found when processing: Table: ‘dbo_FreeText’, Column: ‘Comment’, Value: ‘Some comment’. The attribute is ‘Comment’”. This comes down to a difference in case sensitivity between the underlying database and Analysis Services, which by default is case insensitive. In SSAS this is set at the attribute level. If you select the Comment attribute and expand they KeyColumns group you’ll find the collation property, under which you’ll find a case sensitive check box.

SSAS Attribute Collation

Once you’ve checked this the dimension should now process successfully. When we browse the comment attribute you’ll notice two “blank” values (null and empty) and multiple values for “some comment”. This example assumes that these are different discrete values. If this isn’t the case this should be handled in ETL i.e. converting null values to empty strings and standardising on case.

SSAS Browser Comment Attribute

Transact-SQL IN

August 20th, 2012 | Posted by David Stewart in T-SQL - (0 Comments)

The T-SQL IN operator can be used to test whether a given value matches any item in a particular list or sub-query. If the given value equals an item in the list or sub-query the expression returns true, otherwise it returns false.

The following example (based on AdventureWorks) uses IN to return all the departments which are in the research and development, or quality assurance groups. Below is the full list of departments:

DepartmentID Name                                               GroupName                                          ModifiedDate
------------ -------------------------------------------------- -------------------------------------------------- -----------------------
1            Engineering                                        Research and Development                           1998-06-01 00:00:00.000
2            Tool Design                                        Research and Development                           1998-06-01 00:00:00.000
3            Sales                                              Sales and Marketing                                1998-06-01 00:00:00.000
4            Marketing                                          Sales and Marketing                                1998-06-01 00:00:00.000
5            Purchasing                                         Inventory Management                               1998-06-01 00:00:00.000
6            Research and Development                           Research and Development                           1998-06-01 00:00:00.000
7            Production                                         Manufacturing                                      1998-06-01 00:00:00.000
8            Production Control                                 Manufacturing                                      1998-06-01 00:00:00.000
9            Human Resources                                    Executive General and Administration               1998-06-01 00:00:00.000
10           Finance                                            Executive General and Administration               1998-06-01 00:00:00.000
11           Information Services                               Executive General and Administration               1998-06-01 00:00:00.000
12           Document Control                                   Quality Assurance                                  1998-06-01 00:00:00.000
13           Quality Assurance                                  Quality Assurance                                  1998-06-01 00:00:00.000
14           Facilities and Maintenance                         Executive General and Administration               1998-06-01 00:00:00.000
15           Shipping and Receiving                             Inventory Management                               1998-06-01 00:00:00.000
16           Executive                                          Executive General and Administration               1998-06-01 00:00:00.000

(16 row(s) affected)

Now to get only the departments that are in the groups research and development or quality assurance. We need to use the IN operator in the WHERE clause to restrict the rows returned:

1
2
3
4
5
6
7
8
9
SELECT
   *
FROM
   HumanResources.Department
WHERE
   GroupName IN (
      'Research and Development'
   ,  'Quality Assurance'
   )

This gives us the following result:

DepartmentID Name                                               GroupName                                          ModifiedDate
------------ -------------------------------------------------- -------------------------------------------------- -----------------------
1            Engineering                                        Research and Development                           1998-06-01 00:00:00.000
2            Tool Design                                        Research and Development                           1998-06-01 00:00:00.000
6            Research and Development                           Research and Development                           1998-06-01 00:00:00.000
12           Document Control                                   Quality Assurance                                  1998-06-01 00:00:00.000
13           Quality Assurance                                  Quality Assurance                                  1998-06-01 00:00:00.000

(5 row(s) affected)

We can also include NOT with the IN operator, which logically returns false when the value matches an item in the list and true otherwise. So we could get all departments that aren’t in the above groups:

1
2
3
4
5
6
7
8
9
SELECT
   *
FROM
   HumanResources.Department
WHERE
   GroupName NOT IN (
      'Research and Development'
   ,  'Quality Assurance'
   )
DepartmentID Name                                               GroupName                                          ModifiedDate
------------ -------------------------------------------------- -------------------------------------------------- -----------------------
3            Sales                                              Sales and Marketing                                1998-06-01 00:00:00.000
4            Marketing                                          Sales and Marketing                                1998-06-01 00:00:00.000
5            Purchasing                                         Inventory Management                               1998-06-01 00:00:00.000
7            Production                                         Manufacturing                                      1998-06-01 00:00:00.000
8            Production Control                                 Manufacturing                                      1998-06-01 00:00:00.000
9            Human Resources                                    Executive General and Administration               1998-06-01 00:00:00.000
10           Finance                                            Executive General and Administration               1998-06-01 00:00:00.000
11           Information Services                               Executive General and Administration               1998-06-01 00:00:00.000
14           Facilities and Maintenance                         Executive General and Administration               1998-06-01 00:00:00.000
15           Shipping and Receiving                             Inventory Management                               1998-06-01 00:00:00.000
16           Executive                                          Executive General and Administration               1998-06-01 00:00:00.000

(11 row(s) affected)

We can also use sub-queries with the IN operator. For example we might want to get a list of employee id’s that have been assigned to a department within the Quality Assurance group:

1
2
3
4
5
6
7
8
9
10
11
12
13
SELECT
   EmployeeID
FROM
   HumanResources.EmployeeDepartmentHistory
WHERE
   DepartmentID IN (
      SELECT
         DepartmentID
      FROM
         HumanResources.Department
      WHERE
         GroupName = 'Quality Assurance'
   )

Previously I wrote a post about the LocaleIdentifier error when browsing an Analysis Services cube via Management Studio. Whilst it’s annoying, it really only affects developers so quickly slips down the list of priorities to address! However, when it starts to affect users it becomes a serious issue. Working on another project with an Excel component this issue came up in a couple of places – connecting to the cube from Excel (sometimes), and using drill-through in Excel.

After looking into this for a while I came across a solution, although it’s not one I feel completely comfortable with.

1. Go to Windows > Control Panel > Region and Language

2. Update the Format to “English (United States)”

Region and Language Format

3. Click Apply

4. Update the Format back to your original language, in my case “English (Australia)”

5. Click Apply

6. Click OK