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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.