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"}))
NewStep=let a=Table.RowCount(PreviousStepName) in Table.FromColumns(Table.ToRows(PreviousStepName)&{List.Transform({0..a-1},each "Section "&Text.From(Number.IntegerDivide(_,Number.RoundUp(a/4))+1))},Table.ColumnNames(PreviousStepName)&{"Section"})
Hi Daniel - thanks so much. This is on the right track. I've changed variable a to AAA so I could understand the script better.
When I created the custom column with this Let statement, I got this error:
Expression.Error: The count of 'columns' (1445) doesn't match that of 'columnNames' (11).
Details:
[List]
So the number of rows is correct (1445).
And my table (with the new column we just created for Sections) has 11 columns.
Can you help me solve this mismatch?
Thanks 🙂
- wdx223_Daniel2 years agoCommunity Champion
Could you show your code?
- Linnil2 years agoHelper III
= Table.AddColumn(#"Added Index", "Sections", each let
AAA=Table.RowCount(#"Added Index")
in Table.FromColumns(Table.ToRows(#"Added Index")&{List.Transform({0..AAA-1},each "Section "&Text.From(Number.IntegerDivide(_,Number.RoundUp(AAA/4))+1))},Table.ColumnNames(#"Added Index")&{"Section"}))
My previous step was Added Index.
Thanks- wdx223_Daniel2 years agoCommunity Champion
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"}))