53

I am getting the following error when processing a Dimension:

Errors in the OLAP storage engine: A duplicate attribute key has been found when processing: Table: 'dbo_Orders', Column: 'Project', Value: 'client service stuff'. The attribute is 'Project'.

'Project' is an attribute of the 'Orders' dimension, but not a key. Nowhere did I indicate that the Project column is a key! I should be able to have as many duplicates as necessary, just like a first name field.

I'm new at Analysis Services project and really need to get past the fact that SSAS is constantly complaining about duplicate values when it should be perfectly OK to have duplicate values. I'm sure this must be something simple that I'm overlooking.

Edit: I realize that it is possible to set KeyDuplicate = ReportAndContinue/ReportAndStop and it is also possible to set KeyColumns and NameColumns. But this multistep process seems very cumbersome for what would seem should be a very normal operation, like adding Address1, Address2, Address3, Firstname, Zipcode, and other fields that normally are duplicated. I can't believe this cumbersome process need to be applied to all such fields?

starball
  • 20,030
  • 7
  • 43
  • 238
Dave
  • 4,949
  • 6
  • 50
  • 73

16 Answers16

52

This is usually a result of having both blanks and NULLs in the source table/view.

Essentially, SSAS does this for every attribute SELECT DISTINCT COALESCE(attr,'') FROM SOURCE

Analysis services by default converts NULLs to blanks, resulting in duplicate value blanks in the resulting feed - hence the error.

I agree this sucks and is a major pain for new players.

Solution : Remove all nulls from the data source, for example by using ISNULL / COALESCE everywhere, or filtering out rows containing null using where clause, or running update statement to replace all nulls with values before processing the cube, etc.

