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
Roberto456
Resolver I
Resolver I

Reference RankX Value from a Summarized Table

Hello Everyone.

 

I'm trying to find the 2nd invoice Date created by customer in my database and I'm having a hard time doing this with RankX.

 

I need to use RankX because it has to be dynamic.

 

Below is the RankX formula I'm currently using:

Customer Invoice Rank =

VAR CURRENTCUSTOMER = MAX('Cart'[Customer_ID])
RETURN
RANKX( FILTER( ALLSELECTED( 'Cart'),'Cart'[Customer_ID]=CURRENTCUSTOMER),[Invoice Date (Min)],,ASC,Dense)
 
So far gotten it to SumX the Rank Values for each customer, but I really need to reference the Date for a certain Rank value.
 Rank Test SumX =
VAR NEWTABLE = SUMMARIZE( 'Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date])
RETURN
GROUPBY(
            ADDCOLUMNS(
                              GROUPBY(NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date]) ,
                              "The Rank",[Customer Invoice Rank]
                                     )
            ,"Value" ,SUMX(CURRENTGROUP(),[The Rank])
)
 
In the end I really need it do below but I cant use Calculate in this situation: 
Min Invoice Rank 2 =
VAR NEWTABLE = SUMMARIZE('Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date])
RETURN
GROUPBY(
          ADDCOLUMNS(
                           GROUPBY( NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date]) ,
                           "Rank",[Customer Invoice Rank]
                                  )
           ,"Value",CALCULATE( MIN( 'Cart'[Invoice_Date]), FILTER( CURRENTGROUP(), [Rank]=2))
)
 
Does anyone know how to reference the Rank in this situation?
2 ACCEPTED SOLUTIONS
Roberto456
Resolver I
Resolver I

I have updated the formula but its still not filtering for Rank 2 and only showing the Max Date.

 

Invoice Date (Min) R2 =

VAR NEWTABLE = SUMMARIZE( 'Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date], "Rank" ,[Customer Invoice Rank])
 
RETURN
 
CALCULATE(
          GROUPBY(
               ADDCOLUMNS( GROUPBY (NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date], [Rank]) ,"Invoice Min",[Invoice Date (Min)])
              ,"Value",( MAXX( CURRENTGROUP(), [Invoice Min] ) )
              )
,FILTER(NEWTABLE,[Rank]=2))

View solution in original post

Solved: I put the Calculate inside the addcolumns

 

Invoice Date (Min) R2 =

VAR NEWTABLE = SUMMARIZE('(SQL) Cart','(SQL) Cart'[Customer_ID],'(SQL) Cart'[Invoice_ID],'(SQL) Cart'[Invoice_Date],"Rank",[Customer Invoice Rank])
RETURN
GROUPBY(
ADDCOLUMNS(
GROUPBY(NEWTABLE,'(SQL) Cart'[Customer_ID],'(SQL) Cart'[Invoice_ID],'(SQL) Cart'[Invoice_Date],[Rank])
,"Invoice Min",CALCULATE([Invoice Date (Min)],FILTER(NEWTABLE,[Rank]=2))
)
,"Value",(MAXX(CURRENTGROUP(),[Invoice Min]))
)

View solution in original post

3 REPLIES 3
Roberto456
Resolver I
Resolver I

Hello Everyone.

 

I'm trying to find the 2nd invoice Date created by customer in my database and I'm having a hard time doing this with RankX.

 

I need to use RankX because it has to be dynamic.

 

Below is the RankX formula I'm currently using:

Customer Invoice Rank =

VAR CURRENTCUSTOMER = MAX('Cart'[Customer_ID])
RETURN
RANKX( FILTER( ALLSELECTED( 'Cart'),'Cart'[Customer_ID]=CURRENTCUSTOMER),[Invoice Date (Min)],,ASC,Dense)
 
So far gotten it to SumX the Rank Values for each customer, but I really need to reference the Date for a certain Rank value.
 Rank Test =
VAR NEWTABLE = SUMMARIZE( 'Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date])
RETURN
GROUPBY(
            ADDCOLUMNS(
                              GROUPBY(NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date]) ,
                              "The Rank",[Customer Invoice Rank]
                                     )
            ,"Value" ,SUMX(CURRENTGROUP(),[The Rank])
)
 
In the end I really need it do below but I cant use Calculate in this situation: 
Min Invoice Rank 2 =
VAR NEWTABLE = SUMMARIZE('Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date])
RETURN
GROUPBY(
          ADDCOLUMNS(
                           GROUPBY( NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date]) ,
                           "Rank",[Customer Invoice Rank]
                                  )
           ,"Value",CALCULATE( MIN( 'Cart'[Invoice_Date]), FILTER( CURRENTGROUP(), [Rank]=2))
)
 
Does anyone know how to reference the Rank in this situation?
Roberto456
Resolver I
Resolver I

I have updated the formula but its still not filtering for Rank 2 and only showing the Max Date.

 

Invoice Date (Min) R2 =

VAR NEWTABLE = SUMMARIZE( 'Cart', 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date], "Rank" ,[Customer Invoice Rank])
 
RETURN
 
CALCULATE(
          GROUPBY(
               ADDCOLUMNS( GROUPBY (NEWTABLE, 'Cart'[Customer_ID], 'Cart'[Invoice_ID], 'Cart'[Invoice_Date], [Rank]) ,"Invoice Min",[Invoice Date (Min)])
              ,"Value",( MAXX( CURRENTGROUP(), [Invoice Min] ) )
              )
,FILTER(NEWTABLE,[Rank]=2))

Solved: I put the Calculate inside the addcolumns

 

Invoice Date (Min) R2 =

VAR NEWTABLE = SUMMARIZE('(SQL) Cart','(SQL) Cart'[Customer_ID],'(SQL) Cart'[Invoice_ID],'(SQL) Cart'[Invoice_Date],"Rank",[Customer Invoice Rank])
RETURN
GROUPBY(
ADDCOLUMNS(
GROUPBY(NEWTABLE,'(SQL) Cart'[Customer_ID],'(SQL) Cart'[Invoice_ID],'(SQL) Cart'[Invoice_Date],[Rank])
,"Invoice Min",CALCULATE([Invoice Date (Min)],FILTER(NEWTABLE,[Rank]=2))
)
,"Value",(MAXX(CURRENTGROUP(),[Invoice Min]))
)

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.

Top Solution Authors