Forum Discussion
Create a Column which labels table rows as Section 1, Section 2, 3, 4 according to number of rows
- 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"}))
when you get 100 rows, that can be divisible by 4, then you got 4 sections, each section has 25 rows.
when you get 101 rows, it is preferred to ensure the first section has the mose rows, then you got 4 sections too, but the first three sections with 26 rows and the last section with only 23 rows.
that's the logic of my code.
Thanks Daniel - that makes sense.
However before the Section Step, there are 1445 rows, and when Section Step is applied, there are 1444 steps. So one row is dropped. I thought that was due to a rounding in the code.
BTW Section 1 = 361
Section 2 = 361
Section 3 = 361
Section 4 = 361
All sections have same qty of rows, there does not seem to be any "offset".
Let me know what you think - thanks
- wdx223_Daniel2 years agoCommunity Champion
i used Number.RoundUp, so each section should be 362, instead of 361
then first three sections will have 362 rows, and the last has 359 rows
- Linnil2 years agoHelper III
I see - thanks Daniel.
In my actual table that does not happen. One row has disappeared and all sections have 361.
So the code is not working correctly in real-life scenario. Is there anything else I can try?
Thanks - wdx223_Daniel2 years agoCommunity Champion
the code will not change the row number of your data, it just add a new column
Table.ToColumns(YourData)&{NewColumn}, this will not delete any rows.
try to check, is there some steps filter out something.
- Linnil2 years agoHelper III
Hi Daniel
OK - yes - it is all working perfectly! Thanks for your patience and thanks for such a great solution.
All the bestLinnil