Forum Discussion
JollyRoger01
5 years agoHelper III
How to split a CSV file into tables based on blank rows
I have a CSV file that has multiple tables in that are seperated vertically. I want to know how to import these into tables (preferrably in 1 or 2 steps) based on a blank (or multiple blank) row/s. ...
- Anonymous5 years ago
Hi JollyRoger01
I missed that multiple tables...you need to group the rows into different tables, another way of increasing index, you can take from here
let Source = Csv.Document(File.Contents("C:\Users\----\Book1.csv"),[Delimiter=",", Encoding=1252, QuoteStyle=QuoteStyle.None]), checkBlank = Table.CombineColumns(Source, Table.ColumnNames(Source), (x)=> if List.MatchesAll(x,each _ = "") then 1 else 0,"check"), #"Added Index" = Table.AddIndexColumn(checkBlank, "Index", 0, 1, Int64.Type), #"Added Custom" = Table.AddColumn(#"Added Index", "Group", each if [Index]=0 then 0 else if [check] = 0 then List.Sum(List.FirstN( checkBlank[check], [Index])) else -1), SouceIndex = Table.AddIndexColumn(Source, "Index", 0,1), #"Merged Queries" = Table.NestedJoin(SouceIndex, {"Index"}, #"Added Custom", {"Index"}, "Group", JoinKind.LeftOuter), #"Expanded Group" = Table.ExpandTableColumn(#"Merged Queries", "Group", {"check", "Group"}, {"check", "Group"}), #"Filtered Rows" = Table.SelectRows(#"Expanded Group", each ([check] = 0)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "check"}), #"Grouped Rows" = Table.Group(#"Removed Columns", {"Group"}, {{"allrows", each _, type table }}) in #"Grouped Rows"
mahoneypat
5 years agoMicrosoft Employee
Your two resulting tables are very similar (date headers with 1+ rows of category values). It would probably be better to unpivot and append them to result in one table. That will likely make your visualization/analysis easier. Would that work? If so, the community could suggest a specific query solution given your data.
Pat
JollyRoger01
5 years agoHelper III
I see what you mean, though unfortunately the info is unrelated and I need them all in seperate tables.