olap 多维分析_SQL Server中的OLAP多维数据集

olap 多维分析

An Online Analytical Process (OLAP) cubes are used as an analytical tool. An OLAP Cube is a multi-dimensional database that is optimized for reporting purposes.

联机分析过程(OLAP)多维数据集用作分析工具。 OLAP多维数据集是为报表目的而优化的多维数据库。

Let’s get started with Cubes in their pictorial representation. For that, I have put the below screenshot from Youtube.com

让我们以Cubes的图形表示形式开始。 为此,我从Youtube.com放了以下屏幕截图

olap 多维分析_SQL Server中的OLAP多维数据集

The above OLAP cube has measures, Sales Amount, Sales Cost, Sales Qty and Profit Margin. These measures are analyzed using Product Categories, Time dimensions. If we further analyze, Time Dimension, we will see that year and month are the main attributes in the Time Dimension.

上面的OLAP多维数据集具有度量,销售金额,销售成本,销售数量和利润率。 这些度量使用产品类别,时间维度进行分析。 如果我们进一步分析“时间维度”,我们将看到年和月是“时间维度”的主要属性。

In the Microsoft BI family, SQL Server Analysis Service (SSAS) supports cubes.

在Microsoft BI家族中,SQL Server Analysis Service(SSAS)支持多维数据集。

Let us open SQL Server Data Tools (SSDT) and create an Analysis Services Multi-Dimensional and Data Project is created as shown in the following screen.

让我们打开SQL Server数据工具(SSDT)并创建Analysis Services多维,然后创建数据项目 ,如以下屏幕所示。

olap 多维分析_SQL Server中的OLAP多维数据集

Following is the Solution Explorer for the sample project created in the previous screen.


以下是在上一个屏幕中创建的示例项目的解决方案资源管理器。

olap 多维分析_SQL Server中的OLAP多维数据集

Let us create a data source for the sample project. We will be using the AdventureWorksDW sample database in this article.

让我们为示例项目创建一个数据源。 我们将在本文中使用AdventureWorksDW示例数据库。

Next is to create a data source view, from that we will be selecting the needed Fact and Dimension tables.

接下来是创建数据源视图,从中我们将选择所需的Fact和Dimension表。

olap 多维分析_SQL Server中的OLAP多维数据集

From the above screen, the FactInternetSales fact table and Sales Territory, Currency, Product, Customer, and Promotion dimensions are added.

在上面的屏幕中,添加了FactInternetSales事实表以及“销售地区”,“货币”,“产品”,“客户”和“促销”维度。

There is an easy way to add all the above tables with the least number of clicks. First, select the FactInterSales fact table and move it to the right-hand side then click the Add Related Tables button. With this, another fact table, FactInternetSalesReason will be added which should be removed as it is not required in this example. After these few clicks, you will end up with the above screen.

有一种简单的方法可以以最少的点击次数添加上述所有表格。 首先,选择FactInterSales事实表并将其移到右侧,然后单击“ 添加相关表”按钮。 这样,另一个事实表FactInternetSalesReason 将添加,由于在此示例中不需要,因此应将其删除。 点击几下后,您将看到上面的屏幕。

The following screen is the star-schema for the chosen data source view.

以下屏幕是所选数据源视图的星型图。

olap 多维分析_SQL Server中的OLAP多维数据集

Since foreign key constraints are implemented in these tables, relationships are automatically created. If the foreign key constraints are not implemented, you need to create the relationships manually.

由于在这些表中实现了外键约束,因此将自动创建关系。 如果未实现外键约束,则需要手动创建关系。

Then we need to start creating the OLAP Cube. Right-click the Cube node and select the New Cube…. This will take you through a cube creation wizard.

然后,我们需要开始创建OLAP多维数据集。 右键单击“多维数据集”节点,然后选择“ 新建多维数据集”。 这将带您完成多维数据集创建向导。

First, you need to choose the measures columns.

首先,您需要选择度量列。

Measures are the core element of the dimensional model. Measures are data values that can be aggregated as summed, averaged, minimized, etc.

度量是维模型的核心元素。 度量是可以汇总,平均,最小化等方式汇总的数据值。

Let us see how to choose a measure from the following screenshot.

让我们看看如何从以下屏幕截图中选择一种度量。

olap 多维分析_SQL Server中的OLAP多维数据集

As we know, FactInterSales is the measure group table. If you are not sure, which should not be the case, click the Suggest button. Suggest button will provide you the suggestion for the measure groups.

众所周知,FactInterSales是度量值组表。 如果不确定(不是这种情况),请单击“建议”按钮。 “建议”按钮将为您提供有关度量值组的建议。

Next is to select measure columns from the following screen.

接下来是从以下屏幕中选择度量列。

olap 多维分析_SQL Server中的OLAP多维数据集

It is important to note that you have to choose only the required measure columns. If unnecessary columns are selected, it will cause delays in cube processing. In the above example, we have eliminated the Revision Number column which is not a business measure column.

