天天看點

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

sql2018 ssas

介紹 (Introduction)

I am a DBA consultant and several times, in the past, I have been asked for a good tool to generate fast reports to get information about the company like total sales, sales per year, month, week, etc

我是一名DBA顧問,過去曾多次要求我提供一個很好的工具來生成快速報告,以擷取有關公司的資訊,例如總銷售額,每年,每月,每周的銷售額等。

SSAS is a Business Intelligence (BI) technology that Microsoft bought from Panorama Software in 1996. After the acquisition, the technology was upgraded and evolved and now it is part of the tools that come with SQL Server. This tool is an extremely powerful tool to create analytical reports fast. It works with cubes that are designed to generate reports with optimal performance using aggregated information stored in the cube.

SSAS是Microsoft于1996年從Panorama Software手中購買的一種商業智能(BI)技術。收購後,該技術得到了更新和發展,現在已成為SQL Server随附工具的一部分。 該工具是一種非常強大的工具,可以快速建立分析報告。 它與多元資料集一起使用,這些多元資料集旨在使用存儲在多元資料集中的聚合資訊來生成具有最佳性能的報告。

SSAS generally does consume a lot of space because it contains a lot of information ready to be used.

SSAS通常确實會占用很多空間,因為它包含了很多可供使用的資訊。

In this article, we will learn how to create your first cube from scratch. If you do not know anything about SSAS, this will be a great opportunity to learn.

在本文中,我們将學習如何從頭開始建立第一個多元資料集。 如果您對SSAS一無所知,這将是一個很好的學習機會。

要求 (Requirements)

  1. SSAS multidimensional database installed 已安裝SSAS多元資料庫
  2. SSDT 固态硬碟
  3. SQL Server 2016 Installed

    已安裝SQL Server 2016

  4. AdventureworksDW database AdventureworksDW資料庫
  5. SSMS 2017 installed 已安裝SSMS 2017

入門 (Getting started)

A cube in SSAS requires a data warehouse. The data warehouse is a special database designed to store enterprise information from different sources like Excel, ERPs, CRMs, flat files, legacy data and more.

SSAS中的多元資料集需要資料倉庫。 資料倉庫是一個特殊的資料庫,旨在存儲來自不同來源(如Excel,ERP,CRM,平面檔案,舊資料等)的企業資訊。

If you want to have an SSAS cube, creating the data warehouse is a process that takes a bit of time and resources. You can use SSIS to extract the information from sources to the data warehouse or use other ETL (Extract Transformation and load) tools like Talend Open Studio, SpagoBI Business Intelligence, Jaspersoft ETL and several other external tools.

如果要使用SSAS多元資料集,則建立資料倉庫是一個過程,需要一些時間和資源。 您可以使用SSIS從源中提取資訊到資料倉庫,也可以使用其他ETL(提取轉換和加載)工具,例如Talend Open Studio,SpagoBI Business Intelligence,Jaspersoft ETL和其他一些外部工具。

In this article, we will use the AdventureworksDW sample ready to be used. However, in the real-life, you will need to create some ETLs to automatically extract your business information to the Data Warehouse.

在本文中,我們将使用準備使用的AdventureworksDW示例。 但是,在現實生活中,您将需要建立一些ETL以自動将您的業務資訊提取到資料倉庫中。

We will create a cube based on the fact table FactResellerSales:

我們将基于事實表FactResellerSales建立一個多元資料集:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

FactResellerSales shows information about resellers’ sales like discount amounts, tax amounts, freight, sales amount and other related information.

FactResellerSales顯示有關經銷商銷售的資訊,例如折扣金額,稅額,運費,銷售金額和其他相關資訊。

We will create reports about the fact information combined with 2 dimensions:

我們将建立有關事實資訊的報告,并結合以下兩個次元:

  • currency

    貨币

  • sales territory

    銷售地區

The Currency dimension, will help us to detect amounts in different currencies around the world and Sales territory will help to detect sales, discounts, etc. per region.

貨币次元 ,将幫助我們檢測世界各地不同貨币的金額,而銷售地區将有助于檢測每個地區的銷售,折扣等。

In order to start get started in SQL Server Data Tools aka SSDT, open a new project and select Analysis Services Multidimensional and Data Mining models:

為了開始使用SQL Server資料工具(也稱為SSDT)入門,請打開一個新項目,然後選擇Analysis Services多元和資料挖掘模型:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the Solution Explorer, right-click Data Sources and select New Data Source:

在解決方案資料總管中,右鍵單擊“資料源”,然後選擇“建立資料源”:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

You will receive a Welcome wizard, press next:

您将收到一個歡迎向導,請按下一步:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the option to create a new Data Source based on existing or new connection and press the new button:

選擇選項以基于現有或新連接配接建立新的資料源,然後按新按鈕:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the Provider, select a Native OLEDB\SQL Server Native Client 11.0. For Server name, select the SQL Server with the AdventureworksDW database:

在提供程式中 ,選擇本機OLEDB \ SQL Server本機用戶端11.0。 對于“ 伺服器名稱” ,選擇帶有AdventureworksDW資料庫SQL Server:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the data connection, just created, and press next:

選擇剛剛建立的資料連接配接,然後按下一步:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In Impersonation information specify a user with access to the AdventureworksDW database:

在模拟資訊中,指定有權通路AdventureworksDW資料庫的使用者:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the Completing the wizard, press finish:

在“完成”向導中,按“完成”:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

We created the credentials to connect to the AdventureworksDW database. We will create now the views. In this process, we will select the tables to be included in the cube.

我們建立了憑據以連接配接到AdventureworksDW資料庫。 我們現在将建立視圖。 在此過程中,我們将選擇要包含在多元資料集中的表。

In solution explorer, select New Data Source View:

在解決方案資料總管中,選擇“建立資料源視圖”:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the data source just created:

選擇剛建立的資料源:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the table FactResellerSales:

選擇表FactResellerSales:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Include the dimensions DimSalesTerritory and DimCurrency. These dimensions include information about sales regions and currencies:

包括次元DimSalesTerritory和DimCurrency。 這些次元包括有關銷售地區和貨币的資訊:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once the wizard is completed, press finish:

向導完成後,按完成:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

As you can see, the fact table and the dimensions have a relationship. If the common columns are equal, the relationships are detected automatically:

如您所見,事實表和次元具有關系。 如果公共列相等,則将自動檢測到這些關系:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

To create a cube, we will add dimensions to the cube.

要建立一個多元資料集,我們将向多元資料集添加尺寸。

In the Solution Explorer, right click and select New Dimension:

在解決方案資料總管中,右鍵單擊并選擇“建立次元”:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

You can create a dimension based on templates, time tables or based on existing tables. Select the option Use an existing table:

您可以基于模闆,時間表或現有表建立次元。 選擇選項使用現有表 :

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select DimCurrency as the main table. By default, the key column is currency key:

選擇DimCurrency作為主表。 預設情況下,鍵列為貨币鍵:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In available attributes, select currency name:

在可用屬性中,選擇貨币名稱:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the Completing the Wizard step, press finish:

在“ 完成向導”步驟中,按完成:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Now, you will have a dimension created like this one.

現在,您将建立一個像這樣的尺寸。

Drag and drop the Currency Name from the attributes pane to Hierarchy:

将貨币名稱從屬性窗格拖放到層次結構:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once that you have the first dimension created, Currency name, we will create the sales territory dimension. In solution explorer, right click Dimensions and select New dimension:

建立第一個次元( 貨币名稱)後 ,我們将建立銷售地區次元。 在解決方案資料總管中,右鍵單擊尺寸,然後選擇新尺寸:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the option use an existing table:

選擇使用現有表的選項:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the table dimsalesterritory:

選擇表dimsalesterritory:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the attributes that you want to be browsable in the reports:

選擇要在報告中浏覽的屬性:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once that the wizard is completed, press finish:

向導完成後,按完成:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the new dimension created, click the process icon to process the dimension. The process will generate the structure and load data to the dimension from the SQL Server table:

在建立的新次元中,單擊“處理”圖示以處理該次元。 該過程将生成結構并将資料從SQL Server表加載到次元:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Press run to process the dimension:

按下運作以處理尺寸:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In the Process Progress, close the process once that the process is succeed:

在過程進度中,一旦過程成功,則關閉該過程:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

You can refresh the dimension to view the dimension just processed:

您可以重新整理次元以檢視剛剛處理的次元:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Process the Dim currency dimension also:

還要處理點心貨币次元:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once processed, you can verify in the Browser tab:

處理後,您可以在“浏覽器”标簽中進行驗證:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

We will now create the cube. In the Solution Explorer, right click Cubes and select New Cube:

現在,我們将建立多元資料集。 在解決方案資料總管中,右鍵單擊“ 多元資料集”,然後選擇“ 建立多元資料集”:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In Select Measure Groups Tables select FactResellerSales table. Measure group tables are used to include the table with data to measure. A measure can be the number of sales, amount sold, freight, etc.:

在“ 選擇路徑成本組表”中,選擇“ FactResellerSales表”。 路徑成本組表用于将表包含要度量的資料。 度量可以是銷售數量,銷售數量,運費等:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the data to measure. We will uncheck the keys and check the other attributes to measure:

選擇要測量的資料。 我們将取消選中鍵并檢查其他要測量的屬性:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Select the dimensions that you want to add to the cube:

選擇要添加到多元資料集的尺寸:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

You can also add the fact table as a dimension (degenerate dimension). In this example, we will not add it:

您還可以将事實表添加為維(退化維)。 在此示例中,我們将不添加它:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once that the cube is created, press finish:

建立多元資料集後,按完成:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

You will have the cube created with the fact table (in yellow) and the dimensions (in blue). Press the process icon to process the cube:

您将使用事實表(黃色)和次元(藍色)建立多元資料集。 按過程圖示以處理多元資料集:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

In Process Cube, press run to process the cube:

在“ 處理多元資料集”中,按運作以處理多元資料集:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Once processed, go to the browser:

處理後,轉到浏覽器:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Press the refresh icon:

按重新整理圖示:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Drag and drop some measures from the Measure Group to the design pane:

将一些度量從“路徑成本組”拖放到設計窗格中:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Now drag and drop the currency name to the graph pane, you will be able to see the measures grouped by currency:

現在,将貨币名稱拖放到圖形窗格中,您将可以看到按貨币分組的度量:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

Drag and drop the Sales Territory Country. You will now be able to see the measures grouped by currency and territory:

拖放銷售地區國家/地區。 現在,您将可以看到按貨币和地區分組的度量:

sql2018 ssas_如何使用SQL Server Analysis Services(SSAS)從頭開始建構多元資料集

結論 (Conclusion)

In this article, we learned how to create a cube in SSAS. We first need to create a data source to connect to our database. In this example, we connected to a data warehouse already created. For our example, we used AdventureworksDW, which is a sample database created for learning purposes.

在本文中,我們學習了如何在SSAS中建立多元資料集。 我們首先需要建立一個資料源以連接配接到我們的資料庫。 在此示例中,我們連接配接到已經建立的資料倉庫。 對于我們的示例,我們使用了AdventureworksDW,這是一個為學習目的而建立的示例資料庫。

The next step was to add the fact table and 2 dimensions as data source views. SSAS detected the primary keys and relationships by default.

下一步是添加事實表和2維作為資料源視圖。 預設情況下,SSAS檢測到主鍵和關系。

After that, we added 2 dimensions based on 2 data source views. The currency and sales territory dimensions.

之後,我們基于2個資料源視圖添加了2個次元。 貨币和銷售地區次元。

Finally, we created a cube based on the table factresellersales. We selected some columns as measures and we added the dimensions created. With the process buttons, we loaded data to the cubes. The cube as you can see is a simple way to generate multiple reports. You can create multiple reports without SQL knowledge or other reporting tools. With SSAS you can easily generate thousands of reports to accomplish your company needs.

最後,我們根據表factresellersales建立了一個多元資料集。 我們選擇了一些列作為度量,并添加了建立的維。 使用處理按鈕,我們将資料加載到了多元資料集。 如您所見,多元資料集是生成多個報告的一種簡單方法。 您可以在不具備SQL知識或其他報告工具的情況下建立多個報告。 借助SSAS,您可以輕松生成數千份報告來滿足您的公司需求。

參考資料 (References)

For more information about SSAS refer to these links:

有關SSAS的更多資訊,請參考以下連結:

  • What is Analysis Services? 什麼是分析服務?
  • Analysis Services Tutorials (SSAS) 分析服務教程(SSAS)
  • Analysis Services (SSAS) Cubes – Dimension Attributes and Hierarchies Analysis Services(SSAS)多元資料集–次元屬性和層次結構
  • SSAS Multidimensional or SSAS Tabular SSAS多元或SSAS表格
翻譯自: https://www.sqlshack.com/build-cube-scratch-using-sql-server-analysis-services-ssas/

sql2018 ssas