Forum Discussion

TRADER083's avatar
TRADER083
Icon for Helper II rankHelper II
6 months ago
Solved

How to use FILTER() inside CALCULATE()

Hi everyone,   I have a working measure: security_current_sell = CALCULATE( [measure_1], fact_security[reporting_dt] = reporting_dt_previous && NOT fact_security[secu...
  • danextian's avatar
    6 months ago

    Hi TRADER083 

     

    The first measure is internally written as  + the REMOVEFILTERS which is redundant

    security_current_sell =
    CALCULATE (
        [measure_1],
        FILTER (
            ALL ( fact_security[reporting_dt], fact_security[security_id] ),
            fact_security[reporting_dt] = reporting_dt_previous
                && NOT fact_security[security_id] IN security_current
        )
    )
    

    Without using FILTER, the filter is applied to all the  columns used in the calculation. In your second measure, you're keeping the filter for the columns included so the values show only for the rows that meet your criteria but then  you cleared the filters from reporting_dt so you if the filters are coming from this column, it will show the same value.

     

    Note: if you need to keep the filters to a particular column, just use KEEPFILTERS. FILTERS filters a table and not just a column. The performance difference is negligible with smaller datasets though.