Forum Discussion
Nested Filter DAX Query
- 4 years ago
robarivas you should not use CALCULATETABLE on top of SUMMARIZECOLUMNS.
You can achieve the same by using the filter parameter inside SUMMARIZECOLUMNS.
So, you should write your code like this:SUMMARIZECOLUMNS ( 'DimTable1'[Field_A], 'DimTable1'[Field_G], FILTER( ALL('DimTable4'[Field K]), 'DimTable4'[Field K] = "Revenue" ), FILTER( ALL('DimTable1'[Field_A],'DimTable1'[Field_G]), 'DimTable1'[Field_A] IN { "West", "East" } || ( 'DimTable1'[Field_G] IN { "Red", "Blue" } && 'DimTable1'[Field_A] = "" ) ), "Total Amount", [Total Amount] )
In case it solved your question, please mark this as a solution. Appreciate your Kudos
Hi robarivas
That's interesting. SUMMARIZECOLUMNS can be called within CALCULATETABLE, but, as you've mentioned, an error is returned when CALCULATETABLE has a filter argument containing an || operator between conditions on different columns of the same table. This also seems to be the case if the offending filter argument is constructed as a table.
As an alternative, I would recommend making use of FilterTable arguments within SUMMARIZECOLUMNS itself, unless there's any reason not to. It does mean that you have to construct all filters as tables rather than use boolean expressions.
EVALUATE
VAR DimTable4Filter =
TREATAS ( { "Revenue" }, 'DimTable4'[Field K] )
VAR DimTable1Filter =
FILTER (
ALL ( 'DimTable1'[Field_A], 'DimTable1'[Field_G] ),
'DimTable1'[Field_A] IN { "West", "East" }
|| ( 'DimTable1'[Field_G] IN { "Red", "Blue" }
&& 'DimTable1'[Field_A] = "" )
)
RETURN
SUMMARIZECOLUMNS (
'DimTable1'[Field_A],
'DimTable1'[Field_G],
DimTable4Filter,
DimTable1Filter,
"Total Amount", [Total Amount]
)
Does this work as intended?
Regards,
Owen
Hello OwenAuger Thanks so much. This does work.
As a followup, what if my Nested Filter needed to involve more than just 1 table? Would I have to do something like this: CROSSJOIN ( ALL(Table1), ALL(Table2)) ? And is that the best way to go?
Looking for as flexible and general a pattern as possible.