Forum Discussion
How to use FILTER() inside CALCULATE()
- 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.
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.