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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
daanodinot
Frequent Visitor

Row and Filter contexts

I'm still massively confused by row and filter contexts. Here's a solution (a measure) to an exercise I was doing.

 

Ranking = RANKX(
    ALL(Series),
    CALCULATE(SUM(Series[Viewers (m)])),
    ,
    ASC
)

 

Only the first two lines really matter for my question.

My understanding is that iterators like RANKX introduce a row context. Since RANKX works in a row context, I was expecting it not to be affected by any filters. But the fact that you have to use All(Series) instead of Series, shows that it's still operating in a filter context. So what, then, makes it a row context? Why doesn't Series simply work without All?

One last thing: please don't give general answers like 10 links to articles/videos about filters. I'm already reading/watching those, and a specific answer to my question would be much more helpful. Thanks in advance!

1 ACCEPTED SOLUTION
v-xiaosun-msft
Community Support
Community Support

Hi @daanodinot ,

 

According to your description, I created a sample. Measure 2 is using ALL function.

vxiaosunmsft_0-1664257462344.png

When using RANKX function without ALL function, the following steps will be performed.

RANKX(<table>, <expression>[, <value>[, <order>[, <ties>]]])

Step1: Calculate the query context.

Step2: The RANKX function creates an iteration context in Table Score.

Step3: Compute expression, perform a context transformation, change to a filtering context again, and generate a data series of ranking.

Step4: Calculate the value in the query context.

Step5: Calculate the rank of value in the data series in the query context.

Note that in Step 5, the query context, in addition to being used to calculate the value, but also for filtering the data series, so that all ranking results are 1.

But when you use ALL function, it will only clear the filter of data columns when calculating the rank of value and does not affect the expression time and value calculation. Therefore, you can get the correct result.

 

Best Regards,
Community Support Team _ xiaosun

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

View solution in original post

3 REPLIES 3
v-xiaosun-msft
Community Support
Community Support

Hi @daanodinot ,

 

According to your description, I created a sample. Measure 2 is using ALL function.

vxiaosunmsft_0-1664257462344.png

When using RANKX function without ALL function, the following steps will be performed.

RANKX(<table>, <expression>[, <value>[, <order>[, <ties>]]])

Step1: Calculate the query context.

Step2: The RANKX function creates an iteration context in Table Score.

Step3: Compute expression, perform a context transformation, change to a filtering context again, and generate a data series of ranking.

Step4: Calculate the value in the query context.

Step5: Calculate the rank of value in the data series in the query context.

Note that in Step 5, the query context, in addition to being used to calculate the value, but also for filtering the data series, so that all ranking results are 1.

But when you use ALL function, it will only clear the filter of data columns when calculating the rank of value and does not affect the expression time and value calculation. Therefore, you can get the correct result.

 

Best Regards,
Community Support Team _ xiaosun

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

Thank you for your detailed answer, and sorry for my late response.

I think my confusion was indeed related to the role of the ALL function.

I haven't come much across the concept of query context. My understanding was there was only a row and filter context - together forming the evaluation context. Am I right that a query context is the context of the Score cell and that a query context is created for every Score cell? (The first one being 1 and the last one being 233.)

johnt75
Super User
Super User

"Since RANKX works in a row context, I was expecting it not to be affected by any filters". That is not the case. Iterators like RANKX work on all the rows of a table which are visible in the current filter context. Any rows which are excluded by filters are not included in the calculations.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors