Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
NanPowerBI
Frequent Visitor

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

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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.

View solution in original post

2 REPLIES 2
ALLUREAN
Solution Sage
Solution Sage

Hi, @NanPowerBI 

Just try something like:

Price rank =

VAR currentPrice = products[Price]

RETURN

COUNTX(

FILTER(

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

 

Did I answer your question? Please Like and Mark my post as a solution if it solves your issue. Thanks.

Appreciate your Kudos !!!

https://allure-analytics.com/

https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




AlexisOlson
Super User
Super User

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.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors