Dax Functions 简明教程
DAX Functions - Introduction
DAX 的全称是 *D*ata *A*nalysis E*x*pressions(数据分析表达式)。DAX 是一种公式语言,是一个用于公式或表达式中的函数、运算符和常量的集合,可以计算并返回一个或多个值。DAX 是与 Microsoft Excel Power Pivot 的数据模型以及 Microsoft Power BI 相关联的公式语言。
DAX stands for *D*ata *A*nalysis E*x*pressions. DAX is a formula language and is a collection of functions, operators, and constants that can be used in a formula or expression to calculate and return one or more values. DAX is the formula language associated with the Data Model of Microsoft Excel Power Pivot and with Microsoft Power BI.
DAX 不是一种编程语言,而是一种公式语言,它允许用户在计算列和计算字段(也称为度量)中定义自定义计算。借助 DAX,你可以使用数据模型中现有数据创建新的信息。DAX 公式使你可以执行数据建模、数据分析,并使用结果进行报告和决策。
DAX is not a programming language, however it is a formula language that allows the users to define custom calculations in calculated columns and calculated fields (also known as measures). DAX helps you create new information from the existing data in your Data Model. DAX formulas enable you to perform data modeling, data analysis, and use the results for reporting and decision making.
有关 DAX 的深入理解,请参阅本教程库中有关 DAX 的教程。
For an in-depth understanding of DAX, refer to the tutorial – DAX in this tutorials library.
What is a DAX Function?
DAX 函数是一种内置函数,它在 DAX 语言中提供,使你可以对数据模型中表格中的数据执行各个操作。
A DAX function is an inbuilt function provided in the DAX language to enable you to perform various actions on the data in the tables in your Data Model.
DAX 函数使你可以对数据模型执行常用的数据计算。某些 DAX 函数的名称及其功能与 Excel 函数的相同,但已修改为使用 DAX 数据类型并与表格和列一起使用,如下节中所突出显示的那样。DAX 附加了一些旨在与关系数据一起使用并执行动态聚合的函数。
DAX functions enable you to perform commonly used data calculations on the Data Model. Some of the DAX functions have same names and functionality as that of Excel functions but have been modified to use DAX data types and to work with tables and columns, as highlighted in the next section. DAX has additional functions that are designed to work with relational data and perform dynamic aggregation.
DAX 函数在使用 DAX 进行数据建模和报告中发挥着重要作用。
DAX functions play an important role in the usage of DAX for data modeling and reporting.
Excel Functions vs. DAX Functions
Excel 函数与 DAX 函数之间存在某些相似之处,但也存在某些差异。以下是 Excel 函数和 DAX 函数之间的相似之处和差异 -
There are certain similarities between the Excel functions and the DAX functions and there are certain differences too. Following are the similarities and differences between Excel functions and DAX functions −
Similarities Between Excel Functions and DAX Functions
-
Certain DAX functions have the same name and the same general behavior as Excel functions.
-
DAX has lookup functions that are similar to the array and vector lookup functions in Excel.
Differences Between Excel Functions and DAX Functions
-
DAX functions have been modified to take different types of inputs and some of the DAX functions might return a different data type. Hence, you need to understand the usage of these functions separately though they have the same name.
-
You cannot use DAX functions in an Excel formula or use Excel functions in DAX formula, without the required modifications.
-
Excel functions take a cell reference or a range of cells as a reference. DAX functions never take a cell reference or a range of cells as a reference, but instead take a column or table as a reference.
-
Excel date and time functions return an integer that represents a date as a serial number. DAX date and time functions return a datetime data type that is in DAX but not in Excel.
-
Excel has no functions that return a table, but some functions can work with arrays. Many of the DAX functions can easily reference complete tables and columns to perform calculations and return a table or a column of values. This ability of DAX adds power to the Power Pivot, Power View and Power BI, where DAX is used.
-
DAX lookup functions require that a relationship is established between the respective tables.
DAX Parameter Naming Conventions
DAX 拥有标准的参数名称来帮助使用和理解 DAX 函数。此外,您可以在参数名前使用特定前缀。如果前缀清晰易懂,您可以使用前缀本身作为参数名。
DAX has standard parameter names to facilitate the usage and understanding of the DAX functions. Further, you can use certain prefixes to the parameter names. If the prefix is clear enough, you can use the prefix itself as the parameter name.
您需要了解 DAX 参数的命名约定,以便了解 DAX 函数的语法并正确使用所需参数的值。
You need to understand DAX parameter naming conventions so as to understand the syntax of the DAX functions and use the values for the required parameters correctly.
有关详细信息,请参阅第 {} 章。
Refer to the chapter − DAX Parameter Naming Conventions for details.
Types of DAX Functions
DAX 支持以下类型的函数。
DAX supports the following types of functions.
-
DAX Table-Valued Functions DAX Filter FunctionsDAX Aggregation FunctionsDAX Time Intelligence Functions
-
DAX Date and Time Functions
-
DAX Information Functions
-
DAX Logical Functions
-
DAX Math and Trig Functions
-
DAX Other Functions
-
DAX Parent and Child Functions
-
DAX Statistical Functions
-
DAX Text Functions
-
DAX Description Structure Functions
DAX Table-Valued Functions
许多 DAX 函数将表格作为输入或输出表格,或者同时进行。这些 DAX 函数称为 DAX 表值函数。由于表格可以只有一列,因此 DAX 表值函数也接受单列作为输入。您有以下类型的 DAX 表值函数 -
Many DAX functions take tables as input or output tables or do both. These DAX functions are called DAX table-valued functions. Because a table can have a single column, DAX table-valued functions also take single columns as inputs. You have the following types of DAX table-valued functions −
-
DAX Aggregation functions
-
DAX Filter functions
-
DAX Time intelligence functions
DAX Aggregation Functions
DAX 聚合函数汇总表各行中的任何表达式,并且在计算中很有用。
DAX Aggregation functions aggregate any expression over the rows of a table and are useful in calculations.
有关详细信息,请参阅第 {} 章。
Refer to the chapter − DAX Aggregation functions for details.
DAX Filter Functions
DAX 筛选器函数返回列或表格或与当前行相关的值。您可以使用 DAX 筛选器函数返回特定的数据类型,查找相关表格中的值,并按相关值进行筛选。DAX 查找函数通过使用表格和它们之间的关系来工作。DAX 筛选器函数使您能够操作数据上下文以创建动态计算。
DAX Filter functions return a column or a table or values related to the current row. You can use DAX Filter functions to return specific data types, look up values in related tables and filter by related values. DAX Lookup functions work by using tables and relationships between them. DAX Filter functions enable you to manipulate the data context to create dynamic calculations.
有关详细信息,请参阅第 {} 章。
Refer to the chapter − DAX Filter functions for details.
DAX Time Intelligence Functions
DAX 时间智能函数返回一个包含日期的表格,或使用一个日期表格计算聚合结果。这些 DAX 函数可帮助您创建计算结果,满足商业智能分析需求,让您使用时间段(包括天、月、季度和年)操作数据。
DAX Time Intelligence functions return a table of dates or the use a table of dates to calculate an aggregation. These DAX functions help you create calculations that support the needs of Business Intelligence analysis by enabling you to manipulate data using time periods, including days, months, quarters, and years.
有关详细信息,请参阅章节 DAX Time Intelligence functions 。
Refer to the chapter − DAX Time Intelligence functions for details.
DAX Date and Time Functions
DAX 日期和时间函数与 Excel 日期和时间函数类似。但是,DAX 日期和时间函数基于 DAX 的 datetime 数据类型。
DAX Date and Time functions are similar to the Excel date and time functions. However, DAX Date and Time functions are based on the datetime data type of DAX.
有关详细信息,请参阅章节 DAX Date and Time functions 。
Refer to the chapter − DAX Date and Time functions for details.
DAX Information Functions
DAX 信息函数查看以参数形式提供的单元格或行,并告知您该值是否与预期类型匹配。
DAX Information functions look at the cell or row that is provided as an argument and tell you whether the value matches the expected type.
有关详细信息,请参阅章节 DAX Information functions 。
Refer to the chapter − DAX Information functions for details.
DAX Logical Functions
DAX 逻辑函数返回表达式中值的信息。例如,DAX TRUE 函数让您知道正在计算的表达式是否返回 TRUE 值。
DAX Logical Functions return information about values in an expression. For example, DAX TRUE function lets you know whether an expression that you are evaluating returns a TRUE value.
有关详细信息,请参阅章节 DAX Logical functions 。
Refer to the chapter − DAX Logical functions for details.
DAX Math and Trig Functions
DAX 数学和三角函数与 Excel 的数学和三角函数非常相似。
DAX Mathematical and Trigonometric functions are very similar to the Excel mathematical and trigonometric functions.
有关详细信息,请参阅章节 DAX Math and Trig functions 。
Refer to the chapter − DAX Math and Trig functions for details.
DAX Parent and Child Functions
DAX 父子函数用于管理以数据模型中父子层次结构呈现的数据。
DAX Parent and Child functions are useful in managing data that is presented as a parent/child hierarchy in the Data Model.
有关详细信息,请参阅章节 DAX Parent and Child functions 。
Refer to the chapter − DAX Parent and Child functions for details.
DAX Statistical Functions
DAX 统计函数与 Excel 统计函数非常相似。
DAX Statistical functions are very similar to the Excel Statistical functions.
有关详细信息,请参阅章节 DAX Statistical functions 。
Refer to the chapter − DAX Statistical functions for details.
DAX Text Functions
DAX 文本函数处理表格和列。使用 DAX 文本函数,您可以返回字符串的一部分,在字符串中搜索文本,或连接字符串值。您还可以控制日期、时间和数字的格式。
DAX Text functions work with tables and columns. With DAX Text functions, you can return part of a string, search for text within a string or concatenate string values. You can also control the formats for dates, times, and numbers.
有关详细信息,请参阅章节 DAX Text functions 。
Refer to the chapter − DAX Text functions for details.
DAX Other Functions
这些 DAX 函数执行的独特操作无法由其他大多数函数所属的任何类别定义。
These DAX functions perform unique actions that cannot be defined by any of the categories most other functions belong to.
有关详细信息,请参阅章节 DAX Other functions 。
Refer to the chapter − DAX Other functions for details.
DAX Function Description Structure
如果您需要在 DAX 公式中使用 DAX 函数,那么您需要详细地了解该函数。您应当了解该函数的语法、参数类型、该函数返回的内容,等等。
If you have to use a DAX function in a DAX formula, you need to understand the function in detail. You should know the syntax of the function, the parameter types, what the function returns, etc.
本教程为所有 DAX 函数采用统一的函数描述结构,以便您能有效阅读和理解 DAX 函数。
In this tutorial, a common function description structure is used for all the DAX functions so that you can read and interpret the DAX functions effectively.
请参阅章节 − DAX Function Description Structure 了解详细信息。
Refer to the chapter − DAX Function Description Structure for details.