重要的是要注意,您只需要选择所需的度量列。 如果选择了不必要的列,则将导致多维数据集处理中的延迟。 在上面的示例中,我们删除了“修订号”列,该列不是业务指标列。

In an OLAP Cube, after the measures next important concept is Dimension. Dimension is a collection of referenced information so that measures can be analyzed into detail.

在OLAP多维数据集中,度量之后的下一个重要概念是Dimension。 维度是参考信息的集合,因此可以对度量进行详细分析。

From the following screen, you can choose the required dimensions and modified them as shown below.

在以下屏幕中,您可以选择所需的尺寸并对其进行如下所示的修改。

olap 多维分析_SQL Server中的OLAP多维数据集

With this basic OLAP Cube configuration is completed and you will the Project Explorer as shown in the below screenshot.

有了此基本的OLAP Cube配置,您将完成Project Explorer,如下面的屏幕快照所示。

olap 多维分析_SQL Server中的OLAP多维数据集

Though the cube is configuration is completed, every dimension is empty. So it is important to add attributes to the dimensions.

尽管完成了多维数据集的配置,但是每个维度都是空的。 因此,向维添加属性很重要。

olap 多维分析_SQL Server中的OLAP多维数据集

It is essential to add only the required attributes. Otherwise, the cube process will take longer and the cube will be larger. If the cubes are larger, cube accessing also will have a negative impact. Apart from the attributes, hierarchies can be created so that users can analyze data much effectively.

仅添加必需的属性是必不可少的。 否则,多维数据集处理将花费更长的时间,并且多维数据集将更大。 如果多维数据集较大,则访问多维数据集也会产生负面影响。 除属性外,还可以创建层次结构,以便用户可以更有效地分析数据。

Now you are ready to process the OLAP Cube. By default, Cube will have MOLAP storage. This means all the measures and dimensions are stored in the cube after processing. Since all the data is stored in the cube, data accessing is very fast as no processing is required.

现在,您可以处理OLAP多维数据集了。 默认情况下,多维数据集将具有MOLAP存储。 这意味着所有度量和尺寸在处理后都存储在多维数据集中。 由于所有数据都存储在多维数据集中,因此数据访问非常快速,因为不需要处理。

olap 多维分析_SQL Server中的OLAP多维数据集

After the cube process, now the cube is ready to access. There are multiple ways to access the processed cubes.

多维数据集处理之后,现在可以访问多维数据集了。 有多种方法可以访问已处理的多维数据集。

The following screenshot shows how to access the cube using the visual studio itself.

以下屏幕截图显示了如何使用Visual Studio本身访问多维数据集。

olap 多维分析_SQL Server中的OLAP多维数据集

In this, it is simply a matter of drag and drop the columns. You will be able to see the necessary data in a quick time.

在此,只需拖放列即可。 您将能够快速查看必要的数据。

One of the main methods of accessing the OLAP Cube is using an Excel pivot table. Since pivot tables are more used by the business users, they can leverage the excel features by using the cubes.

访问OLAP多维数据集的主要方法之一是使用Excel数据透视表。 由于数据透视表被业务用户更多地使用,因此它们可以通过使用多维数据集来利用excel功能。

olap 多维分析_SQL Server中的OLAP多维数据集

In the Excel pivot tables, you can use columns as well as rows to select dimensions. This means you can perform the ad-hoc analysis much easier.

在Excel数据透视表中,您可以使用列和行来选择尺寸。 这意味着您可以更轻松地执行即席分析。

olap 多维分析_SQL Server中的OLAP多维数据集

In addition to the simple analysis, users can use created hierarchies as shown in the below screenshot.

除了简单的分析,用户还可以使用创建的层次结构,如下面的屏幕快照所示。

olap 多维分析_SQL Server中的OLAP多维数据集

Apart from EXCEL, SSRS, PowerBI, SSMS can be used to access the cubes. There is a special type of MDX queries which can be used to retrieve data from Cubes.

除EXCEL,SSRS,PowerBI和SSMS外,还可以使用SSMS来访问多维数据集。 有一种特殊类型的MDX查询,可用于从多维数据集检索数据。

This article covers the basics of OLAP Cubes implementation using the SQL Server Analysis Service. However, there are additional features in cubes such as Calculations, KPI, Actions, Partitions, Aggregations, Perspectives, and Translation, etc. Those options need to be discussed in separate articles. Even without those advanced options, OLAP Cube is an important option that is available for the end-users.

本文介绍了使用SQL Server Analysis Service实施OLAP Cubes的基础知识。 但是,多维数据集中还有其他功能,例如计算,KPI,操作,分区,聚合,透视图和转换等。这些选项需要在单独的文章中进行讨论。 即使没有这些高级选项,OLAP Cube也是可供最终用户使用的重要选项。

翻译自: https://www.sqlshack.com/olap-cubes-in-sql-server/

olap 多维分析