Forum Discussion
ihungko
3 years agoFrequent Visitor
How to use KEEPFILTERS with multiple OR conditions
I am trying to create a table using KEEPFILTERS with multiple OR conditions, but it seems that KEEPFIlTERS can only support AND relationships.
My scenario:
I want to filter out [Column 1], [Column 2], and [Amount] based on the conditions of [Type] OR [Category]. But KEEPFILTERS only allows an AND relationships. I want to see data that either matches [Type] condition OR [Category] condition.
EVALUATE
SUMMARIZECOLUMNS(
[Column 1],
[Column 2],
KEEPFILTERS(
TREATAS({XYZ},Type[Type])
),
KEEPFILTERS(
TREATAS({ABC},Catergory[Category])
),
[Amount]
)
Can anyone please tell me how to write the code? Thanks!
Hi, ihungko
try to use union.
here is the documentation. UNION function (DAX) - DAX | Microsoft Learn
example code
DEFINE TABLE TypeFilter = CALCULATETABLE ( 'YourTable', TREATAS ( { "XYZ" }, 'YourTable'[Type] ) ) TABLE CategoryFilter = CALCULATETABLE ( 'YourTable', TREATAS ( { "ABC" }, 'YourTable'[Category] ) ) EVALUATE SUMMARIZECOLUMNS ( [Column 1], [Column 2], UNION ( TypeFilter, CategoryFilter ), [Amount] )
1 Reply
- rubayatyasmin
Community Champion
Hi, ihungko
try to use union.
here is the documentation. UNION function (DAX) - DAX | Microsoft Learn
example code
DEFINE TABLE TypeFilter = CALCULATETABLE ( 'YourTable', TREATAS ( { "XYZ" }, 'YourTable'[Type] ) ) TABLE CategoryFilter = CALCULATETABLE ( 'YourTable', TREATAS ( { "ABC" }, 'YourTable'[Category] ) ) EVALUATE SUMMARIZECOLUMNS ( [Column 1], [Column 2], UNION ( TypeFilter, CategoryFilter ), [Amount] )