Excel Dax 简明教程
Excel DAX - Functions
大多数 DAX functions 具有与 Excel 函数相同名称和功能。但是,已修改 DAX 函数,以使用 DAX 数据类型,并使用表和列。
Most of the DAX functions have the same names and functionality as that of Excel functions. However, DAX functions have been modified to use DAX data types and to work with tables and columns.
DAX 有一些附加函数,这些函数在 Excel 中找不到。这些 DAX 函数用于特定目的,例如基于与数据模型的关系数据库方面相关的关系查找,对表进行迭代以执行递归计算,执行动态聚合,以及利用时间智能执行计算。
DAX has some additional functions that you will not find in Excel. These DAX functions are provided for specific purposes such as lookups based on relationships associated with the relational database aspects of the Data Model, the ability to iterate over a table to perform recursive calculations, to perform dynamic aggregation, and for calculations utilizing time intelligence.
在本章中,您将了解 DAX 语言中支持的函数。有关这些 DAX 函数的用法,请参阅本教程库中的教程 - DAX 函数。
In this chapter, you will learn about the functions supported in the DAX language. For more information on the usage of these DAX functions, refer to the tutorial – DAX Functions in this tutorials library.
What is a DAX Function?
DAX 函数是 DAX 语言中提供的内置函数,使您能够对数据模型中的表中的数据执行各种操作。如前所述,DAX 用于数据分析和商业智能目的,这些目的需要支持从数据中提取、吸收和得出见解。基于数据模型的 DAX 函数为您提供了这些实用工具,一旦您掌握了 DAX 语言和使用 DAX 函数,它将使您的工作更简单。
A DAX function is an in-built function provided in the DAX language to enable you to perform various actions on the data in the tables in your Data Model. As discussed earlier, DAX is used for data analysis and business intelligence purposes that require support to extract, assimilate, and derive insights from the data. The DAX functions that are based on the Data Model provide you with these utilities that make your job simpler, once you get a grasp on the DAX language and the usage of the DAX functions.
Excel Functions vs. DAX Functions
您所熟悉的 Excel 函数与 DAX 函数之间存在某些相似之处。但是,也存在某些差异。您需要了解这些差异,以便在使用 DAX 函数和编写包括 DAX 函数的 DAX 公式时避免出错。
There are certain similarities between Excel functions that you are aware of and the DAX functions. However, there are certain differences too. You need to get a clarity on these, so that you can avoid making mistakes in the usage of DAX functions and in writing DAX formulas that include DAX functions.
Similarities between Excel Functions and DAX Functions
-
Many 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. In this tutorial, you will find every DAX function prefixed with DAX so as to avoid confusion with the Excel functions.
-
You cannot use DAX functions in an Excel formula or use Excel formulas/functions in DAX, without the required modifications.
-
Excel functions take a cell reference or a range of cells as reference. DAX functions never take a cell reference or a range of cells as reference, but instead take a column or table as 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 tables.
-
Excel supports variant data type in a column of data, i.e. you can have data of different data types in a column. Whereas, DAX expects the data in a column of a table to be always of the same data type. If the data is not of the same data type, DAX changes the entire column to the data type that best accommodates all the values in the column. However, if the data is imported and this issue arises, DAX can flag an error.
要了解 DAX 数据类型和数据类型转换,请参阅该章节 – DAX 语法参考。
To learn about DAX data types and data type casting, refer to the chapter – DAX Syntax Reference.
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 函数。有关 DAX 函数语法以及 DAX 函数返回和执行内容的详细信息,请参阅本教程库中的 DAX 函数教程。
In this section, you will learn about DAX functions at the functions category level. For details on the DAX Function Syntax and what the DAX function returns and does - refer to the DAX Functions tutorial in this tutorials library.
DAX 时间智能函数和 DAX 筛选器函数功能强大,需要专门提及。有关详细信息,请参阅章节 - 了解 DAX 时间智能和 DAX 筛选器函数。
DAX time intelligence functions and DAX filter functions are powerful and require a special mention. Refer to the chapters - Understanding DAX Time Intelligence and DAX Filter Functions for details.
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 表值函数可帮助你有效地编写 DAX 公式。
Understanding DAX table valued functions helps you in writing DAX formulas effectively.
DAX Aggregation Functions
DAX 聚合函数汇总表各行中的任何表达式,并且在计算中很有用。
DAX Aggregation functions aggregate any expression over the rows of a table and are useful in calculations.
以下是一些 DAX 聚合函数 -
Following are some DAX Aggregation functions −
DAX Filter Functions
DAX 筛选器函数返回与当前行相关的列、表或值。你可以使用 DAX 筛选器函数返回特定数据类型,查找相关表中的值,以及按相关值筛选。DAX 查找函数通过使用表及其之间的关系来工作。DAX 筛选器函数使你能够操作数据上下文以创建动态计算。
DAX Filter functions return a column, 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.
以下是某些 DAX 筛选器函数 -
Following are some DAX Filter functions −
DAX Time Intelligence Functions
DAX 时间智能函数返回日期表或使用日期表来计算聚合。这些 DAX 函数可帮助你创建支持商业智能分析需求的计算,使你能够使用时间段(包括天、月、季度和年)来操作数据。
DAX Time Intelligence functions return a table of dates or 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 时间智能函数 -
Following are some DAX Time Intelligence functions −
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 日期和时间函数 -
Following are DAX Date and Time functions −
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 信息函数 -
Following are some DAX Information functions −
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 逻辑函数 −
Following are DAX Logical functions −
DAX Math and Trig Functions
DAX 数学和三角函数与 Excel 的数学和三角函数非常相似。
DAX Mathematical and Trigonometric functions are very similar to the Excel mathematical and trigonometric functions.
以下是一些 DAX 数学和三角函数 −
Following are some DAX Math and Trig functions −
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 其他函数 −
Following are some DAX Other functions −
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 父母函数 −
Following are some DAX Parent and Child functions −
DAX Statistical Functions
DAX 统计函数与 Excel 统计函数非常相似。
DAX Statistical functions are very similar to the Excel Statistical functions.
以下是一些 DAX 统计函数 −
Following are some DAX Statistical functions −
DAX Text Functions
DAX 文本函数适用于表和列。利用 DAX 文本函数,您可以返回字符串の一部、在字符串中查找文本或者串联字符串值。还可以控制日期、时间和数字的格式。
DAX Text functions work with tables and columns. With DAX Text functions you can return the 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 文本函数 −
Following are some DAX Text functions −