WOPR
  • 5,313
  • 6
  • 47
  • 63
  • I am starting to get the hang of it. It takes a little practice. Thanks. – Dave Sep 02 '11 at 22:20
  • It helped me find a broken foreign key - I was supposed to be inserting nulls - not blanks. – JumpingJezza Apr 20 '12 at 03:44
  • 15
    @NTDLS one solution is to change how SSAS process null from dimension designer, the KeyColumns property of the problem attribute. Usually I set the NullProcessing subproperty to UnknownMember. – Endy Tjahjono Mar 06 '13 at 12:17
  • Another solution is to remove all nulls from the data source, for example by using ISNULL / COALESCE everywhere, or filtering out rows containing null using where clause, or running update statement to replace all nulls with values before processing the cube, etc. – Endy Tjahjono Mar 06 '13 at 12:47
  • 3
    Endy, your first solution works like a charm. Could you post it as an answer (you'll get my vote)? It seems like the answer shouldn't be buried in a comment. The accepted answer is a nice explanation, but it doesn't really contain a solution. – Tom May 15 '13 at 20:23
  • 3
    I don't agree that SSAS does a `SELECT DISTINCT COALESCE(attr, '')`. The problem is that it does a `SELECT DISTINCT` without the `COALESCE` and then converts nulls into blanks which results in duplicates. – Lock May 06 '16 at 06:40
  • 1
    I don't understand how this relates to nulls at all. I don't have null values and the error message posted by OP is referencing a non null value "Value:'client service stuff'" – AaronLS Jul 17 '16 at 13:59
  • Still.. if both NULLs and Blanks exist how come they are identified as duplicates ? They are not the same – jayt.dev Apr 18 '18 at 10:50
  • 1
    This is not the cause of @Dave's error. If it were, then the "Value" in the error message would be empty string (''). This is likely caused by the source database being case sensitive, and the SSAS database being case insensitive. So, there are two distinct values in the source database that can only "become" the same value in the SSAS database. SSAS rightfully detects this as an error. – Eric Dec 11 '18 at 16:22
  • @AaronLS You will probably find more than one record with Value:'client service stuff' and at least one of those have an extra char(13) or char(10) – embe May 26 '23 at 10:36
18

Right click the attribute and select "Properties". Find "KeyColumn" which is located under the "Source" category within the Properties Window. Edit the "KeyColumn" property, it will display a user friendly window.

Remove the attribute from the right (Key Columns) side of the window and replace it with the actual id column from the left (Available Columns) side.

Then edit the "NameColumn" property, the same window will appear. Move the attribute column (the actual data you want to display) from the left side to the right.

Tested in VS 2010 Shell SSDT.

Eric W.
  • 7,148
  • 3
  • 20
  • 27
  • 3
    This will result in duplicates displaying for that attribute. Eg for a dimension key "Id" with values 1,2,3,4,5 but an attribute with values Blue and Green, the attribute may display Blue, Blue, Blue, Green, Green – Aaron West Nov 12 '16 at 00:45
  • This got rid of the error but like Aaron said resulted in duplicates. – speedinfusion Dec 31 '17 at 06:40
18

I had the same issue, and there was no blank or NULL values in the attribute. After some analysis, I found that some strings had line break character on the end. So, if 2 values of the attribute are nearly the same, but one of them has line break character at the end, and the other doesn't, then SSAS raises “Duplicate attribute key” error.
It can be fixed by removing line break character from the attribute.
I created calculated column with following definition:

REPLACE(REPLACE(ISNULL([AttributeColumn], ''), CHAR(13), ''), CHAR(10), '')

I used this calculated column in the cube, and the error disappeared.

Pavel Sinkevich
  • 619
  • 5
  • 12
  • 1
    I had the same also with CHAR(9) the tab feed – Will Wainwright Oct 14 '16 at 23:16
  • one million up votes, if I could. Thanks very much this was totally the problem for me. The data is user editable, so the new line character snuck into the source data. – KirstieBallance Apr 05 '18 at 02:28
  • It can be caused by characters other than linebreaks so for example in ORACLE SQL it can be better to use REGEXP_REPLACE to only leave characters you know are valid e.g. REGEXP_REPLACE([AttributeColumn], '[^A-Za-z0-9 .()+-/:''&\@]','') – RET May 16 '18 at 15:19
  • Same problem, sql Server 2014. Very strange problem. – Alex Sham Jan 17 '19 at 07:40
8

Just had this happen to me today and scratched my head for a while as none of the solutions here worked. Finally solved it and thought I'd add my solution for anyone else googling this error and arriving here just as I did.

In my case it was not NULL and blank strings as I had the [NullProcessing] value already set to "UnknownMember". Rather it was the [Trimming] value, in my case it was set to "Right".

While I know how I solved(?) it I am not 100% as to why, but I assume when SQL Server does it's SELECT DISTINCT(col) FROM source and the [Trimming] value is set as such, Analysis server later removes among other things tab chars from the end (which RTRIM in SQL Server for example does not) and ends up with duplicates.

So setting [Trimming] to "None" might solve it, since the tabs was data I did not need (my data is parsed/read/entered from external sources) I simply replaced tabs in the column and after that processing of the cube is fine again.

Don
  • 9,511
  • 4
  • 26
  • 25
  • 2 years later and still helpful. – Will Wainwright Oct 14 '16 at 22:59
  • The Trimming option is found in DimensionAttribute -> (Source) KeyColumns -> (specific field). https://wschampheleer.wordpress.com/2009/12/20/degenerate-dimensions-in-ssas/ elaborates more on this and the associated problems that may come up. – Nickolay Dec 13 '20 at 16:34
6

While my other solution on this page works (and depending on situations might be more ideal), this is an alternate solution:

Here is a mock up of part of my error:

Column: 'attribute1_name', Value: 'Search String'

I did a quick search for:

SELECT dim_id,
       dim_name,
       dim_attribute1.id,
       dim_attribute1.name,
       dim_attribute2.id,
       dim_attribute2.name
  FROM dim_table
    INNER JOIN dim_attribute1 ON dim.attribute1_id = dim_attribute1.id
    INNER JOIN dim_attribute2 ON dim.attribute2_id = dim_attribute2.id
 WHERE UPPER(dim_attribute1.name) = UPPER('Search String')

It turns out that there were two different entries for dim_attribute1.name which matched this:

  1. Search String
  2. search string

The first solution split them without issue, so it is a working solution (plus the performance bonus). However an alternative (if one wants to keep the text values as keys) is to change the Collation:

Key Columns → Column Name → Source → Collation

To include 'case sensitive'.

Other similar issues can be white space characters and other easy to not spot subtle changes in the text.

  • Your last point of white space characters was the issue for me. I had to concatenate a pipe to the resulting "description" text to see that there were a couple of spaces added... more of a result of a poorly designed table. – scrawny Mar 12 '16 at 07:21
3

I had a similar issue today (same error message), for the sake of anyone else getting here with the same problem I put some notes on my wiki: http://www.david-halliday.co.uk/wiki/doku.php?id=databases:oracle&#select_dates_for_ssas_include_hierarchy

My case was SQL (simplified and reworded to defend the innocent):

SELECT dim_id,
       dim_name,
       dim_attribute1.name,
       dim_attribute2.name
  FROM dim_table
    INNER JOIN dim_attribute1 ON dim.attribute1_id = dim_attribute1.id
    INNER JOIN dim_attribute2 ON dim.attribute2_id = dim_attribute2.id

The strange thing was the error was happening for some cases of dim_attribute1_name but not dim_attribute2_name. However this particular case the attribute was exactly the same. In the end the solution was to change the SQL to:

SELECT dim_id,
       dim_name,
       dim_attribute1.id,
       dim_attribute1.name,
       dim_attribute2.id,
       dim_attribute2.name
  FROM dim_table
    INNER JOIN dim_attribute1 ON dim.attribute1_id = dim_attribute1.id
    INNER JOIN dim_attribute2 ON dim.attribute2_id = dim_attribute2.id

Then use in the dimension (hiding the IDs in the list) the id value for the key of the attribute and the name for the name of the attribute. I haven't seen this before but for some reason it happened here. This solution I believe is better than setting the cube to process ignoring duplicate key errors.

I presume that if one is building a dimension joining tables this will give better performance/reliability. But don't quote me on that.

  • Thanks for your suggestions. It's been awhile since working on this project, but next time I'll give your techniques a try. – Dave Jul 02 '12 at 19:36
3

I had the same problem and I found a workaround for it.

Right Click in "Cube" => "Process" => "Change Settings" => "Dimension Key Errors"

Active "User Custom Error Configuration"

Set "Ignore Errors" for this four drop down list "Key Not Found" "Duplicated Key" "Null key converted to unknown" "Null key not allowed"

The problem with keys will be ignored.

Jeferson Tenorio
  • 2,030
  • 25
  • 31
3

I got the problem after I had been playing around with adding an ID into the key column of an attribute. I had since removed the key but found that the select statement during processing was still referring to the ID, making the attribute non unique. I couldn't find a way of resolving this via the attribute properties, so I deleted the whole Dimension and recreated it. This fixed the issue.

Lesley
  • 31
  • 2
2

Please read this blog: a duplicate attribute key has been found.... Look at the long explanation for reason 1. It will explain why exactly this is happening.

Thanks guys

Ned

Ned
  • 29
  • 2
2

None of the above solved for me. What worked was something similar to what Eric W. suggested.

I had to set up multiple Key Columns for my attributes. For example, the attribute "City" needs the Key Columns "Country", "State", and "City".

More info here: https://www.mssqltips.com/sqlservertip/3271/sql-server-analysis-server-ssas-keycolumn-vs-namecolumn-vs-valuecolumn/

MrM1k4d0
  • 55
  • 1
  • 10
2

In case it helps other quasi-newbies like me, I’ll outline a solution that I finally figured out after struggling with the “duplicate attribute key” error message while trying to deploy a Date dimension spanning multiple years. The error message indicated, for example, that I had duplicate attribute keys in my CalendarQuarter attribute. That initially confused me because every complete year has four quarters (i.e. 1, 2, 3 & 4) so of course I had duplicates. It finally dawned on me that that was the problem--in other words (and contrary to the title of this thread) the attribute WAS the key. I solved it by adding a “CalendarQuarterKey” named calculation column to my DSV’s Date table to yield unique keys for my CalendarQuarter attribute, e.g. “20171” instead of just “1” for 2017 Q1, “20172” instead of just “2” for 2017 Q2, etc. Ditto with my CalendarMonth attribute: every complete year has twelve months (i.e. 1, 2, 3...,11, 12) so of course I had duplicates there as well. Same solution: I added a “CalendarMonthKey” named calculation column to my DSV’s Date table to yield unique keys for the CalendarMonth attribute, e.g. “201701” instead of just “1” for January 2017, “201702” instead of just “2” for February 2017, etc. Then, I used my new “CalendarQuarterKey” & “CalendarMonthKey” columns as the KeyColumn for my CalendarQuarter and CalendarMonth attributes respectively. This may not be the preferred solution, but it worked for me and I can finally get back to building my cube.

BRW
  • 187
  • 1
  • 10
0

I solved by specifying the COLLATION on my views on the relational database as follow.

COALESCE([Descrição da Transação],'') COLLATE Latin1_General_CI_AI

0

If your data contains both NULLs and '' SSAS give out duplicate attribute key, because it considers NULLs to be ''. You don't have to touch your data to fix this. You can go to your data source view and add a named calculation with expression COALESCE(mycolumn, ''), then use that in your dimension instead of the original column. This will fix the problem at the data source view level and the dimension will process fine.

0

Lemme give you a workaround if you still want to go ahead with deployment & cube browsing . Under 'process cube' window, change dimension key error settings to custom . You would be able to seamlessly deploy & browse the cube . trade-off here is that you might not get the results which you expected.

Nim J
  • 993
  • 2
  • 9
  • 15
0

some time that need composite key in keyColumns to resolve the duplicate attribute key

0

I've run into this error many times for various reasons, but recently encountered a rather obscure cause: the presence of the beta ß character in a text column. Despite the fact that the thousands of unique words in the column used a hodgepodge of every obscure ASCII code under the sun, SSAS choked only while processing column values that included the ß symbol. Nulls, duplicates, trimming and the like were all systematically ruled out. This is in all likelihood related to unfathomable and unsolved issue discussed in the MSDN thread SSAS 2012 duplicate key error with 'ss' and 'ß', in which SSAS interpreted ß values as 'ss' for some inscrutable reason, even when the collation settings were correct. In my case, setting the Collation in the SSAS column properties to match the source column's collation of SQL_Latin1_General_CP1_CS_AS on the relational side did not fix this; I had to also change the collation for the entire server. This workaround might be painful in certain environments where other columns depend on different collations, but it skirted this issue in my case and allowed me to process the dimension without a hitch. I hope this helps the next person to stumble over the same "gotcha."

SQLServerSteve
  • 332
  • 1
  • 11
  • 22