ssas 层次结构

We have already discussed quite some design tips for building Analysis Services (SSAS) Multidimensional cubes and dimensions:

我们已经讨论了很多有关构建Analysis Services(SSAS)多维数据集和维度的设计技巧:

  • Analysis Services (SSAS) Multidimensional Design Tips – Data Source View and Cubes Analysis Services(SSAS)多维设计技巧–数据源视图和多维数据集
  • Analysis Services (SSAS) Multidimensional Design Tips – Creating Dimensions Analysis Services(SSAS)多维设计技巧–创建尺寸

In this last part of the series we’ll look at attribute relationships and hierarchies in a dimension. As with the previous articles, the examples are created using the AdventureWorks 2014 Enterprise sample OLAP cube.

在本系列的最后一部分,我们将研究维度中的属性关系和层次结构。 与前面的文章一样,这些示例是使用AdventureWorks 2014 Enterprise示例OLAP cube创建的 。

层次结构 (Hierarchies)

Hierarchies are a useful tool in SSAS to reduce complexity between attributes and guide users into a certain drill-down behavior. In fact, it’s the first design tip SSAS gives you after creating a new dimension:

层次结构是SSAS中的有用工具,可以降低属性之间的复杂性,并指导用户进行某种向下钻取行为。 实际上,这是SSAS在创建新尺寸之后为您提供的第一个设计技巧:

We can find some examples in the Reseller dimension:

我们可以在转销商维度中找到一些示例:

In the browser, we can inspect the Reseller Bank hierarchy:

在浏览器中,我们可以检查转销商银行层次结构:

When building a Pivot table in Excel, it becomes clear how a hierarchy provides us with a clear drill-down path:

在Excel中构建数据透视表时,很清楚层次结构如何为我们提供清晰的向下钻取路径:

To avoid any confusion between the hierarchy levels and the attributes those levels originate from, it’s a good idea to hide the original attributes. For example, if you have a hierarchy with the levels Year – Month – Day and an attribute called Month, it might be confusing; why are there two month attributes? This is also a design tip provided by SSAS:

为了避免层次结构级别和这些级别所源自的属性之间的混淆,最好隐藏原始属性。 例如,如果您的层次结构的级别为Year – Month – Day,并且名为Month的属性可能会造成混淆; 为什么有两个月的属性? 这也是SSAS提供的设计技巧:

You can combine different attributes with each other, SSAS allows you to create hierarchies in all directions:

您可以相互组合不同的属性,SSAS允许您在各个方向上创建层次结构:

However, not all hierarchies might lead to optimal performance. SSAS warns you about this (see the yellow triangle with exclamation mark):

但是,并非所有层次结构都可能导致最佳性能。 SSAS为此警告您(请参阅带有感叹号的黄色三角形):

We’ll come back on this in the section about attribute relationships.

我们将在关于属性关系的部分中再次讨论这一点。

亲子层次 (Parent-child hierarchies)

A parent-child hierarchy is a special type of hierarchy. It’s number of levels can vary depending on the data. The best practices are quite simple: try to avoid them. Larger parent-child hierarchies have terrible performance and they are hard to secure. If you really need a parent-child structure, you can try to flatten the relationship into a pre-defined set of levels and use the HideMemberIf property to create a ragged hierarchy. You can read all about it in the article User-Defined Hierarchies – Ragged Hierarchies.

父子层次结构是一种特殊的层次结构。 它的级别数可以根据数据而有所不同。 最佳做法非常简单:尽量避免使用。 较大的父子层次结构的性能很差,而且很难保证。 如果确实需要父子结构,则可以尝试将关系展平为一组预先定义的级别,并使用HideMemberIf属性创建一个参差不齐的层次结构。 您可以在《 用户定义的层次结构-参差不齐的层次结构 》一文中阅读所有相关内容。

属性关系 (Attribute Relationships)

Attribute relationships are one of the most important concepts in SSAS dimensions. They tell the cube how the data is structured and they are vital to query performance. In the Reseller dimension, we can find the following relationships:

属性关系是SSAS维度中最重要的概念之一。 它们告诉多维数据集数据的结构,对查询性能至关重要。 在转销商维度中,我们可以找到以下关系:

This is the default behavior: every attribute is related to the key attribute (Reseller in this example). There are two kinds of relationships: flexible and rigid. Flexible relationships can change over time. For example, a reseller might change banks. Rigid relationships are fixed; they cannot change. Here, the relationship Reseller – Business Type is rigid (as indicated by the black arrow). This means that the business type will never change for a reseller. If it does, the processing of the dimension will fail if you use Process Update.

这是默认行为:每个属性都与键属性(在此示例中为Reseller)相关。 有两种关系: 柔性刚性 。 灵活的关系会随着时间而改变。 例如,经销商可能会更换银行。 刚性关系是固定的; 他们无法改变。 在这里,“经销商-业务类型”关系是固定的(如黑色箭头所示)。 这意味着,对于经销商,业务类型将永远不会改变。 如果确实如此,则在使用Process Update时 ,维度的处理将失败。

In a date dimension, you can typically set all relationships to rigid, as we can expect the calendar structure to never change.

在日期维度中,通常可以将所有关系设置为刚性,因为我们可以预期日历结构永远不会改变。

You can read the attribute relationships of the date dimension as follows: at the lowest level at the left we have the individual dates (which are the key attribute of the dimension). Dates roll up into months. Months roll up into quarters, quarters roll up into semesters and semesters finally roll up into years at the right.

您可以按以下方式读取日期维度的属性关系:在左侧的最低层,我们有各个日期(它们是维度的关键属性)。 日期累积到几个月。 几个月累加成季度,季度累加成学期,而学期最后累加成年。

For attribute relationships to function, data must be of a certain quality. There can be no duplicates (watch out for white space and different casing/accents) and a member cannot have multiple parents. For example, you cannot create an attribute relationship between month and year if you have the following data:

为了使属性关系起作用,数据必须具有一定的质量。 不能有重复项(注意空格和不同的大写字母/重音符号),并且成员不能有多个父母。 例如,如果您具有以下数据,则不能在月份和年份之间创建属性关系:

The problem here is that January is not unique. It appears in the years 2016 & 2017, which means it has multiple parents. If you would see the month January, you wouldn’t be able to tell from which year it is. The solution is simple: you either create a different month attribute that contains the year as well, to make it unique. For example: January, 2017. Or you can configure the existing attribute to have a composite key:

这里的问题是一月不是唯一的。 它出现在2016年和2017年,这意味着它有多个父母。 如果您看到一月,您将无法确定是哪一年。 解决方案很简单:您可以创建一个也包含年份的不同的month属性,以使其具有唯一性。 例如: 2017年1月 。 或者,您可以将现有属性配置为具有复合键:

Keep in mind SSAS won’t stop you from creating attribute relationships that aren’t supported by the underlying data. When processing the dimension however, you will be confronted with several error messages. Let’s illustrate with an example. Suppose we created the following attribute relationship between business type and Last Order Year in the Reseller dimension.

请记住,SSAS不会阻止您创建基础数据不支持的属性关系。 但是,在处理尺寸时,您将遇到一些错误消息。 让我们用一个例子来说明。 假设我们在“经销商”维度中在业务类型和“最后订单年”之间创建了以下属性关系。

When we process the dimension, we receive the following error:

处理尺寸时,会出现以下错误:

自然层次 (Natural hierarchies)

When you create a hierarchy and you create attribute relationships between the levels of the hierarchy, you have created a natural hierarchy. Such a hierarchy will be optimized for performance (for example when creating aggregations or a query plan). If you don’t have matching attribute relationships for the hierarchy, the hierarchy will be unbalanced and not optimized for performance. SSAS will warn you for this situation as discussed in the previous section.

创建层次结构并在层次结构的各个级别之间创建属性关系时,就创建了自然层次结构。 这样的层次结构将针对性能进行优化(例如,在创建聚合或查询计划时)。 如果该层次结构没有匹配的属性关系,则该层次结构将不平衡并且不会针对性能进行优化。 如上一节中所述,SSAS将针对这种情况警告您。

排序属性 (Sorting Attributes)

When there’s an attribute relationship between two attributes, you can use the child attribute to sort the parent attribute. A typical example is sorting the months. If you do not apply any sorting, months would be visualized in the following order:

当两个属性之间存在属性关系时,可以使用child属性对父属性进行排序。 一个典型的例子是对月份进行排序。 如果不进行任何排序,则月份将按以下顺序显示:

You can solve this issue in two ways:

您可以通过两种方式解决此问题:

  1. Assign the month number as the key column of the months, and the month name as the name column. 将月份号指定为月份的关键列,并将月份名称指定为名称列。
  2. Or you can define an attribute relationship between Month and the Month Number attributes. 或者,您可以定义月份和月份编号属性之间的属性关系。

With solution 1, you simply need to make sure the sorting is set to Key.

对于解决方案1,您只需要确保将排序设置为Key即可

Now the months will be sorted according to the Key column (1 = January, 2 = February and so on). For the other solution, we need to add an attribute relationship between Month of Year and Month Number:

现在,将根据“关键字”列对月份进行排序(1 =一月,2 =二月,依此类推)。 对于其他解决方案,我们需要在“月份的月份”和“月份的编号”之间添加属性关系:

Now we can change the OrderBy property of Month of Year to AttributeKey. The OrderByAttribute should be set to Month Number.

现在,我们可以将“月份的月份”的OrderBy属性更改为AttributeKey 。 OrderByAttribute应该设置为月数。

After processing the dimension, we can see the months are correctly sorted.

处理完维度后,我们可以看到月份已正确排序。

会员属性 (Member Properties)

Every attribute that has an attribute relationship with another attribute is a member property of that other attribute. This means there’s a direct relationship between those attributes. Let’s look at an example.

与另一个属性具有属性关系的每个属性都是该另一个属性的成员属性。 这意味着这些属性之间存在直接关系。 让我们来看一个例子。

In the date dimension, we have the attribute Calendar Quarter.

在日期维度中,我们具有日历季度属性。

It has attribute relationships with the following attributes:

它具有具有以下属性的属性关系:

  • Calendar Quarter of Year 日历季度
  • Calendar Semester of Year 年度日历学期
  • Calendar Semester 日历学期
  • Fiscal Quarter 财政季度

These attributes are also member properties of Calendar Quarter. We can easily check this in the dimension browser:

这些属性也是“日历季度”的成员属性。 我们可以在维度浏览器中轻松检查此内容:

Selecting items from the list would put them side by side with their parent attribute:

从列表中选择项目将使它们与它们的父属性并排放置:

SSAS can do this because it knows there’s a 1:1 relationship between the attribute and its member properties, thanks to the attribute relationships. Now, member properties become interesting for attributes that aren’t useful for direct analysis, because it wouldn’t make much sense to do so. Examples are phone numbers, email addresses, remarks etc. However, sometimes they are useful if you need more information about a certain member. For example, in an analysis with our top 5 worst performing sales persons, you might want to include the email addresses so you can easily contact them.

由于属性关系,SSAS知道属性与其成员属性之间存在1:1的关系,因此可以这样做。 现在,成员属性对于对直接分析无用的属性变得很有趣,因为这样做没有多大意义。 例如电话号码,电子邮件地址,备注等。但是,如果您需要有关某个特定成员的更多信息,有时它们很有用。 例如,在对我们表现最好的5名销售人员的分析中,您可能希望包括电子邮件地址,以便您轻松与他们联系。

Using such attributes directly in an analysis can cause performance problems. For example, suppose you have 30,000 customers each with a unique email address. If you create a pivot table with customers and their emails on the row axis, Excel will be slow because it will try to calculate subtotals for each customer and its email. This isn’t necessary because there’s a 1:1 relationship. We can avoid this by using the property AttributeHierarchyEnabled. When this is set to False, you won’t be able to use this attribute directly. You can only use it as a member property. Since SSAS knows there’s a 1:1 relationship, there will be no subtotals in Excel and performance will be much faster.

在分析中直接使用此类属性可能会导致性能问题。 例如,假设您有30,000个客户,每个客户都有一个唯一的电子邮件地址。 如果您在行轴上创建一个带有客户及其电子邮件的数据透视表,Excel将会变慢,因为它会尝试计算每个客户及其电子邮件的小计。 这是没有必要的,因为存在1:1的关系。 我们可以通过使用AttributeHierarchyEnabled属性来避免这种情况。 当将此设置为False时,您将无法直接使用此属性。 您只能将其用作成员属性。 由于SSAS知道存在1:1的关系,因此Excel中不会有小计,并且性能会更快。

In the Reseller dimension, we can see some attributes have been disabled (notice the gray icons).

在转销商维度中,我们可以看到一些属性已被禁用(请注意灰色图标)。

In Excel, we can see member properties in the tooltip:

在Excel中,我们可以在工具提示中看到成员属性:

You can also add member properties by right-clicking an attribute and selecting an item from the list Show Properties in Report.

您还可以通过右键单击一个属性,然后从“ 在报表显示属性 ”列表中选择一个项目来添加成员属性。

This will add the member property next to the parent attribute:

这会将member属性添加到parent属性旁边:

Notice the member property is not visible in the pivot table fields and there are no subtotals. Reporting Services also supports the use of member properties, but Power BI Desktop (currently) does not.

请注意,成员属性在数据透视表字段中不可见,并且没有小计。 Reporting Services还支持成员属性的使用,但Power BI Desktop(当前)不支持。

结论 (Conclusion)

In this article, we went over some best practices for hierarchies and relationships in SSAS dimensions. We showed why attribute relationships are important, why we would need hierarchies and how we can improve performance with member properties.

在本文中,我们介绍了有关SSAS维度中的层次结构和关系的一些最佳实践。 我们展示了为什么属性关系很重要,为什么我们需要层次结构以及如何使用成员属性提高性能。

Previous articles in this series

本系列以前的文章

  • Analysis Services (SSAS) Multidimensional Design Tips – Data Source View and Cubes Analysis Services(SSAS)多维设计技巧–数据源视图和多维数据集
  • Analysis Services (SSAS) Multidimensional Design Tips – Creating Dimensions Analysis Services(SSAS)多维设计技巧–创建尺寸

参考链接 (Reference Links)

  • MDX Member Properties – User-Defined Member Properties MDX成员属性–用户定义的成员属性
  • SSRS: Retrieving Member Properties in Reporting Services (with Analysis Services) SSRS:在Reporting Services中检索成员属性(与Analysis Services一起使用)
  • Analysis Services MOLAP Performance Guide for SQL Server 2012 and 2014 SQL Server 2012和2014的Analysis Services MOLAP性能指南
  • 4-6-Specifying Attribute Relationships in User-Defined Hierarchy 4-6-在用户定义的层次结构中指定属性关系

翻译自: https://www.sqlshack.com/analysis-services-ssas-multidimensional-design-tips-relations-hierarchies/

ssas 层次结构

