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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
harshagraj
Post Partisan
Post Partisan

Rank in Direct Query to sort

Hello all, 
I am in direct query mode and i am trying to achieve a horizontal bar chart with highest rated user in the module like below. I am able to this in Tableau and I am not able to create a rank calculation in Power BI. Kinldy modify the below dax to achieve like the ss below.

 

Manager Rating is a calculated measure 

Manager Rating =
CALCULATE (
    SUM ( 'USER_RATING_VIEW'[MANAGER_RATINGS_FINAL] ),
    ALLEXCEPT (
        'USER_RATING_VIEW',
        'USER_RATING_VIEW'[USER_DN],
        'USER_RATING_VIEW'[Module],
        'USER_RATING_VIEW'[QUESTION],
        'USER_RATING_VIEW'[MANAGER_RATINGS_FINAL],
        'USER_RATING_VIEW'[JOB_ROLE_BAND]
    )
)


Required view on Power BI

 

harshagraj_0-1691136602693.png

Tried this below rank to sort.

 

Rank_Module =
RANKX(
    CALCULATETABLE(
        VALUES(USER_RATING_VIEW[USER_DN]),
        ALLSELECTED(USER_RATING_VIEW[USER_DN])),
CALCULATE([Manager Rating]))
 
 

 

 

ModuleManager RatingUSER_DN
R&R162C
SOI126C
KSI114C
R&R108A
DT105C
R&R73D
KSI66A
DT63A
DT63D
SOI60A
SOI56D
R&R48B
KSI45D
SOI30B
KSI29B
DT28B
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @harshagraj ,

 

As far as I know, Power BI doesn't support us to sort values in same legend with different groups at the same time.

Here I have a workaround. You need to add [USER_DN] in Y-axis as level2 and add Rank measure into Tooltip.

vrzhoumsft_0-1691390033010.png

Measure:

Rank_Module = 
MAX(USER_RATING_VIEW[Module])
&""&
RANKX(
    CALCULATETABLE(
        VALUES(USER_RATING_VIEW[USER_DN]),
        ALLSELECTED(USER_RATING_VIEW[USER_DN])),
CALCULATE([Manager Rating]))
 

Sort axis by [Rank_Module] measure. Result is as below.

vrzhoumsft_1-1691390112760.png

Best Regards,
Rico Zhou

 

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

1 REPLY 1
Anonymous
Not applicable

Hi @harshagraj ,

 

As far as I know, Power BI doesn't support us to sort values in same legend with different groups at the same time.

Here I have a workaround. You need to add [USER_DN] in Y-axis as level2 and add Rank measure into Tooltip.

vrzhoumsft_0-1691390033010.png

Measure:

Rank_Module = 
MAX(USER_RATING_VIEW[Module])
&""&
RANKX(
    CALCULATETABLE(
        VALUES(USER_RATING_VIEW[USER_DN]),
        ALLSELECTED(USER_RATING_VIEW[USER_DN])),
CALCULATE([Manager Rating]))
 

Sort axis by [Rank_Module] measure. Result is as below.

vrzhoumsft_1-1691390112760.png

Best Regards,
Rico Zhou

 

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

 

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors