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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Group Data by number of rows

Hello my PBI friends

 

Odd question, here. I have table that includes the following data, sorting State+County in ascending order:

 

StateCountyState+CountyIndex
ArkansasBradleyArkansas Bradley1
ArkansasCalhounArkansas Calhoun2
ArkansasChicotArkansas Chicot3
ArkansasClarkArkansas Clark4
ArkansasClayArkansas Clay5
ArkansasCraigheadArkansas Craighead6
ArkansasCrossArkansas Cross7
ArkansasDeshaArkansas Desha8
ArkansasGreeneArkansas Greene9
ArkansasHempsteadArkansas Hempstead10
ArkansasIzardArkansas Izard11
ArkansasJeffersonArkansas Jefferson12
ArkansasLeeArkansas Lee13
ArkansasLincolnArkansas Lincoln14
ArkansasMillerArkansas Miller15

 

I want to add a new "Group" column and group them so that the first five (Index 1 - 5) are group "1", second five (Index 6 - 10) are group "2" and so forth, like this:

 

StateCountyState+CountyIndexGroup
ArkansasBradleyArkansas Bradley11
ArkansasCalhounArkansas Calhoun21
ArkansasChicotArkansas Chicot31
ArkansasClarkArkansas Clark41
ArkansasClayArkansas Clay51
ArkansasCraigheadArkansas Craighead62
ArkansasCrossArkansas Cross72
ArkansasDeshaArkansas Desha82
ArkansasGreeneArkansas Greene92
ArkansasHempsteadArkansas Hempstead102
ArkansasIzardArkansas Izard113
ArkansasJeffersonArkansas Jefferson123
ArkansasLeeArkansas Lee133
ArkansasLincolnArkansas Lincoln143
ArkansasMillerArkansas Miller153

 

I tried a few different things but I could not figure out how to get it the way I need it. 

 

Any ideas?

 

Thank you!!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

Fowmy_0-1630427963386.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdHJDsIgEIDhVzFc9SDuHrUmLtGTx8bDxE6FiGAAE/XprQsti7fO3w9CMnlO9hYskg7J1E3aR/XxCe16XMsC7+TQyclMn0EaMFWcaygEvn+72GoSjXUGglXX+bpJvUQzflQ2wK70EytAnwP6C4M/8hHB9zxMnAZ+YghFgL04Sk8oY0L9DeNYLtAw8KULk1guNaJEn9ZlGtsVXq7GRi/2I+3GR9ZP0AF3gSa722BZojYq2J4fabLALQYv/4402d2Wy6MSwb1NoskCd1wI1L6uC622eHgB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Index", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index.1", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index.1", each Number.IntegerDivide(_, 5), Int64.Type}}),
    #"Added to Column" = Table.TransformColumns(#"Integer-Divided Column", {{"Index.1", each _ + 1, type number}})
in
    #"Added to Column"
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@Anonymous 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

Fowmy_0-1630427963386.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdHJDsIgEIDhVzFc9SDuHrUmLtGTx8bDxE6FiGAAE/XprQsti7fO3w9CMnlO9hYskg7J1E3aR/XxCe16XMsC7+TQyclMn0EaMFWcaygEvn+72GoSjXUGglXX+bpJvUQzflQ2wK70EytAnwP6C4M/8hHB9zxMnAZ+YghFgL04Sk8oY0L9DeNYLtAw8KULk1guNaJEn9ZlGtsVXq7GRi/2I+3GR9ZP0AF3gSa722BZojYq2J4fabLALQYv/4402d2Wy6MSwb1NoskCd1wI1L6uC622eHgB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Index", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index.1", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index.1", each Number.IntegerDivide(_, 5), Int64.Type}}),
    #"Added to Column" = Table.TransformColumns(#"Integer-Divided Column", {{"Index.1", each _ + 1, type number}})
in
    #"Added to Column"
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy Excellent, I added the Integer-Divided Column and Added to Column steps and it worked perfectly! Thank you!!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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