Forum Discussion
How to create dynamic filter in DAX query
- 1 year ago
Hello,
Thank you for the inputs. As I want to add multiple filters dynamically, I chose the following route:
EVALUATE
FILTER(MyTable,
AND(MyTable[col1]=@Col1Value , IF(NOT(ISBLANK(@Col2Value)), MyTable[col2]=@qCol2Value, TRUE().....))I will also try your syntax.
Hi bhavya11 ,
"MyTable[col1]=" & @param1
This part looks like text, and the second argument to filter needs to be a boolean expression.
FILTER function (DAX) - DAX | Microsoft Learn
Please try:
DEFINE
VAR param1Value = @param1
VAR filters =
IF (
NOT ISBLANK ( param1Value ),
FILTER ( MyTable, MyTable[col1] = param1Value ),
MyTable
)
EVALUATE
filters
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hello,
Thank you for the inputs. As I want to add multiple filters dynamically, I chose the following route:
EVALUATE
FILTER(MyTable,
AND(MyTable[col1]=@Col1Value , IF(NOT(ISBLANK(@Col2Value)), MyTable[col2]=@qCol2Value, TRUE().....))
I will also try your syntax.