I have an interesting problem with Analysis Services that I was able to resolve (sort of), but I would appreciate some feedback to see if this is known behavior, a bug, or if I'm just setting up my dimension incorrectly.
Basically, the intermediate members of a hierarchy are showing up incorrectly in my date dimension. For example, when I browse the dimension, I'll end up with a tree that looks like this:
All CY
- CY 1998
- Qtr 1 CY 1998
- January 1998
- Jan 1, 1998
- Jan 2, 1998
- etc.
- .....
- .....
- CY 2005
- Qtr 1 CY 1998
- January 1998
- Jan 1, 2005
- Jan 2, 2005
- etc.
As you can see, the years are correct and the lowest element (date) is correct, but the names of the intermediate elements (quarter and month) are incorrect. These intermediate elements are the same for each calendar year (i.e. it's always 1998, which is the earliest year we have data for in the table).
I've included the table/hierarchy structure below for reference.
So the way that I (sort of) resolved the issue was by using the calculated name values as the keys for the attributes instead of using the integer-based keys that I was using. It seems that you can't/shouldn't have key values that repeat for different higher-level elements (i.e. the month_si value of "12" (December) is present in the table for rows from CY 1998, 1999, 2000, etc.). I'm guessing here, but it seems that when it went to build the hierarchy underneath, say, CY 2006, it found key values of "1","2","3", & "4" for [quarter_si] (correctly so). It then pulled the value from [Column15] for those key values, but instead of limiting itself to data underneath CY 2006, it looked at the whole table, and thus pulled the name values for those quarters from the first records in the table, which happened to be "Qtr 1 CY 1998","Qtr 2 CY 1998" and so on. But since "Qtr 1 CY 2006" is only present in CY 2006, using "Qtr 1 CY 2006" as the key and name value gave me the correct hierarchy.
Unfortunately, this resolution doesn't work because the keys won't order correctly (i.e. "June 2006" comes before "May 2006" under "Qtr 2 CY 2006") and this is a show-stopper.
What's odd is that I converted this dimension directly from SSAS 2000, and this was not a problem we encountered in 2000. Is this issue resulting from something new introduced in SSAS 2005? Is there a property flag that controls this behavior?
Or do I just not have a good understanding of how dimensions work? ;)
I would appreciate anyone's feedback or comments.
Thanks in advance,
Jamie C.
TABLE/DIMENSION/HIERARCHY INFO:
The underlying table used for the dimension is "dbo.dci_Date" - the structure of the table (including calculated columns within AS) is this:
[dbo].[dci_Date]
[date_id_si] [smallint] NOT NULL,
[year_si] [smallint] NOT NULL,
[quarter_si] [smallint] NOT NULL,
[month_si] [smallint] NOT NULL,
[date_sd] [smalldatetime] NULL,
The following "virtual" columns are also present as calculated columns - I've included the formulas for reference:
[Column4] [WChar] = left("date_sd",11)
[Column13] [WChar] = 'CY ' + convert(char,DatePart(year,"date_sd"))
[Column15] [WChar] = 'Qtr ' + convert(CHAR, DatePart(quarter,"date_sd")) + 'CY ' + convert(char,DatePart(year,"date_sd"))
[Column17] [WChar] = convert(CHAR, DateName(month,"date_sd")) + convert(char,DatePart(year,"date_sd"))
Here's an example of what a couple of rows from the table look like (including the values for the calculated columns) - I've included the min & max as well:
[date_id_si],[year_si],[quarter_si],[month_si],[date_sd],[Column4],[Column13],[Column15],[Column17]
-729,1998,1,1,1998-01-01 00:00:00Z,Jan 1 1998,CY 1998,Qtr 1 CY 1998,January 1998 ** MIN
2495,2006,4,10,2006-10-30 00:00:00Z,Oct 30 2006,CY 2006,Qtr 4 CY 2006,October 2006
2496,2006,4,10,2006-10-31 00:00:00Z,Oct 31 2006,CY 2006,Qtr 4 CY 2006,October 2006
2497,2006,4,11,2006-11-01 00:00:00Z,Nov 1 2006,CY 2006,Qtr 4 CY 2006,November 2006
4270,2011,3,9,2011-09-09 00:00:00Z,Sep 9 2011,CY 2011,Qtr 3 CY 2011,September 2011 ** MAX
The hierarchy for this dimension (Calendar Year) is built with the following attributes:
Year -- key: [year_si] name: [Column13]
Quarter -- key: [quarter_si] name: [Column15]
Month -- key: [month_si] name: [Column17]
Day -- key: [Column4] name: [Column4]
Hello. You must assure that each attribute in a dimensions has an unique key. Like month, if you represent this with a month number like 1 to 12, this is not unique over years. To solve this problem you simply go to the key property of the attribute and change that to a collection by adding each year to column. By clicking to button to the right for the key column you will see the "Data Item Collection editor".
I would recommed to use numbers or collections of numbers as keys for year, quarters and months. Change the name column to something for informative instead, like a text based description. Check that the attribute is ordered by key, not by name in the properties for each attribute.
HTH
Thomas Ivarsson
|||Thanks Thomas! I had a feeling that was the case, but it never hurts to be sure.
Best,
Jamie C.
No comments:
Post a Comment