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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Everton
Helper I
Helper I

RANKX within group

Hi,

 

I want to rank within the InvoiceNumber group by CreatedDate, the latest date should be rank 1. There are two InvoiceNumber in the below data 408 and 449. 

Everton_0-1648016249480.png

I have created a measure to do the ranking:

InvoiceRankInTimePeriod =
VAR CreatedDate = [CreatedDateMin]
VAR Invoices =
CALCULATETABLE ( 'Data InvoiceFact', ALLSELECTED ( 'Data InvoiceFact' ), Values('Data InvoiceFact'[InvoiceNumber]) )
VAR InvoiceRank =
RANKX ( Invoices, VALUE(FORMAT([CreatedDateMin], "YYYYMMDDHHmmss") + [InvoiceKeyMin]))
VAR Result =
IF ( NOT ISBLANK ( CreatedDate ), InvoiceRank )
RETURN
Result

 

The ranking works:

Everton_1-1648016455843.png

I am wondering why it works, in particular what is VALUES doing within the CALUCLATETABLE function. 

1 REPLY 1
AilleryO
Memorable Member
Memorable Member

Hi,

 

The VALUES function creates a virtual table with all unique values of Invoice Number.

It's very close to DISTINCT function, even though soem diffrences might appear in some calculations.

To have more details on both functions, please refer to :

https://dax.guide/distinct/

and

https://dax.guide/values/

 

Hope it makes more sense for you

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.