Forum Discussion

campelliann's avatar
campelliann
Icon for Post Patron rankPost Patron
4 years ago
Solved

Theoretical Explanation on Filter/Row Context

Hi,


So I needed to compare a certain date with the End of the month. 

When I use a measure I need to do something like this: 

if(MAX('Calendario Ano (Automatico)'[Date])>EOMONTH(today(),0),0,1)

When I use a calculated column I dont need to use the MAX around date:
if('Calendario Ano (Automatico)'[Date]>EOMONTH(today(),0),0,1)

This would lead me to believe that in tables, the row context "collapses" the table in one row, so power BI knows it must compare the date of the current row with EOMonth. 

But if for instance I were to do another different exercise and calculate the Max Date in a calculated column, power BI would return the max of the entire table not the row. I know I can use calculate to do a context transition to filter context, but this seems contractictory. 

If anyone can explain the logic behind I would be most grateful 🙂 

Best wishes



  • Hi campelliann 

    Thanks for reaching out to us.

    To understand that, we need to know the difference between measure and column first:

    • Measures are calculated in the context of visual or DAX queries, and calculated columns are calculated at the row level of the table in which they are located. This is because the calculated columns are calculated row by row, and the measures aggregate the data in the current context. When creating a calculated column, DAX will create a row context by default, use it as a cursor, iterate the table row by row, and evaluate the expression. Therefore, we don't need to manually create the row context. We can directly use table[column] to obtain the contents of the current row.

    Then we need to know the row context and the filter context, you can refer to this video:

    https://www.youtube.com/watch?v=NkYwwb7I3BY

     

    Best Regards,

    Community Support Team _Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • v-xiaotang's avatar
    v-xiaotang
    Icon for Community Support rankCommunity Support

    Hi campelliann 

    Thanks for reaching out to us.

    To understand that, we need to know the difference between measure and column first:

    • Measures are calculated in the context of visual or DAX queries, and calculated columns are calculated at the row level of the table in which they are located. This is because the calculated columns are calculated row by row, and the measures aggregate the data in the current context. When creating a calculated column, DAX will create a row context by default, use it as a cursor, iterate the table row by row, and evaluate the expression. Therefore, we don't need to manually create the row context. We can directly use table[column] to obtain the contents of the current row.

    Then we need to know the row context and the filter context, you can refer to this video:

    https://www.youtube.com/watch?v=NkYwwb7I3BY

     

    Best Regards,

    Community Support Team _Tang

    If this post helps, please consider Accept it as the solution to help the other members find it more quickly.