Forum Discussion
Linnil
2 years agoHelper III
Create a Column which labels table rows as Section 1, Section 2, 3, 4 according to number of rows
Hi - I have a table with a variable amount of rows. Whenever the data is refreshed (once a week) it changes. I would like to count all the rows and then divide those rows into 4 sections, more of ...
- 2 years ago
please use my code as a new step, instead of puting it in the add column function.
click the "fx" label beside the formula edit bar, then copy code into formula area
=let
AAA=Table.RowCount(#"Added Index")
in Table.FromColumns(Table.ToColumns(#"Added Index")&{List.Transform({0..AAA-1},each "Section "&Text.From(Number.IntegerDivide(_,Number.RoundUp(AAA/4))+1))},Table.ColumnNames(#"Added Index")&{"Section"}))
BA_Pete
2 years agoSuper User
Hi Linnil,
You can try using the following in a custom step:
Table.Split(PreviousStepName, Number.RoundUp(Table.RowCount(PreviousStepName) / 4))
This will split your table into four tables - not perfectly evenly, but it's fast and simple.
Pete
Linnil
2 years agoHelper III
Thanks Pete - I ran a few scenarios trying this out before coming to the Community. Not quite what I need but thanks for your suggestion. Very kind of you to respond.