is it possible to store a table into a DAX variable conditionally

Viewed 11

I'd like to store a table in a variable, but based on conditions of the visual.

e.g.

VAR ColumnValues = values( SpecificTable[SpecificColumn] ) 

works fine, but what I'd like to do is:

VAR ColumnValues = if([some condition T/F], values( SpecificTable1[SpecificColumn1] ) , SpecificTable2[SpecificColumn2] )

For reference, this question is in exploration of workarounds to solve question: Dynamic measure that responds to dynamic dimension which I marked as answered prematurely. I still do not have a solution to dynamically work with column values in DAX.

I've not been able to work out a syntax that allows this. Switch only returns scalar strings, and IF seems to only allow for a scalar result, not a table. Any other options I'm not thinking of?

1 Answers

Was not explicitly using any condition, but the condition that I was checking for, that I was able to get the desired result with the following:

Create Field Parameter (name it "_Dimension"), selecting the columns that need to be in play in the DAX

DAX looks like this:

    VAR SelectedDim = SELECTEDVALUE( _Dimension[_Dimension Fields] ) //fully qualified - created by field parameter
    
    //stage the values in each of the columns available
        VAR Dim1Values = ADDCOLUMNS( VALUES( Dim1[Column1] ) , "RowValue" , Dim1[Column1] , "ColumnName" , "'Dim1'[Column1]" ) 
        VAR Dim2Values = ADDCOLUMNS( VALUES( Dim1[Column2] ) , "RowValue" , Dim1[Column2] , "ColumnName" , "'Dim1'[Column2]" ) 
    //... same pattern, as many column as needed
        VAR SelectedDimValues = FILTER( UNION( Dim1Values, Dim2Values ) , [RowValue] = SelectedDim )  //return the values just for the selected column

SelectedDimValues is a Variable that contains a table with the rows from my selected dimension.

Related