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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

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
Most Valuable Professional
Most Valuable Professional

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
Most Valuable Professional
Most Valuable Professional

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.