Creating tables that are based on data from different data sources
Sometimes—for example, when creating a bridge table—you may need to extract distinct values from more than one table because the distinct values may be different in different tables. In that case, you’d need to take distinct values from both tables, and if they come from different data sources or from different “islands,” or both, the performance may be slow. You can solve this issue by using a calculated table.
For example, you could retrieve the distinct Buying Group values from both the Customer and Targets tables by using the following calculated table formula:
Click here to view code image
Buying Group =
DISTINCT(
UNION(
DISTINCT(Customer[Buying Group]),
DISTINCT(Targets[Buying Group])
)
The DISTINCT function ensures there are no duplicates, and UNION combines values from two tables that come from different sources. UNION acts similarly to appending tables in Power Query, though they combine tables differently:
- UNION ignores column names and combines table columns based on their positions. The number of columns between tables must match.
- Appending tables in Power Query combines tables based on column names, and it’s possible to combine tables that have a different number of columns.
In addition to UNION, other set functions available in DAX include EXCEPT and INTERSECT, which also require that tables have the same number of columns.
Since the data is already in memory, this process is usually much quicker compared to creating the same table by using Power Query.
Precalculating measures to improve report performance
If you have complex measures that perform poorly, depending on the type of calculation you may want to precalculate them in a calculated table, and then create new measures that aggregate the precalculated values. This approach may not work for some types of calculations, though it usually helps with additive measures.
Aggregations, which are outside the scope of the exam, are an example of calculated tables that precalculate measures and improve performance.
Need More Review? Using Calculated Tables
For more details on how to create calculated tables, see “Create calculated tables in Power BI Desktop” at https://docs.microsoft.com/en-us/power-bi/transform-model/desktop-calculated-tables.