Search This Blog

Sunday, 30 September 2012

ERROR: An item with the same key has already been added

During the process of creating Multi value report. I received the following error while previewing the report
“An item with the same key has already been added.”.















I got irritate when fetch the report MDX through Sql server profiler it ran with no error. After doing lot of research my friend gave a hint (he was having the same problem using TSQL Stored procedure) and resolved my issue. The issue was due to I  added the two fields with same name .
Quick Solution
1.    Go to the report query, stored procedure and identify the duplicate fields and remove it.
2.     If the report is using MDX go to the .rdl code and identify the duplicate fields and remove it.
3.    In MDX report if the field name is different but Unique name is same as highlighted in red below than we can also experience this error
<Field Name="Average_Unit_Price">
<DataField>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Measure" UniqueName="[Measures].[Average Unit Price]" /&gt;</DataField>
<rd:UserDefined>true</rd:UserDefined>
</Field>
<Field Name="Average_Unit_Price">
<DataField>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Measure" UniqueName="[Measures].[Average Unit Price]" /&gt;</DataField>
<rd:UserDefined>true</rd:UserDefined>
</Field>



No comments:

Post a Comment