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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
kongyuancn
Helper I
Helper I

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors