Forum Discussion
Fact table filtering dim table
- 2 years ago
The difference lies in the DAX queries Power BI generates for the different visuals.
1. When no measure is included in the visual (as in V2/V3), a "hidden measure" is automatically added to the query within SUMMARIZECOLUMNS, in this case with this expression (wrapped in CALCULATE):
COUNTROWS ( 'FactT' )This ensures that only combinations of Product/Sales values where FacT is nonempty are returned.
The DAX query also includes a check that at least one of Product/Sales is nonblank.
2. When a measure is included the visual (as in V4), the nonblank values of this measure will determine which combinations of Product/Sales values are returned. In the case of [Product_M], this measure is nonblank for all combinations in the Cartesian product of Product/Sales values.
We could summarise this as: If a table visual includes fact/dim columns but no measures, Power BI will automatically filter the combinations of fact/dim columns to those where fact is nonempty.
I extracted the essential parts of the V2/V3 & V4 queries below to illustrate:
-- V2/V3 DAX Query -- Includes rows where -- 1. CALCULATE ( COUNTROWS ( FactT ) ) is nonblank, -- which is true when FactT is nonempty when Product/Sales values are applied as filters. -- 2. At least one of DimT[Product] or FactT[Sales] is nonblank EVALUATE FILTER ( SUMMARIZECOLUMNS ( 'DimT'[Product], 'FactT'[Sales], "CountRowsFactT", CALCULATE ( COUNTROWS ( 'FactT' ) ) ), OR ( NOT ( ISBLANK ( 'DimT'[Product] ) ), NOT ( ISBLANK ( 'FactT'[Sales] ) ) ) ) -- V4 DAX Query -- Includes rows where -- 1. [Product_M] is nonblank. -- which is true for any combination of DimT[Product] & FactT[Sales] -- resulting in the Cartesian product. EVALUATE SUMMARIZECOLUMNS ( 'DimT'[Product], 'FactT'[Sales], "Product_M", 'FactT'[Product_M] )It would be interesting to understand the general rule determining what expressions are automatically added when a visual includes no measures. Presumably tables on the "end" of a chain of 1:many relationships would always be aggregated.
Regards
The difference lies in the DAX queries Power BI generates for the different visuals.
1. When no measure is included in the visual (as in V2/V3), a "hidden measure" is automatically added to the query within SUMMARIZECOLUMNS, in this case with this expression (wrapped in CALCULATE):
COUNTROWS ( 'FactT' )
This ensures that only combinations of Product/Sales values where FacT is nonempty are returned.
The DAX query also includes a check that at least one of Product/Sales is nonblank.
2. When a measure is included the visual (as in V4), the nonblank values of this measure will determine which combinations of Product/Sales values are returned. In the case of [Product_M], this measure is nonblank for all combinations in the Cartesian product of Product/Sales values.
We could summarise this as: If a table visual includes fact/dim columns but no measures, Power BI will automatically filter the combinations of fact/dim columns to those where fact is nonempty.
I extracted the essential parts of the V2/V3 & V4 queries below to illustrate:
-- V2/V3 DAX Query
-- Includes rows where
-- 1. CALCULATE ( COUNTROWS ( FactT ) ) is nonblank,
-- which is true when FactT is nonempty when Product/Sales values are applied as filters.
-- 2. At least one of DimT[Product] or FactT[Sales] is nonblank
EVALUATE
FILTER (
SUMMARIZECOLUMNS (
'DimT'[Product],
'FactT'[Sales],
"CountRowsFactT", CALCULATE ( COUNTROWS ( 'FactT' ) )
),
OR ( NOT ( ISBLANK ( 'DimT'[Product] ) ), NOT ( ISBLANK ( 'FactT'[Sales] ) ) )
)
-- V4 DAX Query
-- Includes rows where
-- 1. [Product_M] is nonblank.
-- which is true for any combination of DimT[Product] & FactT[Sales]
-- resulting in the Cartesian product.
EVALUATE
SUMMARIZECOLUMNS (
'DimT'[Product],
'FactT'[Sales],
"Product_M", 'FactT'[Product_M]
)
It would be interesting to understand the general rule determining what expressions are automatically added when a visual includes no measures. Presumably tables on the "end" of a chain of 1:many relationships would always be aggregated.
Regards
Thanks very much OwenAuger for the fantastic explanation.
That makes sense.
I also see that the queries generated by PBI for V2 and V3 are exactly the same, regardless of the order in which DimT[Product] and FactT[Sales] are placed in the table visual. I was always under the impression this order would play a role but apparently I was mistaken.
Thanks