3D. Write DAX formulas for Power BI Desktop models Flashcards
What types of calculations can you add to a semantic model by using DAX?
- Calculated tables
- Calculated columns
- Measures
What are calculated tables, and what should you remember about them?
You can write a DAX formula to add a calculated table to your model. The formula can duplicate or transform existing model data, or create a series of data, to produce a new table.
Calculated table data is always imported into your model, so it increases the model storage size and can prolong data refresh time.
A calculated table can’t connect to external data; you need to use Power Query to accomplish that task.
In what ways can calculated tables be useful?
- Date tables
- Role-playing dimensions
- What-if analysis
What are date tables?
Date tables are required to apply special time filters known as time intelligence. DAX 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.
What is a role-playing dimension?
When two model tables have multiple relationships, it could be because your model has a role-playing dimension. For example, if you have a table named Sales that includes two date columns, OrderDateKey and ShipDateKey, both columns are related to the Date column in the Date table. In this case, the Date table is described as a role-playing dimension because it could play the role of order date or ship date.
How do you make use of an inactive relationship between two tables?
The active relationship is used by default to propagate filters. Any remaining relationships between the two tables are inactive. In a model diagram, the relationships are represented as dashed lines.
Inactive relationships are only used when they’re expressly requested in a calculated formula by using the USERELATIONSHIP DAX function.
What is an alternative design to using multiple relationships between two tables when creating role-playing dimensions?
A better design could be to copy the dimension table (by creating a calculated table), each with their own active relationship to the fact table.
What is what-if analysis, how do they work, and how do they connect to tables in the model?
Power BI Desktop supports a feature called What-if parameters. When you create a what-if parameter, a calculated table is automatically added to your model.
What-if parameters allow report users to select or filter by values that are stored in the calculated table. Measure formulas can use selected value(s) in a meaningful way. For example, a what-if parameter could allow the report user to select a hypothetical currency exchange rate, and a measure could divide revenue values (in a local currency) by the selected rate.
Notably, what-if calculated tables aren’t related to other model tables because they’re not used to propagate filters. For this reason, they’re sometimes called disconnected tables.
What are calculated columns?
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.
How do calculated columns relate to storage mode?
- When added to an Import storage mode table, the formula is evaluated when the semantic 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.
What is a measure?
You can write a DAX formula to add a measure to any table in your model. The formula is concerned with achieving summarization over model data.
Similar to a calculated column, the formula must return a single value.
How do calculated columns and measures differ in terms of when they’re evaluated?
- Calculated columns are valuated at data refresh time
- Measures are evaluated at query time. Their results are never stored in the model.
What are “implicit” measures?
Implicit measures are columns that can be summarized by visuals in simplistic ways, like count, sum, minimum, maximum, and so on. You can identify implicit measures in the Fields pane because they’re shown with the sigma symbol ( ∑ ).
To be clear, explicit measures are model calculations that are written in DAX and are commonly referred to as simply measures.
What is a DAX formula?
Each model calculation type, calculated table, calculated column, or measure is defined by its name, followed by the equals symbol (=), which is then followed by a DAX formula.
A DAX formula consists of expressions that return a result.
What can DAX formulas return?
The result is either a table object or a scalar value.
Calculated table formulas must return a table object.
Calculated column and measure formulas must return a scalar value (single value).
What is a DAX function?
Similar to Microsoft Excel, DAX is a functional language meaning that formulas rely on functions to accomplish specific goals. Typically, DAX functions have arguments that allow passing in variables. Formulas can use many function calls and will often nest functions within other functions.
In a formula, function names must be followed by parentheses. Within the parentheses, variables are passed in.
What are DAX operators?
Formulas also rely on operators, which can perform arithmetic calculations, compare values, work with strings, or test conditions.