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
fandecine68
New Member

Can't find correct syntax with EARLIER

Hi,

I want to create the index column below based on duplicates Key column:

Key,Index
A1,1
A1,2
B1,1
C1,1
D1,1
D1,2
E1,1
F1,1

 

I started with this but get only 1s.....

=RANKX(
    FILTER(
        Test,
        Test[Key] = EARLIER(Test[Key])
    ),
    Test[Key]
)

Thanks for your help.

2 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

hi @fandecine68 ,

 

this is mostly done with power query. try to paste the code below into a blank query,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWBU04QyhlCuaBQrhDKDUjFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Key"}, {{"Count", each _, type table [Key=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count], "Index", 1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Index"}, {"Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Count"})
in
    #"Removed Columns"

 

for detailed steps, check like:

https://community.fabric.microsoft.com/t5/Power-Query/Group-by-a-column-and-set-index/m-p/2918028

https://community.fabric.microsoft.com/t5/Desktop/Create-Index-Column-on-Power-Query-based-on-2-or-3...

https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

 

View solution in original post

Anonymous
Not applicable

Hi @fandecine68 

 

The rankx() function can only order by the distinct values, the duplicate values can get the same number.

You can try the method posted by @FreemanZ , or add a index column in power query:

vzhengdxumsft_0-1710740232629.pngvzhengdxumsft_1-1710740253687.png

And then add a calculate column:

Column =
RANKX (
    FILTER ( ALL ( 'Table' ), 'Table'[Key] = EARLIER ( 'Table'[Key] ) ),
    'Table'[Index],
    ,
    ASC
)

The result is as follow:

vzhengdxumsft_2-1710740544586.png

Best Regards

Zhengdong Xu
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

2 REPLIES 2
Anonymous
Not applicable

Hi @fandecine68 

 

The rankx() function can only order by the distinct values, the duplicate values can get the same number.

You can try the method posted by @FreemanZ , or add a index column in power query:

vzhengdxumsft_0-1710740232629.pngvzhengdxumsft_1-1710740253687.png

And then add a calculate column:

Column =
RANKX (
    FILTER ( ALL ( 'Table' ), 'Table'[Key] = EARLIER ( 'Table'[Key] ) ),
    'Table'[Index],
    ,
    ASC
)

The result is as follow:

vzhengdxumsft_2-1710740544586.png

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FreemanZ
Super User
Super User

hi @fandecine68 ,

 

this is mostly done with power query. try to paste the code below into a blank query,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWBU04QyhlCuaBQrhDKDUjFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Key"}, {{"Count", each _, type table [Key=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count], "Index", 1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Index"}, {"Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Count"})
in
    #"Removed Columns"

 

for detailed steps, check like:

https://community.fabric.microsoft.com/t5/Power-Query/Group-by-a-column-and-set-index/m-p/2918028

https://community.fabric.microsoft.com/t5/Desktop/Create-Index-Column-on-Power-Query-based-on-2-or-3...

https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

 

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.