Hi,
I'm working on a query that splits a table into multiple tables based on column one contents where I have managed to create a table of tables.
It's here where I'm stuck because the number of rows in the table of tables can vary, how to execute the next set of steps that will be dynamic enough to split the tables from the table of tables to create separate tables in power query?
The above query has generated 15 tables that I'm expanding by manually duplicating the main query and double-clicking each table individually.
I'm working on a query that splits a table into multiple tables based on column one contents where I have managed to create a table of tables.
Power Query:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Scheme or Stock name", type text}, {"Investment date", type date}, {"Investment price", Currency.Type}, {"Units", type number}, {"Investment amount", Currency.Type}, {"Current price", Currency.Type}, {"Current market value", Currency.Type}, {"Gain", Currency.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Scheme or Stock name", Order.Ascending}, {"Investment date", Order.Ascending}}),
// Add an index column to keep track of row order
Add_Index = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
// Add a column to shift the desired column's values by one row to compare with the current row
Add_Previous = Table.AddColumn(Add_Index, "PreviousContent", each try if [Index] = 1 then null else Add_Index{[Index]-2} [Scheme or Stock name] otherwise null),
// Add a column to flag changes in the column content
Add_ChangeFlag = Table.AddColumn(Add_Previous, "ChangeFlag", each if [Scheme or Stock name] <> [PreviousContent] then 1 else 0),
// Add a column to create group identifiers by using a cumulative sum of the change flags
Add_Group = Table.AddColumn(Add_ChangeFlag, "Group", each List.Sum(List.FirstN(Add_ChangeFlag[ChangeFlag], [Index]))),
// Group the data by the group identifier
GroupedTables = Table.Group(Add_Group, "Group", {{"AllData", each Table.RemoveColumns(_, {"PreviousContent", "ChangeFlag", "Group", "Index"}), type table [Content=nullable text]}}),
#"Changed Type1" = Table.TransformColumnTypes(GroupedTables,{{"Group", Int64.Type}})
in
#"Changed Type1"
It's here where I'm stuck because the number of rows in the table of tables can vary, how to execute the next set of steps that will be dynamic enough to split the tables from the table of tables to create separate tables in power query?
The above query has generated 15 tables that I'm expanding by manually duplicating the main query and double-clicking each table individually.