I have one report with 3 visual filters (date, country and type) and a table that list the stores and number of operatios with the aplied filters. I added a column with the number of operations that meet a condition, but this measure is very slow.

Here the measure:
Nº operations with conditions = CALCULATE('OPERACIONES'[Nº lines];
FILTER('OPERACIONES';'OPERACIONES'[id_type_sale] = 4 ||
'OPERACIONES'[id_type_sale] = 5 ||
( 'OPERACIONES'[line_sin_origen]=1
|| 'OPERACIONES'[line_fuera_plazo]=1
|| 'OPERACIONES'[line_manual]=1)
))
I think that it is slow because the FILTER function is filtering all data in the table (this table has billions of records)
How can I improve this measure?
Thanks!
I'd recommend creating a calculated column which evaluates your condition for each row only once.
SatisfiesConditions =
IF (
'OPERACIONES'[id_type_sale] = 4
|| 'OPERACIONES'[id_type_sale] = 5
|| 'OPERACIONES'[line_sin_origen] = 1
|| 'OPERACIONES'[line_fuera_plazo] = 1
|| 'OPERACIONES'[line_manual] = 1,
1,
0
)
Then your measure can be simplified to
Nº operations with conditions =
CALCULATE (
'OPERACIONES'[Nº lines];
'OPERACIONES'[SatisfiesConditions] = 1
)
Try this:
Nº operations with conditions :=
CALCULATE (
[Nº lines];
'OPERACIONES'[id_type_sale] = 4
|| 'OPERACIONES'[id_type_sale] = 5
|| 'OPERACIONES'[line_sin_origen] = 1
|| 'OPERACIONES'[line_fuera_plazo] = 1
|| 'OPERACIONES'[line_manual] = 1
)
In a few situations, I've noticed a significant increase in performance by just removing the FILTER function and filtering implicitly.
Another option would be something like this (not tested):
Nº operations with conditions :=
CALCULATE (
[Nº lines],
KEEPFILTERS (
FILTER (
SUMMARIZE (
'OPERACIONES',
'OPERACIONES'[id_type_sale],
'OPERACIONES'[line_sin_origen],
'OPERACIONES'[line_fuera_plazo],
'OPERACIONES'[line_manual]
),
'OPERACIONES'[id_type_sale] = 4
|| 'OPERACIONES'[id_type_sale] = 5
|| 'OPERACIONES'[line_sin_origen] = 1
|| 'OPERACIONES'[line_fuera_plazo] = 1
|| 'OPERACIONES'[line_manual] = 1
)
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With