ssas 层次结构_分析服务(SSAS)多维设计技巧–关系和层次结构相关推荐

  1. ssas如何创建分区_Analysis Services(SSAS)多维设计技巧–创建尺寸

    ssas如何创建分区 In the previous article, Analysis Services (SSAS) Multidimensional Design Tips – Data Sou ...

  2. ssas报表项目数据集_Analysis Services(SSAS)多维设计技巧–数据源视图和多维数据集

    ssas报表项目数据集 In this article, we'll discuss some tips and best practices regarding the design of OLAP ...

  3. 用分析服务SSAS解决占比、同比和环比问题

    本文将介绍用分析服务SSAS如何解决占比.同比和环比三个指标. 首先理解一下这三个指标的基本概念: 占比是指当前成员的值与该成员父级的值的比率,意思是在总数中所占的比重,比如某水果商店总销售额为14, ...

  4. mysql distinct 慢_分析MySQL中优化distinct的技巧

    有这样的一个需求:select count(distinct nick) from user_access_xx_xx; 这条sql用于统计用户访问的uv,由于单表的数据量在10G以上,即使在user ...

  5. 设计师张超越_超越响应能力–手机网站设计技巧

    设计师张超越 Smartphones are now the primary way people access the internet. We use them for over 60% of o ...

  6. ssas 维度属性_Analysis Services(SSAS)多维数据集–维度属性和层次结构

    ssas 维度属性 In Data Warehouse language, slicing and dicing is done with Dimension Attributes. Sometime ...

  7. 使用SQL Server分析服务定位目标用户

    如何定位目标用户,在任何一个业务单元中都是一个很重要的话题,尤其在预算有限的情况下,如何获得活动的最大收益,目标用户的定位都是很重要的手段. 本文将介绍如何通过SQL Server分析服务(SSAS) ...

  8. SSAS(分析服务)优化手册

    优化前注意事项 1.数据质量.数据仓库中维度表的数据质量要严格保证.比如店仓的大区.省区.管理城市等属性和店仓代码没有一对多的上下级关系,这样在设计店仓维度时,就无法建立有效的层次结构.这会拖慢查询时 ...

  9. 微软BI 之SSAS 系列 - 在 SQL Server 2012 下查看 SSAS 分析服务的模型以及几个模型的简单介绍...

    在SSDT中部署一个 SSAS 项目到本地服务器上出现错误. You cannot deploy the model because the localhost deployment server i ...

最新文章

  1. 也许你不知道的c#基本数据类型及其默认值
  2. Linux和optee双系统中1020-1023号的中断号的使用
  3. Hibernate Mysql 写入中文乱码 解决方法
  4. 玩cf出现outofmemory_完美解决outofmemory|Win7系统CF出现out of memory的解决方法
  5. 三种基本的存储引擎比较
  6. package javax.servlet.jsp.tagext does not exist的错误消息如何解决
  7. 领域模型(domain model)贫血模型(anaemic domain model)充血模型(rich domain model)
  8. 进程间通信之管道通信
  9. Java开发人员需要掌握数据库的知识点有哪些?
  10. mysql shell 所有表_删除mysql数据库中所有表的shell脚本
  11. JavaScript学习系列之执行上下文与变量对象篇
  12. linux下使用dd命令制作ubuntu的u盘启动,Ubuntu使用dd命令制作U盘系统启动盘
  13. java 如何结束线程_java中,如何安全的结束一个正在运行的线程?
  14. ef 批量保存 oracle,mybatis-oracle与mysql批量添加
  15. 在缺乏贷后数据的情况下做好策略的调整把控
  16. 为什么我们一直赚不到钱?
  17. 树与图的深度优先遍历
  18. p1186反素数(模板题)
  19. 疯狂Java讲义(十三)----第一部分
  20. 一文详解自动驾驶技术与挑战

热门文章

  1. 64匹马,8个赛道,通过比赛,决出前四名。
  2. HTML5画布(矩形)
  3. 字符串压缩——C语言
  4. Apache HTTP Server Version 安装简要记录
  5. escape encodeURI 和encodeURIComponent JS编码
  6. 利用JDK1.5的工具对远程的Java应用程序进行监测(摘录)
  7. 用JS实现简单的省市联动
  8. 线程中这么调用类_一文学会 Python 多线程编程
  9. 东北老家有人在大连娶了媳妇
  10. 一个女人在公司做领导是如何在4年内做到年薪200万的?