Forum Discussion

Santiago95's avatar
Santiago95
New Member
7 years ago

DAX table variables

For the last couple of weeks I`ve been trying to incorporate variables in DAX codes. However, I´ve struggled deepley when defining tables as variables. The main problem comes up when trying to reference an existing column from the table previously defined as a variable, it seems that this can´t be done. Lets look at the following code for the better understanding of the problem. (The formula used is LOOKUPVALUE):

 

Measure =


VAR Table_1= GROUPBY('Indice de estacionalidad';'Indice de estacionalidad'[Codigo];"MAX";MAXX(CURRENTGROUP();'Indice de estacionalidad'[Promedio anual]))
return


LOOKUPVALUE(


LOOKUPVALUE( ‘ Here we would need to reference a column from the table Tabla_1 ’; …. ; ….

 

(THE LANGUAGE USED IS SPANISH)

 

The example shown is very basic and variables should not be needed. However, this would be part of an even longer code, and defining tables as variable will make the code easier to read.

Another clear example would be instead of using LOOKUPVALUE, using ALL, were the columns of the virtual table cannot be accesed.

 

2 Replies

  • Yeah, it's an annoying limitation. However, there are workarounds.

     

    For example, if you want to look up the [Promedio anual] for a given [Codigo], say, 123, then you can access it like this:

     

    MAXX(
        FILTER(Table_1, [Codigo] = 123),
        [Promedio anual]
    )

    There's only one row for that [Codigo], so the max will just be whatever is in that column.

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi Santiago95,

     

    Have you solved your problem?

     

    If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

     

    If you still need help, please share some sample data and your desired output so that we could help further on it.

     

    Best Regards,

    Cherry