Splitting Table into multiple tables

jajatidev

Board Regular
Joined
Jul 29, 2016
Messages
75
Office Version
  1. 365
Platform
  1. Windows
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.

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.

1716665484481.png
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,499
Messages
6,131,012
Members
449,613
Latest member
MedDash99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top