Forum Discussion

Sang's avatar
Sang
Frequent Visitor
2 years ago
Solved

Slow perfomance FILTER function

Hi,   I have the following data model. DimOrder table has 1,5 million rows and FactOrderlines has 6 million rows. I need to create a measure where I calculate the number of unique order numbers whe...
  • edhans's avatar
    2 years ago

    Don't use FILTER to filter a table like that, it can be very slow.

    You can filter this way:

    Unique Order Number =
    CALCULATE (
        DISTINCTCOUNT ( FactOrderlines[Order Number] ),
        FILTER (
            VALUES ( DimOrder[YesNo] ),
            DimOrder[YesNo] = "Yes"
        )
    )
    

    This is filtering a column of distinct values, and that column has only 2 values (or maybe 3 if there are blanks). 

     

    Better yet, just use a predicate like this:

     

    Unique Order Number =
    CALCULATE (
        DISTINCTCOUNT ( FactOrderlines[Order Number] ),
        DimOrder[YesNo] = "Yes"
    )
    


    Internally, this gets rewritten to this:

    Unique Order Number =
    CALCULATE (
        DISTINCTCOUNT ( FactOrderlines[Order Number] ),
        FILTER (
            ALL ( DimOrder[YesNo] ),
            DimOrder[YesNo] = "Yes"
        )
    )
    

     

    Which is still filtering a column, not an entire table.