ssas表格模型 权限控制

To make the first steps into the BI world easier, you just need to build one SSAS Tabular model database. In this article, we will learn some basics of querying a SSAS Tabular model database with simple DAX queries, starting with a theoretical approach, and then retrieve data and analyze it.

为了使进入BI世界的第一步更容易,您只需要构建一个SSAS Tabular模型数据库 。 在本文中,我们将学习从理论方法入手,通过简单的DAX查询来查询SSAS表格模型数据库的一些基础知识,然后检索数据并进行分析。

Requirements for querying with DAX include SQL Server Management Studio 2014 or higher with an installed SSAS Tabular instance, and a deployed SSAS Tabular model database.

使用DAX进行查询的要求包括具有已安装的SSAS Tabular实例SQL Server Management Studio 2014或更高版本,以及已部署的SSAS Tabular模型数据库。

准备环境 (Preparing the environment)

In order to get insight in a Tabular model database, the main method is data retrieval from tables through queries; after that, performing additional simple or complex calculations can take place.

为了了解表格模型数据库,主要方法是通过查询从表中检索数据。 之后,可以执行其他简单或复杂的计算。

Querying a SSAS Tabular model database in this article will perform in SSMS, within the MDX query window, as shown in the picture:

查询本文中的SSAS表格模型数据库将在MDX查询窗口中的SSMS中执行,如图所示:

Note: Don’t get confused with DAX code presence in a MDX query – both of them, DAX and MDX, can query a Tabular model database.

注意 :不要与MDX查询中的DAX代码存在混淆-DAX和MDX都可以查询表格模型数据库。

数据分析表达式(DAX)概述 (Data Analysis Expression (DAX) overview)

DAX originally emerged from a Power Pivot add-in for Excel, as a formula language extension for creating calculated columns and measures for data analysis (which are also integral elements of one SSAS Tabular model database, too), but when Microsoft added support for DAX queries in SQL Server 2012, BI experts started “daxing” data from Tabular model databases.

DAX最初是从Excel的Power Pivot加载项中出现的 ,它是一种公式语言扩展,用于创建计算列和度量值以进行数据分析(它们也是一个SSAS表格模型数据库的组成部分),但是当Microsoft添加对DAX的支持时在SQL Server 2012中进行查询后,BI专家开始从表格模型数据库中“ daxing”数据。

That trend continues, because of simplicity and fast query execution (related to DirectQuery mode in SSAS Tabular).

由于简单和快速的查询执行(与SSAS表格中的DirectQuery模式有关),这种趋势仍在继续。

DAX query consists of a function and number of expressions (e.g.):

DAX查询由一个函数和多个表达式组成 (例如):

Functions are the main part of the query, and they act similar to some T-SQL statements (as we will see later). Expressions consist of values, operators and constants. The difference between expressions in Excel (Power Pivot) and SSMS should be apparent; In Power PIvot, expressions start with equal sign “=”, and they look like formulas:

函数是查询的主要部分,它们的行为类似于某些T-SQL语句(我们将在后面看到)。 表达式由值,运算符和常量组成。 Excel(Power Pivot)和SSMS中的表达式之间的区别应该显而易见。 在Power PIvot中 ,表达式以等号“ =”开头,它们看起来像公式:


='Product'[Standard Cost]

In this example, ‘Product’[Standard Cost] is value, and there are no operators (+, – e.g.) or constants.

在此示例中, “产品” [标准成本]是值,并且没有运算符(例如+,-)或常量。

DAX expressions in SSMS are more complex, because of the whole syntax. Although there are many rules, the following are just some examples.

由于整个语法 ,SSMS中的DAX表达式更加复杂。 尽管有很多规则,但以下仅是一些示例。

查询SSAS表格模型数据库 (Querying SSAS Tabular model database)

The foundation of every Tabular DAX query is the Evaluate statement:

每个表格DAX查询的基础是Evaluate语句:


evaluate Product

Or displayed in SSMS, a query result below:

或显示在SSMS中,查询结果如下:

The Evaluate statement is similar to a SELECT in T-SQL, because it retrieves all columns from a particular table, in this case, the Product table. Similar T-SQL code would be:

Evaluate语句与T-SQL中的SELECT相似,因为它从特定表(在本例中为Product表)中检索所有列。 类似的T-SQL代码为:


SELECT * FROM dbo.Product

The query result, the selected columns, would be the same as in querying the SQL Server database, but the main difference is the naming of columns. Columns in SSAS Tabular model database don’t use CamelCase or pascalCase naming methods. They include the actual table name in the title and allow space characters, as shown in the picture below:

查询结果(选定的列)将与查询SQL Server数据库中的结果相同,但主要区别是column命名 。 SSAS表格模型数据库中的列不使用CamelCase或pascalCase命名方法。 它们在标题中包括实际的表名,并允许使用空格字符,如下图所示:

It is important to know the exact names of the elements, because of using particular tables and columns in DAX expression(s). Regarding the syntax, format tables like this:

重要的是要知道元素的确切名称,因为在DAX表达式中使用了特定的表和列。 关于语法,格式化表如下:


evaluate 'Product'

Now, the table Product in this expression is surrounded with apostrophe characters, and executing the query shows the same result, as with ‘Product’ expression without apostrophes.

现在,该表达式中的表Product用撇号字符包围,并且执行查询时显示的结果与无撇号的'Product'表达式相同。

Note: Statements in DAX query code are case-insensitive:

注意 :DAX查询代码中的语句不区分大小写


evaluate 'Product'
//or
EVALUATE 'Product'

To start creating some complex queries, format the evaluate statement as shown:

要开始创建一些复杂的查询,请格式化显示的评估语句,如下所示:

evaluate ( ‘Product’ )

评估(“产品”)

or like this, which will be used in the article:

或类似的方法,将在本文中使用:


evaluate('Product')

Putting brackets (as parenthesis operator) after function means that query will become complex, although this query shows the same results as in the previous queries. Also, choose a suitable format according to your personal preferences, but pay attention on the examples from this article (number of brackets etc.).

在函数后面加上方括号(作为括号运算符 )意味着查询将变得复杂,尽管此查询显示的结果与之前的查询相同。 另外,根据个人喜好选择合适的格式,但请注意本文中的示例(括号等)。

  1. VALUES function

    VALUES功能

    This query will show all values of the Product Name column only:

    此查询将仅显示“产品名称”列的所有值:

    
    evaluate(values('Product'[Product Name]))

    Values function shows the distinct values of specified column, without duplicates:

    函数显示指定列的不同值,不重复:

  2. ORDER BY function

    ORDER BY功能

    ORDER BY function is exact as it is in T-SQL:

    ORDER BY函数与T-SQL中的函数完全相同:

    
    evaluate('Product')
    order by [Product Subcategory Id]

    It orders the query result according to the selected column as a parameter. In this case, the parameter is Product Subcategory Id.

    它根据所选列将查询结果排序为参数。 在这种情况下,参数为产品子类别ID

    Multiple columns can be set as parameters, as shown:

    可以将多个列设置为参数,如下所示:

    
    evaluate('Product')
    order by [Product Subcategory Id], [Color]

    Order can be ascending or descending (ASC or DESC in the end of statement):

    顺序可以升序或降序(语句末尾为ASC或DESC):

    
    evaluate('Product')
    order by [Color] DESC
  3. START AT function

    START AT功能

    This function sets the starting point (first row) from which values will be displayed:

    此函数设置显示值的起点(第一行):

    
    evaluate('Geography')
    order by [State Province Name]
    start at "Illinois"

    In this example, the value “Illinois” is set:

    在此示例中,设置了“伊利诺伊州”值:

  4. FILTER function

    过滤功能

    With FILTER function, particular column values with distinctive rows can be isolated as in T-SQL WHERE statement:

    使用FILTER函数,可以像T-SQL WHERE语句中那样隔离具有独特行的特定列值:

    
    evaluate(filter('Geography', [State Province Name] = "North Carolina"))

    In this statement, use the comparison operators:

    在此语句中,使用比较运算符 :

    One more example of the Filter function, with a numeric value:

    过滤器函数的另一个示例,带有数字值:

    
    evaluate(filter('Product', [Product Id] >= 82))

    Notice that the value 82 doesn’t have any surrounding symbols, and “North Carolina” has quotation marks – that is because of the data type of the columns (Int and Text).

    注意,值82没有任何周围的符号, “ North Carolina”带有引号–这是由于列的数据类型(Int和Text)所致。

  5. ADDCOLUMN function

    ADDCOLUMN功能

    This is function adds a custom column Daily Profit, and it is dependent on the FILTER function:

    此函数添加了一个自定义列Daily Profit ,它取决于FILTER函数:

    
    evaluate
    (filter(addcolumns(
    'Product',
    "Daily Profit", 'Product'[List Price] - 'Product'[Standard Cost]),
    'Product'[List Price] > 1))
    order by 'Product'[Product Subcategory Id]

    As can be seen, column Daily Profit is the product of calculation (subtraction) between two previously specified columns.

    可以看出,“ 每日利润”列是两个先前指定的列之间的计算(减)乘积。

  6. SUMMARIZE function

    SUMMARIZE函数

    This function acts as an aggregated and simplified substitute of T-SQL GROUP BY or JOIN statements in T-SQL. In one case, the desired columns are retrieved and shown as a result of the query, without any mathematical operation:

    此函数充当T-SQL中T-SQL GROUP BY或JOIN语句的聚合和简化替代。 在一种情况下,无需任何数学运算即可检索所需的列并将其显示为查询的结果:

    
    evaluate
    summarize('Geography', 'Geography'[City], 'Geography'[Postal Code])

    The syntax for the SUMMARIZE function is to define the primary table (Product), then define the columns which will be included in the result.

    SUMMARIZE函数的语法是定义主表(产品),然后定义将包含在结果中的列。

    Also, with the Order by clause included:

    另外,在包含Order by子句的情况下:

    
    evaluate
    summarize('Geography', 'Geography'[City], 'Geography'[Postal Code])
    order by [Postal Code]

    The result is put in order of Postal code:

    结果按邮政编码顺序排列:

    In this example we will include summary calculations of Total Days of Manufacture August 2016:

    在此示例中,我们将包括2016年8月制造总天数的摘要计算:

    
    evaluate
    summarize('Product', "Total Days of Manufacture August 2016",
    sum('Product'[Days To Manufacture]))

    This result was created by defining the primary table, and then naming the measure (the title must be within quotation marks) and performing the calculation with a SUM function on the particular column with the table specified.

    通过定义主表,然后命名度量(标题必须在引号内)并使用SUM函数对指定表的特定列执行计算来创建此结果。

  7. ROW function

    ROW功能

    These statements can be very interesting to show a combination of particular functions while querying a SSAS Tabular model database.

    这些语句在查询SSAS表格模型数据库时显示特定功能的组合可能非常有趣。

    The ROW function returns a single, custom titled column and one row with the specific value. Execute these specific (and interesting) expressions:

    ROW函数返回单个自定义标题列和具有特定值的一行。 执行以下特定(有趣的)表达式:

    • Show the current date and time with NOW():

      使用NOW()显示当前日期和时间:

      
      evaluate(ROW("Current date and time", Now()))
    • Show the PI number with PI():

      使用PI()显示PI编号:

      
      evaluate(ROW("The PI Number", PI()))
    • Convert degrees to radians with DEGREES function:

      使用DEGREES函数将度转换为弧度:

      
      evaluate(ROW("Degrees to Radians", DEGREES(90)))
    • Calculate the average value of particular column with AVERAGE function:

      使用AVERAGE函数计算特定列的平均值

      
      evaluate(ROW("Average Price", AVERAGE('Product'[List Price])))

    Quick tip: Try other aggregate functions like MAX, MIN or COUNT instead of AVERAGE, and don’t forget to rename the column properly

    快速提示 :尝试使用其他汇总函数,例如MAXMINCOUNT而不是AVERAGE,并且不要忘记正确地重命名列

    • Retrieve the position of specified letter in particular word with SEARCH function:

      使用SEARCH功能检索特定字母在特定单词中的位置:

      
      evaluate(ROW("Position of letter B", SEARCH("b", "Tabular")))
    • We can even perform some basic mathematical operations within the query, and also add some more complex functions:

      我们甚至可以在查询中执行一些基本的数学运算 ,还可以添加一些更复杂的函数:

      
      evaluate(ROW("Calculator", 25*6-6))

    I hope you have enjoyed these examples and querying your SSAS Tabular model database!

    希望您喜欢这些示例并查询SSAS表格模型数据库!

    有用的链接 (Useful links)

    • Data Analysis Expressions (DAX) Overview数据分析表达式(DAX)概述
    • DAX Syntax ReferenceDAX语法参考
    • Tabular Models (SSAS)表格模型(SSAS)

翻译自: https://www.sqlshack.com/query-ssas-tabular-model-database-using-dax-functions/

ssas表格模型 权限控制

