Forum Discussion

Mona01's avatar
Mona01
Frequent Visitor
7 years ago
Solved

Nested Calculate to compute Simple moving Average

Hi, I am new in Dax. I am just going through an article which compute simple moving average. As per my understanding, it is a calculated column So there is a row context. So the VALUES(SMoving[DayNu...
  • AlB's avatar
    7 years ago

    Hi Mona01

     

    VALUES( ) is not be affected by row context, only by filter context. If you use VALUES( Table1[Column1] ) directly in a calculated column, you will get a one-column table with the unique values in Table1[Column1], since there is no filter context. 

     

    In the second example that you show, the outermost CALCULATE however converts the row context into a filter context through context transition. In this way, when VALUES( ) is evaluated, there is a filter context that actually filters the current row (and its duplicates, if there are any) and therefore VALUES ( Prices[DayNumber] ) will return the value of Prices[DayNumber] in the current row.      

     

    You might want to take a look at this and this articles by the Italian gurus.