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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kongyuancn
Helper II
Helper II

RANKX on Table Expression

Hi There,

 

I have a smiple table:

kongyuancn_0-1634199699590.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YGRTmDSGUbGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}})
in
    #"Changed Type"

 

I created a rank measure like this:

RankOnTable = RANKX(ALL('Table'),CALCULATE(MAX('Table'[Data])),,ASC)

 

Then I draged the table as this:

kongyuancn_1-1634199876184.png

It seems perfect.

 

Then I created another measure to try to use a table expression:

RankOnTableExp = 
VAR DistinctTable = VALUES('Table'[Data])
VAR TableWithRank = ADDCOLUMNS(
    DistinctTable,
    "RANK",RANKX(DistinctTable,CALCULATE(MAX('Table'[Data])),,ASC)
)
VAR CurrentData = CALCULATE(MAX('Table'[Data]))
VAR CurrentDataRank = CALCULATE(MAXX(TableWithRank,[RANK]))
RETURN
    CurrentDataRank

Then I get the table which looks like:

kongyuancn_2-1634200150408.png

 

Can anyone tell me what is wrong?

 

Thanks in advance

1 ACCEPTED SOLUTION

Thank you @lbendlin for your reply. But it doesn't work.

Values doesn't accept allselected inside, so I changed to distinct:

 

RankOnTableExp =
VAR DistinctTable = DISTINCT(ALLSELECTED('Table'[Data]))
VAR TableWithRank = ADDCOLUMNS(
DistinctTable,
"RANK",RANKX(DistinctTable,CALCULATE(MAX('Table'[Data])),,ASC)
)
VAR CurrentData = CALCULATE(MAX('Table'[Data]))
VAR CurrentDataRank = CALCULATE(MAXX(TableWithRank,[RANK]))
RETURN
CurrentDataRank

 


And the result is still wrong:

 

kongyuancn_1-1634535181680.png

 

View solution in original post

6 REPLIES 6
wdx223_Daniel
Super User
Super User

VAR CurrentDataRank = MAXX(FILTER(TableWithRank,'Table'[Data]=CurrentData),[RANK])

Thank you @wdx223_Daniel, I still get wrong result.

kongyuancn_0-1634623696332.png

 

wdx223_Daniel_0-1634628413020.png

 

Thank you @wdx223_Daniel that works good.

lbendlin
Super User
Super User

RankOnTableExp = 
VAR DistinctTable = VALUES(ALLSELECTED('Table'[Data]))
VAR TableWithRank = ADDCOLUMNS(
    DistinctTable,
    "RANK",RANKX(DistinctTable,CALCULATE(MAX('Table'[Data])),,ASC)
)
VAR CurrentData = CALCULATE(MAX('Table'[Data]))
VAR CurrentDataRank = CALCULATE(MAXX(TableWithRank,[RANK]))
RETURN
    CurrentDataRank

Thank you @lbendlin for your reply. But it doesn't work.

Values doesn't accept allselected inside, so I changed to distinct:

 

RankOnTableExp =
VAR DistinctTable = DISTINCT(ALLSELECTED('Table'[Data]))
VAR TableWithRank = ADDCOLUMNS(
DistinctTable,
"RANK",RANKX(DistinctTable,CALCULATE(MAX('Table'[Data])),,ASC)
)
VAR CurrentData = CALCULATE(MAX('Table'[Data]))
VAR CurrentDataRank = CALCULATE(MAXX(TableWithRank,[RANK]))
RETURN
CurrentDataRank

 


And the result is still wrong:

 

kongyuancn_1-1634535181680.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.