Write DAX formulas for Power BI Desktop models
DAX is a library of functions and operators that can be combined to build formulas and expression used by Microsoft BI Tools.
Dax is also known as function language, where the full code is kept inside a function.
We can use DAX
1. Power BI
2. Power Pivot For Excel
3. SSAS Tabular Model
4. Azure Analysis Service
By using Data Analysis Expressions (DAX), you can add three types of calculations to your data model:
Calculated tables
Calculated columns
Measures
Date tables
Date tables are required to apply special time filters known as time intelligence. A family of DAX functions, known as time-intelligence functions, only work correctly when a date table is set up. When your source data doesn't include a date table, you can create one as calculated tables by using the CALENDAR or CALENDARAUTO DAX functions.
You can write a DAX formula to add a calculated column to any table in your model. The formula is evaluated for each table row and it returns a single value. When added to an Import storage mode table, the formula is evaluated when the data model is refreshed and it increases the storage size of your model. When added to a DirectQuery storage mode table, the formula is evaluated by the underlying source database when the table is queried.
Write Dax functions
Formulas are assembled by using:
DAX functions
DAX operators
References to model objects
Constant values, like the number 24 or the literal text "FY" (for fiscal year)
DAX variables
- Whitespace
| Model data type | DAX data type | Description |
|---|---|---|
| Whole number | 64-bit integer | -263 through 263-1 |
| Decimal number | 64-bit real | Negative: -1.79 x 10308 through -2.23 x 10-308 Zero Positive: 2.23 x 10-308 through 1.79 x 10308 Limited to 17 decimal digits |
| Boolean | Boolean | TRUE or FALSE |
| Text | String | Unicode character string |
| Date | Date/time | Valid dates are all dates after March 1, 1900 |
| Currency | Currency | -9.22 x 1014 through 9.22 x 1014 Limited to four decimal digits of fixed precision |
| N/A | BLANK | In some cases, it’s the equivalent of a database (SQL) NULL |
DAX Operators
1. Logical operators
Use logical operators to combine expressions that produce a single result. The following table lists all logical operators.
2. Comparison operators
The following table lists the comparison operators, which are used to compare two values. The result is either TRUE or FALSE.
3. Arithmetic operators
The following table lists the arithmetic operators.
You can declare DAX variables in your formula expressions. When you declare at least one variable, a RETURN clause is used to define the expression, which then refers to the variables.
We recommend that you use variables because they offer several benefits:
Improving the readability and maintenance of your formulas.
Improving performance because variables are evaluated once and only when or if they're needed.
Allowing (at design time) straightforward testing of a complex formula by returning the variable of interest.
Comments
Post a Comment