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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Sam7
Advocate II
Advocate II

Number Rows by Group and Order

Hi

I Power Query, how do I number each row of data, so each group is the same number, but I only want the numbering to go upto 5 then start again?

Sam7_0-1697632696857.png

Cheers

2 REPLIES 2
Ahmedx
Super User
Super User

pls try this code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqqqqUorVwaQdnZzBtKtnMArt7OiCQoe4QtR5OTphpT0cwZRvgD8KHRmETHn6OAKVxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Group = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Count", each _, type table [Group=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Calculated Modulo" = Table.TransformColumns(#"Added Index", {{"Index", each if  Number.Mod(_, 5)=0 then 5 else Number.Mod(_, 5) , type number}}),
    #"Removed Columns" = Table.RemoveColumns(#"Calculated Modulo",{"Group"}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Removed Columns", "Count", {"Group"}, {"Group"})
in
    #"Expanded Count"
lbendlin
Super User
Super User

Use GroupKind.Local and Modulus.

 

If you like more help please provide the sample data in a usable format, not as a screenshot.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

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.