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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
mbosch
Regular Visitor

Power Query count rows

Hello!

 

I would like to add a columns Index like the one you can see below.

 

Index should count accounts by user and Cyle sorted by higher to lower. Scores can be repeated.

 

I am using following formula but it only ranks 1,1,1,1
= Table.Group(
Personalizado1,
{"Cycle", "User", "Account"},
{
{"Max Score", each List.Max([Score]), type number},
{"Index", each Table.AddIndexColumn(_, "Index", 1, 1), type table}
}
)

 

CycleUserAccountScoreINDEX
AAlexXXy1001
AAlexXXz1002
A

Alex

XXu503
AVikXXc1001
AVikXXv802
AVikXXb803
BAlexXXy1001
BAlexXXz1002
B

Alex

XXu503
BVikXXc1001
BVikXXv802
BVikXXb803

 

Really appreaciate some help! Thank you!

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @mbosch ,

 

How about this? 🙂

tackytechtom_0-1707250199150.png

 

The NewIndex was the column I created.

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXLMSa0AUhERlUDS0MAARCrF6qBJVsEljTAlS4GkKUjOGC4XlpkNlkrGYihMrgxIWqAaCZNKgklBTHTC504nfO50wuNOJzzudMLtTicc7owFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cycle = _t, User = _t, Account = _t, Score = _t, INDEX = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cycle", type text}, {"User", type text}, {"Account", type text}, {"Score", Int64.Type}, {"INDEX", Int64.Type}}),
    #"Sorted Rows1" = Table.Sort(#"Changed Type",{{"Score", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows1", {"Cycle", "User"}, {{"Grouping", each _, type table [Cycle=nullable text, User=nullable text, Account=nullable text, Score=nullable number, INDEX=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ( [Grouping], "NewIndex", 1 )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Cycle", "User", "Account", "Score", "INDEX", "NewIndex"}, {"Cycle", "User", "Account", "Score", "INDEX", "NewIndex"})
in
    #"Expanded Custom"

 

I took idea from here.

 

Let me know if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

1 REPLY 1
tackytechtom
Super User
Super User

Hi @mbosch ,

 

How about this? 🙂

tackytechtom_0-1707250199150.png

 

The NewIndex was the column I created.

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXLMSa0AUhERlUDS0MAARCrF6qBJVsEljTAlS4GkKUjOGC4XlpkNlkrGYihMrgxIWqAaCZNKgklBTHTC504nfO50wuNOJzzudMLtTicc7owFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cycle = _t, User = _t, Account = _t, Score = _t, INDEX = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cycle", type text}, {"User", type text}, {"Account", type text}, {"Score", Int64.Type}, {"INDEX", Int64.Type}}),
    #"Sorted Rows1" = Table.Sort(#"Changed Type",{{"Score", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows1", {"Cycle", "User"}, {{"Grouping", each _, type table [Cycle=nullable text, User=nullable text, Account=nullable text, Score=nullable number, INDEX=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn ( [Grouping], "NewIndex", 1 )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Cycle", "User", "Account", "Score", "INDEX", "NewIndex"}, {"Cycle", "User", "Account", "Score", "INDEX", "NewIndex"})
in
    #"Expanded Custom"

 

I took idea from here.

 

Let me know if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.