Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Analyzing Data with Power BI and Power Pivot for Excel (Alberto Ferrari, Marco Russo) (z-lib.org).pdf
Скачиваний:
11
Добавлен:
14.08.2022
Размер:
18.87 Mб
Скачать

but this time, it happens through table expansion. The main difference between using bidirectional filtering and table expansion is that the pattern with table expansion always applies the filter, whereas the bidirectional filtering works only when the filter is active. To see the difference, let us add a new row to the Transactions table, which is not related to any account. This row has 5,000 USD and, not being related to any account, it does not belong to any customer. Figure 8- 5 shows you the result.

FIGURE 8-5 CROSSFILTER and table expansion lead to different results in the grand total.

The difference between the two measures is exactly 5,000 USD, which is the amount that is not related to any customer. It is reported at the grand total in the CROSSFILTER version, but it is not reported in the table expansion one. When you use the CROSSFILTER version at the grand total when no filter on the customer is active, the fact table shows all the rows. On the other hand, the filter is always activated when using table expansion, showing only the rows in the fact table that can be reached through one of the customers. Thus, the additional row is hidden and does not contribute to the grand total.

As it often happens in these cases, it is not that one value is more correct than the other. They are reporting different numbers following different calculations. You only need to be aware of the difference so you can use the correct formula depending on your needs. From a performance point of view, because the filter is not applied if it is not necessary, you can expect the version with CROSSFILTER to be slightly faster than the version with table expansion. CROSSFILTER and bidirectional filtering, on the other hand, report the same numbers, and behave the same way in terms of performance.

Understanding non-additivity

The second important point about many-to-many relationships is that typically, measures aggregated through a many-to-many relationship are non-additive. This is not an error in the model; it is the nature of many-to-many that makes these

relationships non-additive. To better understand this, look at the report in Figure 8-6 that shows both the Accounts and the Customers tables on the same matrix.

FIGURE 8-6 Many-to-many relationships generate non-additive calculations.

You can easily see that the column totals are correct, meaning that the total is the sum of all the rows in that column. The row totals, however, are incorrect. This is because the amount of the account is shown for all the customers who own that account. The account Mark-Paul, for example, is owned by Mark and Paul together. Individually, they have 1,000 USD each, but when you consider them together, the total is still 1,000.

Non-additivity is not a problem. It is the correct behavior whenever you work with many-to-many relationships. However, you need to be aware of nonadditivity because you can easily be fooled if you do not take it into account. For example, you might iterate over the customers, compute the sum of the amount, and then aggregate it at the end, which obtains a result that is different from the calculation done for the grand total. This is demonstrated in the report in Figure 8- 7, which shows the result of the following two calculations:

Click here to view code image

Interest := [SumOfAmount] * 0.01

Interest SUMX := SUMX ( Customers, [SumOfAmount] * 0.01 )