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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
gbrenner35
Frequent Visitor

Ranking Order Dates by Customer

Hi,

 

I am trying to rank my orders, which are unique to my customers, by OrderDate, i.e. SO52682 will have a 1, SO53684 a rank of 2 and SO56488 a rank of 3...etc.

 

CustomerKeySalesOrderNumberSalesOrderLineNumberOrderDateNumber of Orders by Customer
11142SO5268218/17/200317
 SO5368419/2/200317
  29/2/200317
  39/2/200317
 SO56488110/22/200317
  210/22/200317
 SO56610110/24/200317
 SO60699112/25/200317
  212/25/200317
  312/25/200317
 SO6203611/14/200417
  21/14/200417
  31/14/200417
 SO6224711/17/200417
  21/17/200417
 SO6389412/10/200417
 SO6671313/23/200417
  23/23/200417
 SO6678413/24/200417
 SO6803914/11/200417
  24/11/200417
  34/11/200417
 SO7229616/6/200417
  26/6/200417
 SO7280116/13/200417
  26/13/200417
  36/13/200417
 SO7297616/15/200417
  26/15/200417
  36/15/200417
 SO7318516/18/200417
 SO7427217/4/200417
  27/4/200417
  37/4/200417
 SO7462517/16/200417
  27/16/200417
Grand Total    
 
I tried this calculated column, but it returned rank of 1-35 (skipping numbers in between) instead of 17.
 
Purchase Date Index
=RANKX(CALCULATETABLE(Sales, ALLEXCEPT(Sales,Sales[CustomerKey], Sales[Number of Orders by Customer])),Sales[OrderDate],,ASC)
 
gbrenner35_0-1634956104576.jpeg

 

ReplyForward
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gbrenner35 ,

 

1. Go to Power Query to transform the data:

 
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type"," ",null,Replacer.ReplaceValue,{"SalesOrderNumber"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"CustomerKey","SalesOrderNumber"}),
    #"Added Index" = Table.AddIndexColumn(#"Filled Down", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

Eyelyn9_1-1635230551556.png

 

2. Then use the following formula:

Column = 
var _column= RANKX(FILTER('Table',[CustomerKey]=EARLIER('Table'[CustomerKey]) && [SalesOrderNumber]=EARLIER([SalesOrderNumber])),[OrderDate],,ASC,Dense)
return 
RANKX(FILTER('Table',[CustomerKey]=EARLIER('Table'[CustomerKey]) && [SalesOrderNumber]=EARLIER([SalesOrderNumber])),_column*100+[Index],,ASC,Dense)

Below is the final output:

Eyelyn9_2-1635231043784.png

 

 

Best Regards,
Eyelyn Qin
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 @gbrenner35 ,

 

1. Go to Power Query to transform the data:

 
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type"," ",null,Replacer.ReplaceValue,{"SalesOrderNumber"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"CustomerKey","SalesOrderNumber"}),
    #"Added Index" = Table.AddIndexColumn(#"Filled Down", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

Eyelyn9_1-1635230551556.png

 

2. Then use the following formula:

Column = 
var _column= RANKX(FILTER('Table',[CustomerKey]=EARLIER('Table'[CustomerKey]) && [SalesOrderNumber]=EARLIER([SalesOrderNumber])),[OrderDate],,ASC,Dense)
return 
RANKX(FILTER('Table',[CustomerKey]=EARLIER('Table'[CustomerKey]) && [SalesOrderNumber]=EARLIER([SalesOrderNumber])),_column*100+[Index],,ASC,Dense)

Below is the final output:

Eyelyn9_2-1635231043784.png

 

 

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

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