DAX Flashcards
What is the full form of DAX?
Data Analysis Expressions
What is DAX?
DAX is a collection of constants, operators, and functions that are used to build expressions that return one or more values.
DAX is not a programming language in the traditional sense but is instead a functional language, which means that it makes calls to a function as part of an expression. The result of an expression will, depending on the function, return either a single value or a table as output. The output from an expression can be used to nest functions, by using it as the input parameter to another function.
DAX can only be used to filter or query a physical table; it cannot add, delete, or update data in a table.
What are the Function groups in DAX?
- Aggregate
- Count
- Date and Time
- Time intelligence
- Information
- Logical
- Mathematical
- Statistical
- Text
- Parent/Child
What are the 4 Operator Groups in DAX?
- Arithmetic
- Comparison
- Concatenation
- Logical
What are the different types of operator available within the arithmetic group?
- Addition
- Subtraction or sign
- Multiplication
- Division
- Exponentiation
What is the order of precedence for each of the different DAX arithmetic operators?
- Exponentiation
- Sign
- Multiplication and division
- Addition and subtraction
What are the different types of comparison operators?
- =
- ==
- >
- <
- >=
- <=
- <>
When using comparison expressions, you should consider the following points:
- Boolean values are treated as greater than string values.
- String values are treated as greater than numeric or date/time values.
- Numeric and date/time values are treated the same.
what is the Concatenation operator in DAX?
Details in Attached image
what are the different types of logical operators?
- &&
- ||
- IN
In addition to the preceding logical operators, DAX also has the logical AND and OR functions that replicate the functionality of the AND operator (&&) and OR operator (||) respectively.
The advantage of using these functions over the equivalent operators in a complex expression is that it is easier to format and read the code. However, one drawback is that the functions only accept two arguments, restricting you to comparing two conditions only. To be able to compare multiple conditions, you will need to nest the functions. In this case, it might be better to use the AND operator (&&) instead.
The following gives an example of the syntax for the AND function:
Measure 1-3 =
IF (
AND (
20 > 10,
-20 < -10
),
“All true”,
“One or more false”
)
The following gives an example showing the syntax of the AND function nested to compare three conditions:
Measure 1-4 =
IF (
AND (
AND (
10 > 9,
5 < 10
),
20 > 10
),
“All true”,
“One or more false”
)
The following gives an alternative example of the one given, using the equivalent AND operator (&&):
Measure 1-5 =
IF (
10 > 9
&& 5 < 10
&& 20 > 10,
“All true”,
“One or more false”
)
How are BLANK values handled in DAX?
Any column in a table can have blank values, which are the result of the data source containing NULL in values. How a blank value affects the result of a DAX expression depends on the data type expected and the operator being used. In some instances, a blank value will be converted into a zero or an empty string, while in others, it will propagate through as a blank. Table 1-12 shows how different DAX operators handle blank values: (IN THE ATTACHED IMAGE)
The BLANK data type represents nulls, blank values, empty cells, and missing values. The BLANK function is used to generate blanks, while the ISBLANK function is used to verify a blank value.
Difference b\w calculated columns and measures
At first, they may seem very similar, and indeed there are some instances where both can be used to obtain the same result. However, they are different and serve different purposes. Likewise, they also impact resources in different ways. Calculated columns allow you to extend a table in your data model by creating additional columns. Measures allow you to aggregate the values of rows in a table and take into account any current filters or slicers that are applied.
In DAX can the calulated columns be used in defining table relationships?
Calculated columns can be used in any part of a report and they can be used to define relationships.
Give some details on caculated columns ? for eg…. when are the calculated columns populated, benefits and disadvantages of calculated columns etc
Calculated columns are computed during a data refresh and stored in memory with the rest of your data model. This is an important point to note when you are planning and building your data model. On the one hand, with complex expressions, the time taken to compute them is at the point you refresh the data and not when you are querying the data. This can improve the user experience, especially with complex expressions, but you need to remember that each calculated column will take up space in memory. Although this might not be an issue with a smaller table, it could have a significant impact on memory use when you are dealing with large tables. If you have complex expressions behind your calculated columns, then this could also slow down the time it takes to refresh the data in your data model.
You would be well advised not to have too many calculated columns in your data model and to consider whether it would be possible to use a measure instead, especially if it does not impact the user experience too adversely.
What are Measures in DAX?
Unlike calculated columns, which are evaluated row by row using the context of the current row, measures are used to summarize data by aggregating the values of rows in a table. They work within the current filter context, which means they are affected by the current filters, slicers applied, and the highlighted sections of charts or visuals.
There are two types of measures: implicit and explicit. Implicit measures are created behind the scenes when you drag a field to the Values area of the PivotTable Fields list
An explicit measure, on the other hand, is a measure that is specifically created by you.
A measure must be created if you want to conduct an operation on aggregate values instead of values on a row-by-row basis. For example, if you need to calculate the percentage ratio of two columns, you will need to create a measure that calculates the ratio based on the sum of each column. The following measure calculates the percentage of returns to sales by dividing the sum of items returned by the sum of items sold:
Return % =
DIVIDE (
SUM ( Sales[ReturnQuantity] ),
SUM ( Sales[SalesQuantity] )
)
Difference Between Calculated column vs Measures?
Although they may look similar, calculated columns and measures operate very differently. They both use DAX expressions, but they differ in the point at which they are calculated and in the context of their evaluation:
- The values of calculated columns are calculated during a data refresh and they are evaluated using the current row context. They also take up memory and disk space and can slow down data loading times during data refreshes. However, once loaded, they do not impact performance.
- A measure is executed every time a value uses it in a report or chart. Measures are re-calculated every time a page loads. They are also re-calculated when filters or slicers are changed or a user highlights different parts of a chart or visual. A measure does not add to the space used by a data model, but it may impact the speed of user interactions. Measures operate on aggregates that are defined by the current filter context.
It is sometimes possible to calculate the same value using either a calculated column or a measure, using different DAX expressions. In most cases, where this is possible, you should use a measure, as this will not increase the size of your data model and use extra memory or disk space. This is especially important if you are working with a table that contains a large number of records.
When naming measures, you should not include the table name in the measure name. Although a measure is created under a table, it does not strictly belong to that table. If you do not include the table name, it can easily be moved between tables if necessary. It also makes it easier to identify as a measure. On the other hand, calculated columns should include the table name.