0
votes

Is it possible to use a variable within a DAX measure expression? For example, the following measure isn't working (it always returns 0).

Notice the second variable below is referencing the first:

Measure = 
VAR ThisMonth =
    CALCULATE (
        ABS ( SUM ( 'Table'[Saldo] ) );
        FILTER ( Table; Table[Conta] = 71 )
    )
VAR PreviouzMonth =
    CALCULATE (
        ThisMonth;
        PREVIOUSMONTH ( 'Calendário'[Date] );
        FILTER ( ALL ( 'Calendário'[Mês] ); MAX ( 'Calendário'[Mês] ) > 1 )
    )
RETURN
    ThisMonth-PreviouzMonth

But if the two variables above are calculated separetely - ie as two different measures - the calculation works fine.

Thanks for supporting!

1
Can you please post an mcve?user5226582

1 Answers

0
votes

You can have variables in expressions. The issue is somewhere else.

Something simple like this work;

Measure = 
VAR X = SUM('Sheet1 (3)'[Total])
VAR Y = DIVIDE(X,5,0)

RETURN X-Y

When you use ThisMonth inside calculate, it's not an expression. It's a variable. That might be it.