简体   繁体   English

使用SSAS的带有年龄段的基于周期的图

[英]Period based graph with age blocks using SSAS

I am just starting to use SSAS and I'm trying to produce a data cube that allows me to produce a chart of the number of people in a particular age range per quarter spanning a number of years. 我刚刚开始使用SSAS,并且试图创建一个数据立方体,该数据立方体使我能够生成一张图表,该图表显示跨度多年的每季度特定年龄范围内的人数。 So for example: 因此,例如:

                 |   $        @$           $
Number of people | # $        @$         #@$
                 | #@$       #@$         #@$
                 +------------------------------
                  2010 Q1   2010 Q2 ... 2014 Q1

where # are people aged 10-20, @ are people aged 20-30 and $ are people aged 30-40. 其中#是10-20岁的人,@是20-30岁的人,而$是30-40岁的人。

The problem I'm finding is that in 2010 someone might have been 29 and so would fall into the 20-30 age range, but in 2014 I want that same person to be counted in the 30-40 age range because he would now be 33. I don't know how to (or if it is even possible to) create a dimension that would be date and time sensitive? 我发现的问题是,在2010年某个人可能已经29岁,因此属于20-30岁年龄段,但是在2014年,我希望将同一个人计入30-40岁年龄段,因为他现在33.我不知道如何(或者甚至有可能)创建一个对日期和时间敏感的维度?

Build it into your model 将其构建到模型中

Just model it correctly: Assuming you have a fact table containing the measures you analyze and foreign keys to a person dimension as well as a date dimension, add a new table for the "age group" dimension containing the ranges you want to analyze. 只需对其进行正确建模即可:假设您有一个事实表,其中包含要分析的度量以及人维度和日期维度的外键,请为“年龄组”维度添加一个新表,其中包含要分析的范围。 This table would contain eg one record "0-9", one "10-19", etc. 该表将包含一个记录“ 0-9”,一个“ 10-19”等。

Then add a foreign key column referencing the age group dimension to the fact table. 然后,将引用年龄组维的外键列添加到事实表。 Setting the value of this foreign key would then be a SQL update statement on the fact table that calculates the difference between the date referenced by the foreign key to the date dimension and the birth date of the person referenced by the foreign key to the person dimension. 设置此外键的值将是事实表上的一条SQL更新语句,该语句将计算外键对日期维度的引用日期与外键对人员维度的引用对象的出生日期之间的差。 This difference is the age at that date. 该差异是该日期的年龄。 From this, determine the age group and use its primary key as the value of the foreign key column. 由此确定年龄组,并将其主键用作外键列的值。

And finally, just make an attribute from your age group column of the age group dimension. 最后,只需在“年龄组”维度的“年龄组”列中创建一个属性即可。

Calculate it on the fly 即时计算

If you really want to calculate that on the fly, I am not sure the performance is good, but you could try it as follows: You would need the "age group" dimension as well. 如果您真的想即时计算出来,我不确定性能是否很好,但是您可以按以下方式进行尝试:您也需要“年龄组”维度。 But there would be no need to link it to your fact table. 但是没有必要将其链接到您的事实表。 Then define a calculated member like this: 然后定义一个计算成员,如下所示:

member [Measures].[Age at Date] AS
       DateDiff('yyyy',
                [Person].[BirthDate].CurrentMember.Properties("Key0", TYPED),
                Measures.[Date]
               )
Member [Measures].[Person Count per Age Group] AS
       CASE
           WHEN [Age Group].[Age Group].CurrentMember is [Age Group].[Age Group].[0-9] THEN
                Filter([Person].[Person Id].[Person Id].Members,
                       [Measures].[Age at Date] >= 0 AND [Measures].[Age at Date] < 10
                      ).Count
           WHEN [Age Group].[Age Group].CurrentMember is [Age Group].[Age Group].[10-19] THEN
                Filter([Person].[Person Id].[Person Id].Members,
                       [Measures].[Age at Date] >= 10 AND [Measures].[Age at Date] < 20
                      ).Count
           ...
       END

This assumes that you have the date of each record in a measure named Measures.[Date] directly in your fact table. 假设您在事实表中直接在名为Measures.[Date]的度量中具有每个记录的Measures.[Date] If that would not be the case, you could get that date as a date data type possibly from the current member of the date dimension similarly how the birth date is derived via the Key0 property. 如果不是这种情况,则可以从日期维度的当前成员中获取该日期作为日期数据类型,这与通过Key0属性导出出生日期类似。 I am assuming that you really use a Date data type in the dimension for the birth date attribute key, otherwise, a type conversion might be necessary. 我假设您确实在出生日期属性键的维度中使用了Date数据类型,否则,可能需要进行类型转换。 For purposes like that, there are many VBA functions available in Analysis Services (like the DateDiff that I used above), as documented here . 对于本这样的,也有分析服务(如许多可用的VBA函数DateDiff我上面使用的),作为记录在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM