Forum Discussion
Anonymous
1 year agoNot applicable
Create row sequence based on row id column but retaining other column
Hi, I really need help with row sequencing based on a column (row_id) while retaining another column called 'split_desc'. There are two columns in the table - 'row_id' and 'split_desc' and they ...
- 1 year ago
Hi Anonymous. Here's a solution you could take a look at! Thanks
Akash_Varuna
Super User
1 year agoHi Anonymous , After the index did you expand it Could you try this please
Sort the Data:
- Sort the table first by the Row_Id column in ascending order, then by Split_Desc in ascending order. This ensures a proper order for generating the sequence.
Group the Data:
- Group the data by Row_Id:
- Go to Transform → Group By.
- Group by Row_Id.
- Create an All Rows operation to retain the grouped table.
- Group the data by Row_Id:
Add an Index for Sequencing:
- Within each group, add an index to generate the Row_Sequence:
- After grouping, click the small table icon for the grouped column.
- Add an Index Column starting from 1.
- Rename this index column as Row_Sequence.
- Within each group, add an index to generate the Row_Sequence:
Expand the Table:
- After adding the index, expand the grouped table to flatten it back into a single table:
- Click on the expand icon next to the grouped column.
- Include all original columns and the newly created Row_Sequence column.
- After adding the index, expand the grouped table to flatten it back into a single table:
let
Source = Table.FromRows(
{
//Data
},
{"Row_Id", "Split_Desc"}
),
// Convert data types
ChangeTypes = Table.TransformColumnTypes(Source, {{"Row_Id", Int64.Type}, {"Split_Desc", Text.Type}}),
// Sort by Row_Id and Split_Desc
SortedTable = Table.Sort(ChangeTypes, {{"Row_Id", Order.Ascending}, {"Split_Desc", Order.Ascending}}),
// Group by Row_Id
GroupedTable = Table.Group(
SortedTable,
{"Row_Id"},
{
{"AllData", each Table.AddIndexColumn(_, "Row_Sequence", 1, 1, Int64.Type)}
}
),
// Expand grouped data
ExpandedTable = Table.ExpandTableColumn(GroupedTable, "AllData", {"Row_Id", "Split_Desc", "Row_Sequence"})
in
ExpandedTable
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance