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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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

v-zhengdxu-msft
Community Support
Community Support

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
v-zhengdxu-msft
Community Support
Community Support

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors