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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
elsteshepardo
Frequent Visitor

Using RANKX & FILTER

Hi

I've got 2 tables - 1 that stores a Project request (Requests), 2 stores an assessment (Request Assessment)

I want to rank the scores from table 2 - I've got the code for this after watching some Bas videos on Youtube

 

 

RequestsAssessmentPriority = 
VAR AssessmentRank = 
RANKX(
    ALL('Request Assessment'),
    CALCULATE(SUM('Request Assessment'[TotalMinusEffort])),,DESC,Dense)

VAR Result = 
IF(MAX('Request Assessment'[TotalMinusEffort]) <> 0, AssessmentRank)

RETURN
Result

 

This works but I want to exclude completed requests (no point in ranking 'old' projects). I have a status column in Table 1 that has a completed value - I want to filter the ranking but exclude the completed requests. I also want to keep the ALL so that any filters applied to the visual/report aren't applied - I need to know that Request #1 is always Request #1

 

Table 1 and Table 2 are related with an ID column (1:1 relationship)

 

 

 

 

3 REPLIES 3
elsteshepardo
Frequent Visitor

Hi @Anonymous 

Yeah, that's how the tables are in my data (albeit simplified)

I've done the same and compared <> complete and including complete:

 

elsteshepardo_0-1729156922011.png

 

The left table show the measure as you're written that I already have - as you can see, Rank 5 is missing - it's filtering the resulting table

The right table shows the measure without the filter and Rank 5 is shown (stage = complete)

 

I don't profess to understand DAX at all, but logically it makes sense to me that the RANK part of the statement needs to include the filtering part. Doing the rank on ALL, and then only filtering the results would give the results I have?

 

I'll re-do your example with a new query and see if I get the same results as you

Thanks

@Anonymous 

I've gone through the same steps as you did, set up some new tables, linked them. I added a few more rows and some other status too.

I still don't get the required results - i.e. I want the rank to exclude Completed projects

 

elsteshepardo_0-1729171477094.pngelsteshepardo_1-1729171505122.pngelsteshepardo_2-1729171543730.png

 

The same measure, gives me this result:

elsteshepardo_3-1729171619262.png

As before, you can see that some ranks are missing - 7, 8 and 12

And just to be sure, this is the measure:

RequestsAssessmentPriority = 
VAR AssessmentRank = 
    RANKX(
        ALL('Request Assessment'),
        CALCULATE(SUM('Request Assessment'[TotalMinusEffort])),
        ,
        DESC,
        Dense
    )
VAR Result = 
    IF(
        MAX('Requests'[Stage]) <> "Complete" && MAX('Request Assessment'[TotalMinusEffort]) <> 0, 
        AssessmentRank
    )
RETURN
    Result

Any ideas?

Anonymous
Not applicable

Hi @elsteshepardo 

 

The following testing is for your reference.

 

My sample:

 

Requests table:

vxuxinyimsft_0-1729131612019.png

 

Request Assessment table:

vxuxinyimsft_1-1729131664870.png

 

Relationship:

vxuxinyimsft_2-1729131754704.png

 

Create a measure as follows:

RequestsAssessmentPriority = 
VAR AssessmentRank = 
    RANKX(
        ALL('Request Assessment'),
        CALCULATE(SUM('Request Assessment'[TotalMinusEffort])),
        ,
        DESC,
        Dense
    )
VAR Result = 
    IF(
        MAX('Requests'[Status]) <> "Completed" && MAX('Request Assessment'[TotalMinusEffort]) <> 0, 
        AssessmentRank
    )
RETURN
    Result

 

Output:

vxuxinyimsft_3-1729131870441.png

 

If this sample data is structurally different from the one you are using, please provide some sample data and the desired output based on the sample data so that I can help you better. How to provide sample data in the Power BI Forum - Microsoft Fabric Community

 

Best Regards,
Yulia Xu

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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