Forum Discussion

AlB's avatar
AlB
Community Champion
2 years ago
Solved

Fact table filtering dim table

Hi all, We have a simple model with one dim table (DimT) and one fact table (FactT) (pbix attached) :                          We now create a simple table visual (V1) with DimT[...
  • OwenAuger's avatar
    OwenAuger
    2 years ago

    AlB 

    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