Forum Discussion
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[security_id] IN security_current,
REMOVEFILTERS(fact_security[reporting_dt])
)
security_current_sell =
CALCULATE(
[measure_1],
FILTER(
fact_security,
fact_security[reporting_dt] = reporting_dt_previous &&
NOT fact_security[security_id] IN security_current
),
REMOVEFILTERS(fact_security[reporting_dt])
)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.
5 Replies
- danextian
Super User
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.
- techies
Super User
- Irwan
Super User
hello TRADER083
try checking this page, FreemanZ explained it very simple and clear.
Solved: help in understanding use of FILTER within CALCULA... - Microsoft Fabric Community
Thank you.
- v-hashadapu
Community Support
- v-hashadapu
Community Support
Hi TRADER083 , Hope you are doing well. Kindly let us know if the issue has been resolved or if further assistance is needed. Your input could be helpful to others in the community.