Você está na página 1de 15

11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

SQLShack Treinamento SQL Server Espanhol 

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 1/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

Implementando um modelo tabular SSAS para


análise de dados
4 de agosto de 2020 por Dinesh Asanka

Introdução
Depois de discutir diferentes aspectos dos cubos MDM SSAS, veremos a ferramenta OLAP reco‐
mendada pela Microsoft, Modelos Tabulares SSAS para análise de dados. Existem algumas vanta‐
gens de usar modelos tabulares em vez de MDM listadas abaixo.

Column Store -> SSAS tabular usa o mecanismo xVelocity , que é um mecanismo baseado
em colunas. Devido à natureza baseada em colunas, utiliza melhor compactação. Isso signi‐
fica que os modelos tabulares têm vantagem de espaço em disco sobre os cubos MDM
In-Memory -> A opção padrão para modelos de dados tabulares está na memória, o que au‐
mentará o desempenho de usabilidade
Fácil utilização -> Ao contrário do MDM, projetar um modelo em tabela é muito mais fácil.
Se você conhece padrões de design de banco de dados relacionais, poderá se tornar um
bom designer de modelos tabulares. Além da facilidade de uso, o tabular usa a consulta
DAX, que é muito equivalente à expressão do Excel. Portanto, as expressões DAX são muito
mais fáceis do que o MDX usado no cubo MDM
Cloud-Ready -> O serviço Azure Analysis tem apenas a opção tabular como opção PaaS, não
em MDM. Isso significa que ao desenvolver modelos tabulares, é mais fácil implantá-los no
Azure. Se você tiver cubos MDM, precisará ter uma caixa virtual com a instância do SQL Ser‐
ver Analysis Service ou precisará reescrever o cubo MDM em modelos de dados tabulares

Instalação
É importante observar que você precisa ter instâncias diferentes para MDM e Tabular. Isso significa
que, no momento da instalação, você precisa decidir que tipo de SQL Server Analysis Server você
precisa. Além disso, após instalar o serviço SSAS, você não poderá converter para outro serviço.
Além do servidor, não é possível converter o MDM em tabular e vice-versa após instalar o SQL Ser‐
ver Analysis Service.

Modelagem
Vamos ver como modelar usando o modelo tabular SSAS com o banco de dados de exemplo, Ad‐
https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 2/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

ventureworksDW. Na ferramenta SQL Server Data, vamos criar um projeto tabular do Analysis
Service.

When the tabular is created, you need to provide a tabular name, workspace server and the com‐
patible level that you are willing to deploy this tabular model to. Following is the Tabular Model Ex‐
plorer that you will see after the creation of the Tabular Model.

Let us first create the Data Sources that will make a connection to the SQL Server database
AdventureWorksDW.

The following screenshot shows the possible data sources for the Tabular models which covers da‐
tabase such as SQL Server, Oracle, Microsoft Azure, DB2 etc.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 3/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

After choosing the database, next, we need to provide the server name and database as shown
below.

Next, let us choose the following tables and rename the tables with some friendly names as shown
in the below screenshot.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 4/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

We have mainly chosen FactInternetSales and its related table. This means we need to choose Fac‐
tInternetSales, DimCurrency, DimCustomer, DimDate, DimProduct, DimProductCategory,
DimProductSubcategory, DimPromotion, DimSalesTerritory tables.

We do not need all the columns for the model. Therefore, we need to remove the unnecessary co‐
lumn by clicking the Preview & Filter button.

You can remove the columns by un-ticking the column name.

We have removed some audit dates and different language columns. Then data will be imported to
the project. If you missed removing any columns, you can remove the columns after importing
them as well in the later stage.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 5/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

The following is the SSAS Tabular model data structure.

If there are foreign key relationships available for the tables, those relationships will be available in
the above diagram. If there are no relationships defined in the database level, you need to create
relationships in the Tabular model. Please note that you cannot define many-to-many relationships
like MDM cubes.

You can hide Key columns as they are needed for the relation and you do not want users to see
them. Further, you can rename the columns with friendly names as shown below.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 6/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

In the above SSAS Tabular model, you will see that the Date table is related to the Internet Sales
table three times but only one relationship is with Active and the other two relationships are inac‐
tive as shown below.

In MDM, there is an option of Role Playing Dimension where one dimension can be linked to multi‐
ple keys in the fact tables. However, the role Playing Dimension option is not available in Tabular
modelling. Therefore, you need to add multiple instances of the Date table. However, these are in‐
dependent instances and you need to configure them differently as shown below.

The next important aspect of the Tabular modules is the ability to create columns. For example, let
us create Full Name column using the First Name Middle Name and Last Name Age from the
https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 7/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados
us create, Full Name column, using the First Name, Middle Name and Last Name, Age from the
Date of the Birth column, Income Group, Margin form the Revenue and Cost.

The following are the simple DAX function that can be used for the calculated columns.

Column Expression

Full Name =TRIM(CONCATENATE( CONCATENATE(Customer[First Name] , ” ” & Customer[Middle


Name]), ” ” & Customer[Last Name]))

Age =DATEDIFF(Customer[Birth Date],TODAY(),YEAR)

Income =IF (Customer[Yearly Income] < 25000,” 0 – 25K”,IF(Customer[Yearly Income] < 75000,” 25K –
Category 75K”,IF( Customer[Yearly Income] < 150000,”75K = 150K”,” 150K-200K”)))

These calculations are done in the customer tab as shown below.

Similarly, you can calculate the Profit for the Internet Sales table using =’Internet Sales'[Revenue] –
‘Internet Sales'[Cost] formula.

Measures

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 8/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados
Now let us create measures for the Internet Sales table. We will create measures for Quantity, Reve‐
nue, Cost and Profit columns.

In the above model, Quantity, Cost, Revenue and Profit is summed and Margin measure is created
with the Profit / Cost formula. You can use different types of formatting such as Percentage, Nume‐
ric, Currency etc.

After these configurations, now you are ready to test the Tabular Model using Microsoft Excel. This
is the standard pivot table usage so the end-users will not have any impact.

Hierarchies
https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 9/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

Like we created hierarchies for MDM models, we can create hierarchies for the SSAS Tabular Mo‐
dels as well.

After selecting the hierarchy, you need to drag and drop the columns to the desired hierarchy level.

In the above example, two hierarchies are created namely Calendar and Fiscal. It is important to
note that, you need to create the same hierarchies in other date tables as they are not
automatically created.

Now let us view the hierarchy from Microsoft Excel as shown in the below screenshot.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 10/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

You will see that the Month Name and Week Name is ordered by the alphabetic order not by how
it should be ordered. Ideally, Month Name should be ordered by the Month Number while the
Week Name should be ordered by the Week Number of the Week.

Selecting the Properties of Month, you should select the Sort By Column as the
MonthNumberofYear as shown in the below screenshot.

Da mesma forma, o nome da semana deve ser ordenado na coluna DayNumberofWeek . Agora
você pode ver que o nome do mês e da semana estão conforme mostrado na imagem abaixo

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 11/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

Implantando o modelo tabular SSAS


Após a configuração, você pode processar e implementar o modelo tabular para que ele esteja
pronto para acesso pelos usuários finais. Você pode processar todas as tabelas das tabelas selecio‐
nadas. Terminado o processamento, temos que prosseguir com a implantação do tabular. Esta é a
tela final que você obterá após a implantação do tabular.

Em seguida, o modelo tabular SSAS deve estar disponível para acesso do usuário final. Você pode
acessar o Tabular no SQL Server Management Studio (SSMS).

Outros recursos dos modelos tabulares SSAS


Existem alguns outros recursos importantes no modelo tabular SSAS, como principais indicadores
de desempenho, partições, tradução e perspectivas semelhantes aos cubos MDM. Você pode criar
https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 12/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados
p ,p ç , ç p p p
funções e fornecer segurança em nível de linha conforme necessário para que os usuários acessem
os modelos tabulares.

Além da opção in-Memory, existe uma opção Direct Query para que os modelos tabulares SSAS
possam obter os dados diretamente das fontes de dados. No entanto, existem algumas limitações
na opção Consulta Direta em Modelos Tabulares.

Conclusão
O modelo tabular SSAS é uma ferramenta simples que pode ser usada para analisar dados. Além
da simplicidade de uso, esta opção traz benefícios de desempenho. Ele usa a consulta DAX que é
semelhante às expressões do Excel. Além disso, possui recursos como KPI, Partições, Perspectiva.

Ver mais
Para uma ferramenta de documentação de cubo e banco de dados SSAS , considere o ApexSQL
Doc, que pode documentar bancos de dados multidimensionais e tabulares em diferentes forma‐
tos de saída, por exemplo, HTML, PDF, Word etc.

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 13/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

Dinesh Asanka 
Dinesh Asanka é MVP da categoria SQL Server nos últimos 8 anos. Ele tra‐
balha com SQL Server há mais de 15 anos, escreveu artigos e é coautor de li‐
vros. Ele é apresentador em vários grupos de usuários e universidades. Está
sempre disponível para aprender e compartilhar seus conhecimentos.

Veja todos os posts de Dinesh Asanka

Postagens Relacionadas:
1. Automatize a documentação do modelo tabular do SQL Server Analysis Server
2. Introdução ao monitoramento do SQL Server Analysis Services (SSAS)
3. Principais livros do SQL Server
4. Criando seu primeiro banco de dados de modelo tabular SSAS
5. Perguntas da entrevista SSAS para modelos multidimensionais

Serviços de análise (SSAS)


168 visualizações

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 14/15
11/30/23, 6:23 PM Implementando um modelo tabular SSAS para análise de dados

0 Comments 
1 Login

G Start the discussion…

LOG IN WITH OR SIGN UP WITH DISQUS ?

Name

 2 Share Best Newest Oldest

Be the first to comment.

Subscribe Privacy Do Not Sell My Data

© 2023 Quest Software Inc. ALL RIGHTS RESERVED. | GDPR | Terms of Use | Privacy

https://www.sqlshack.com/implementing-an-ssas-tabular-model-for-data-analytics/ 15/15

Você também pode gostar