Forum Discussion
Multiple table formats in a single text source file
- 8 years ago
Here is a simple example of splitting types
Load the file ensure the widest no columns are imported
Basically add a conditional column to identify the first row of each type.
use fill down to set all the rows between types to the header type.
Then create references for each type and filter by the type column,
From here you can shape each type of date
Here is the advance editor code.
let Source = Csv.Document(File.Contents("L:\Downloads\Sample_data_multple_types.csv"),[Delimiter=",", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]), #"Added Conditional Column" = Table.AddColumn(Source, "RowType", each if [Column1] = "Row type 1" then "Type1" else if [Column1] = "Row type 2" then "Type2" else if [Column1] = "Row type 3" then "Type3" else null), #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"RowType"}) in #"Filled Down"Type 1 code
let Source = Sample_data_multple_types, #"Filtered Rows" = Table.SelectRows(Source, each ([RowType] = "Type1")), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11"}) in #"Removed Columns"
Here is a simple example of splitting types
Load the file ensure the widest no columns are imported
Basically add a conditional column to identify the first row of each type.
use fill down to set all the rows between types to the header type.
Then create references for each type and filter by the type column,
From here you can shape each type of date
Here is the advance editor code.
let
Source = Csv.Document(File.Contents("L:\Downloads\Sample_data_multple_types.csv"),[Delimiter=",", Columns=11, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Added Conditional Column" = Table.AddColumn(Source, "RowType", each if [Column1] = "Row type 1" then "Type1" else if [Column1] = "Row type 2" then "Type2" else if [Column1] = "Row type 3" then "Type3" else null),
#"Filled Down" = Table.FillDown(#"Added Conditional Column",{"RowType"})
in
#"Filled Down"
Type 1 code
let
Source = Sample_data_multple_types,
#"Filtered Rows" = Table.SelectRows(Source, each ([RowType] = "Type1")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11"})
in
#"Removed Columns"