ssas表格模型 权限控制_如何使用DAX函数查询SSAS表格模型数据库相关推荐

  1. ssas表格模型 权限控制_性能调整SSAS表格模型

    ssas表格模型 权限控制 Modeling for the xVelocity/Vertipaq engine is a completely different beast than modeli ...

  2. ssas表格模型 权限控制_创建第一个SSAS表格模型数据库

    ssas表格模型 权限控制 Considering BI environment, when comparing Multidimensional Vs Tabular model databases ...

  3. ssas表格模型 权限控制_如何在SQL Server 2016中自动执行SSAS表格模型处理

    ssas表格模型 权限控制 There are many ways to process your SSAS Tabular Model. This can be achieved in SSIS u ...

  4. ssas表格模型 权限控制_Analysis Services(SSAS)表格模型中的时间智能

    ssas表格模型 权限控制 In the analytical world, time is an important slicer. The ability to view data over ti ...

  5. 表格在整个html居中显示,html 表格字符居中显示_如何在HTML中居中显示表格?

    html 表格字符居中显示_如何在HTML中居中显示表格? html 表格字符居中显示_如何在HTML中居中显示表格? html 表格字符居中显示 HTML table provides the ab ...

  6. 实现权限控制_在 Go 语言中使用 casbin 实现基于角色的 HTTP 权限控制

    Go语言中文网,致力于每日分享编码.开源等知识,欢迎关注我,会有意想不到的收获! 身份认证和授权对 web 应用的安全至关重要.最近,我用 Go 完成了我的第一个正式的 web 应用,这篇文章是在这个 ...

  7. 权限控制_多租户系统设计之权限控制

    概述 业务层面的隔离是用户可以直接感知的隔离,也是多租户系统必须实现的隔离,在上篇文章中提到的数据隔离主要是针对数据存储层面而言的,用户一般感知不到,所以如"基于数据行的租户唯一标识&quo ...

  8. java按钮权限控制_详解Spring Security 中的四种权限控制方式

    Spring Security 中对于权限控制默认已经提供了很多了,但是,一个优秀的框架必须具备良好的扩展性,恰好,Spring Security 的扩展性就非常棒,我们既可以使用 Spring Se ...

  9. hive表级权限控制_数据库权限管理:表、行、列级别的权限控制

    权限规则 1. 在配有主从集群时建议在主节点上做权限相关操作 2. 只有管理员和超级管理员才有将数据导入至表中的权限 3. 管理员用户赋予的是以整表为单位的权限,所有能赋予的权限为create/sel ...

最新文章

  1. R语言临床预测模型的评价指标与验证指标实战:综合判别改善指数IDI(Integrated Discrimination Improvement, IDI)
  2. Windows 7 搭建 Mobile 6 真机调试开发环境
  3. CH - 0805 防线(二分+思维)
  4. 每日两SQL(6),欢迎交流~
  5. 【Python】RotatingFileHandler:log日志文件自定义大小+滚动输出
  6. 流放之路材质过滤怎么设置_松下除湿机怎么样 松下除湿机款式有哪些型号【详解】...
  7. 【AI视野·今日Robot 机器人论文速览 第十三期】Wed, 23 Jun 2021
  8. win7 / mysql-8.0.11-winx64 安装的测坑步骤
  9. android编程任务进度条,Android应用开发之AsyncTask 处理耗时操作和显示进度条
  10. linux pwm测试程序,DM8168 PWM驱动与测试程序
  11. android ion --system heap(个人理解,不确定完全对)
  12. 解决数据质量问题方案
  13. cf/codeforces #365 E - Mishka and Divisors 数学+背包dp+gcd
  14. 2014Gartner技术成熟度曲线
  15. pdf2htmlEX命令行参数大全
  16. win10安装Tomcat10详细教程
  17. pygame精灵组有哪些方法_pygame 的精灵使用
  18. etc的常见算法_几个常用算法的适应场景及其优缺点(非常好)
  19. react(子传父、父传子)
  20. 一文搞懂浏览器缓存机制

热门文章

  1. cookie代码加时间多久出现一次_恶意代码分析 丨 一个毫无套路的咸鱼诈骗网站...
  2. 2、Shiro的认证
  3. 解决Qt-至少需要一个有效且已启用的储存库 问题
  4. 1043 幸运号码 数位DP
  5. Oracle、DB2、SQLSERVER、Mysql、Access分页SQL语句梳理
  6. Oracle 的 Sql*Plus 常用命令介绍
  7. 这周的工作任务,编写sql存储过程
  8. 我喜欢的歌-FOREVER
  9. 操作系统的概念,功能和目标
  10. 液晶电视发出“嘭”的一声,然后就无法开机了,是什么原因,好不好修?