Forum Discussion
OR condition between multivalue parameters
Using OR operator is trick in Report Builder. I have recorded as short video showing how to achieve this.
Actually, trick part is modifying DAX query and use parameter properly in this query. For your reference here is the query, and let me explain how does Report Builder/PowerBI RS handles parameters with OR.
CALCULATE (
[measure],
UNION (
CROSSJOIN ( VALUES ( T1[Column1] ), ALL ( T2[Column2] ) ),
CROSSJOIN ( ALL ( T1[Column1] ), VALUES ( T2[Column2] ) )
)
)
This is how to implement multi-column filter. There are other methods, but this one is suitable for injecting parameters (For other techniques please refer to this excellent article. We are using #1).
Power BI Report Builder Query Editor generates this query (for sure its "AND")
EVALUATE SUMMARIZECOLUMNS(
RSCustomDaxFilter(@DimProductColor,EqualToCondition,[DimProduct].[Color],String),
RSCustomDaxFilter(@DimProductSize,EqualToCondition,[DimProduct].[Size],String),
"TotalSalesAmount", [TotalSalesAmount])
Then, when executing, engine re-writes it and uses selected parameters and injects them as "FILTER" (still uses AND)
EVALUATE SUMMARIZECOLUMNS(
FILTER (
VALUES ( 'DimProduct'[Color] ),
( 'DimProduct'[Color] = "Black" )
|| ( 'DimProduct'[Color] = "Blue" )
|| ( 'DimProduct'[Color] = "Grey" )
) ,
FILTER (
VALUES ( 'DimProduct'[Size] ),
( 'DimProduct'[Size] = "L" )
|| ( 'DimProduct'[Size] = "M" )
|| ( 'DimProduct'[Size] = "S" )
|| ( 'DimProduct'[Size] = "XL" )
),
"TotalSalesAmount", [TotalSalesAmount])
So every RSCustomDaxFilter function is translated to corresponding "FILTER". If we change our query to apply this method (to use OR), we get the result we want. Finally here is the query which is modified in the Power BI Report Builder Query Editor.
EVALUATE SUMMARIZECOLUMNS(UNION (
CROSSJOIN (
RSCustomDaxFilter(@DimProductColor,EqualToCondition,[DimProduct].[Color],String),
ALL ( 'DimProduct'[Size] )
),
CROSSJOIN (
ALL ( 'DimProduct'[Color] ),
RSCustomDaxFilter(@DimProductSize,EqualToCondition,[DimProduct].[Size],String)
)
), "TotalSalesAmount", [TotalSalesAmount])
Hope it helps.
If my post solved your problem, mark my post as a solution to help others to quickly find it and also please give it a 👍
Hi,
I found your solution to be useful, but I am not clear how I can modify it to suit my requirement. My current report builder query is as below:
EVALUATE SUMMARIZECOLUMNS('DataforPL'[CNTR], 'DataforPL'[CNTR_DT], 'DataforPL'[SUPP_LD_NO], RSCustomDaxFilter(@DataforPLCNTR,EqualToCondition,[DataforPL].[CNTR],String), RSCustomDaxFilter(@DataforPLCNTRDT,EqualToCondition,[DataforPL].[CNTR_DT],DateTime), RSCustomDaxFilter(@DataforPLSUPPLDNO,EqualToCondition,[DataforPL].[SUPP_LD_NO],String))
I have 3 parameters in above query above. I need to modify it such either I enter a combination of [CNTR] & [CNTR_DT] or enter just enter [SUPP_LD_NO] as the parameter, leaving other two fields blank.
Hope I was clear with my requirement. Thanks to assist.
Regards,
Muralidhar
- Hariharan_R5 years agoSolution Sage
Hi Murali,
Try like below. You may need to handle "ALL" (blank) is no value is passed.
SUMMARIZECOLUMNS ('Data'[CNTR], 'Data'[CNTR_DT], 'Data'[SUPP_LD_NO],FILTER (Data,(FORMAT ( Data[CNTR_DT], "YYYY-MM-DD" )<= FORMAT ("2020-01-01", "YYYY-MM-DD" )|| (PATHCONTAINS ( "A", DATA[CNTR] )))|| PATHCONTAINS ("1ABC", DATA[SUPP_LD_NO])))ThanksHari- murali54315 years agoHelper III
Thank you Hariharan_R !
- Hariharan_R5 years agoSolution Sage
If my answer helps you, Mark my post as a solution!!