Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Confused: Filter function in a calculated column

I think I am just confused about the context of filter function used in a calculated column: 

Say you want to rank the products by price in products table, by creating a calculated column in the products table as below - my question is, why the filter function in red below is not taking the row context of the current row, but having access to the entire products table, and loop row by row?

Price rank = 

var currentPrice = products[Price]

return

countrows(

    filter(

       products, products[Price]>currentPrice))+1

 

Thanks!
NM

  • When you reference a table in a calculated column, rather than a single value from the row context, DAX interprets it as the whole table rather than just a single row unless there is a context transition involved that converts the row context into a filter context.

     

    Basically, it treats a table as an unfiltered table unless there is filter context involved and there isn't any inherent filter context in a calculated column unless you create some.

2 Replies

  • When you reference a table in a calculated column, rather than a single value from the row context, DAX interprets it as the whole table rather than just a single row unless there is a context transition involved that converts the row context into a filter context.

     

    Basically, it treats a table as an unfiltered table unless there is filter context involved and there isn't any inherent filter context in a calculated column unless you create some.