Gary Walton on 21 Dec 2022 11:32:47
The below proposal will enhance the utility of the recently introduced field parameters capability.
In this brief example, a matrix table visual shows the result of a True/False measure using field parameter for both rows and columns.
Problem: How do you count the occurrences of True and show as a separate card visual?
Until now, the rows and columns used in the matrix table visual would have been static, meaning a single SUMMARIZE measure would suffice.
With the inclusion of field parameters we now resort to multiple SUMMARIZE within a SWITCH, one for each combination of the field parameters used.
This can quickly become untenable, resulting in extremely long DAX measures and pain when adding items to a field parameter.
The acceptance of variables as table references could drastically reduce repetition. However they would need to be correct as if typed manually.
In the example below, TBLREF_A & TBLREF_B replace the manually typed table references in the SELECTEDCOLUMNS functions within the CROSSJOIN, they are formatted appropriately and if replaced with static values, work as expected.
Count of True in Matrix =
Var PARAM_A = SELECTEDVALUE('Field Parameter A'[Field Parameter A Fields],0)
Var TBLREF_A = SUBSTITUTE(LEFT(PARAM_A,SEARCH("[",PARAM_A,1)-1),"'","")
Var PARAM_B = SELECTEDVALUE('Field Parameter B'[Field Parameter B Fields],0)
Var TBLREF_B = SUBSTITUTE(LEFT(PARAM_B,SEARCH("[",PARAM_B,1)-1),"'","")
Var TBL_C =
ADDCOLUMNS(
SUMMARIZE(
CROSSJOIN(
SELECTCOLUMNS(TBLREF_A,"A",PARAM_A),
SELECTCOLUMNS(TBLREF_B,"B",PARAM_B)),
[A], [B]),"__Value", [T/F Measure])
VAR __Result = COUNTROWS(FILTER(TBL_C, [__Value] = TRUE))
Return
//__Result
This shows only one possibility of what allowing variables as table references with DAX could bring, specifically in conjunction with user interactive field parameters.