Forum Discussion
How to apply filter on multiple columns with OR operator using DAX formula
- 4 years ago
Hi Anonymous
You can tweak your current syntax to apply Filter Condition 1 OR Filter Condition 2:
EVALUATE FILTER ( SUMMARIZECOLUMNS ( Asset[Type], Asset[Program], Asset[Category], Sales[Period], Sales[Quantity] ), OR ( Asset[Program] = "Primary Assets", Asset[Category] IN { "ASM", "NSN", "TPG", "STB" } ) )One potential performance issue with FILTER( SUMMARIZECOLUMNS(...)) is that SUMMARIZECOLUMNS returns the full table (which contains some unwanted rows) which is then iterated over with FILTER.
An alternative, which may perform better, is to construct a table containing the filter condition, and provide that as an argument in SUMMARIZECOLUMNS after the Groupby columns. Something like this:
EVALUATE VAR FilterTable = UNION ( CROSSJOIN ( TREATAS ( { "Primary Assets" }, Asset[Program] ), ALL ( Asset[Category] ) ), CROSSJOIN ( ALL ( Asset[Program] ), TREATAS ( { "ASM", "NSN", "TPG", "STB" }, Asset[Category] ) ) ) RETURN SUMMARIZECOLUMNS ( Asset[Type], Asset[Program], Asset[Category], Sales[Period], Sales[Quantity], FilterTable )See also this article (which the 2nd approach above is based on):
https://www.sqlbi.com/articles/using-or-conditions-between-slicers-in-dax/
Regards,
Owen
Hi Anonymous
You can tweak your current syntax to apply Filter Condition 1 OR Filter Condition 2:
EVALUATE
FILTER (
SUMMARIZECOLUMNS (
Asset[Type],
Asset[Program],
Asset[Category],
Sales[Period],
Sales[Quantity]
),
OR (
Asset[Program] = "Primary Assets",
Asset[Category] IN { "ASM", "NSN", "TPG", "STB" }
)
)
One potential performance issue with FILTER( SUMMARIZECOLUMNS(...)) is that SUMMARIZECOLUMNS returns the full table (which contains some unwanted rows) which is then iterated over with FILTER.
An alternative, which may perform better, is to construct a table containing the filter condition, and provide that as an argument in SUMMARIZECOLUMNS after the Groupby columns. Something like this:
EVALUATE
VAR FilterTable =
UNION (
CROSSJOIN (
TREATAS ( { "Primary Assets" }, Asset[Program] ),
ALL ( Asset[Category] )
),
CROSSJOIN (
ALL ( Asset[Program] ),
TREATAS ( { "ASM", "NSN", "TPG", "STB" }, Asset[Category] )
)
)
RETURN
SUMMARIZECOLUMNS (
Asset[Type],
Asset[Program],
Asset[Category],
Sales[Period],
Sales[Quantity],
FilterTable
)
See also this article (which the 2nd approach above is based on):
https://www.sqlbi.com/articles/using-or-conditions-between-slicers-in-dax/
Regards,
Owen
- Anonymous4 years agoNot applicable
Thanks for your help OwenAuger!