Forum Discussion
power query - data cleaning and analysis
- May 15, 2021
i am talking about the fixed width feature as shown belowSergeiBaklan
SergeiBaklan Appreciated, it is really same what i am looking for
Thanks a lot
could you please elaborate little more or could you please suggest some video related to this topic
Thanks once again ..
First we remove the row with date of extraction
and split the rest on the tables having blocks of 15 rows each
Each table in this list is transformed by function, results are combined.
What function do is first renames columns with needed information in the table
, remove all other columns, replace spaces and empty strings on null. Next transform table to columns, in each column remove nulls and combine table back from such columns.
- noushad1ali2000Oct 23, 2024Copper Contributor
Appreciated
mind blowing!
I am quite good in macros and data visualization, but I don't have any hesitations to saying, that I need much more class in advance excel. with data model
Thanks
Naushad Ali
- noushad1ali2000Oct 23, 2024Copper ContributorGreetings,
one more thing, if the sequence of the gap is not uniform, which means currently you are splitting the table in 15 rows. what if the data start after 20 rows or after 10 rows then how can i split table.
* can we search for the end line which having dashes ---- and split on that basis
you know better than me, please advice
Thanks
Naushad Ali- SergeiBaklanOct 25, 2024Diamond Contributor
We may first add Index column, after that custom column value in which is equal to Index if first column starts with "_", otherwise null. Fill that column up to have unique number for each block and group the table but these numbers.
let Source = Csv.Document(File.Contents("C:\Test\Source.csv"),[Delimiter=",", Columns=15, Encoding=65001, QuoteStyle=QuoteStyle.None]), RemoveDate = Table.Skip(Source,1), RenameColumns = Table.RenameColumns( RemoveDate, { {"Column1", "Headers"} , {"Column2", "Code"} , {"Column3", "Grade"} , {"Column5", "ID"} , {"Column9", "Title"} , {"Column13", "Role"} }), names = {"Headers", "ID", "Role", "Grade", "Code", "Title"}, SelectColumns = Table.SelectColumns(RenameColumns,names), AddIndex = Table.AddIndexColumn(SelectColumns, "Index", 1, 1, Int64.Type), AddGroup = Table.AddColumn( AddIndex, "Group", each if Text.StartsWith([Headers], "_") then [Index] else null), FillGroupUp = Table.FillUp(AddGroup,{"Group"}), RemoveExtraRows = Table.SelectRows( FillGroupUp, each ([Group] <> null)), RemoveFirstColumn = Table.RemoveColumns( RemoveExtraRows,{"Headers"}), #"Grouped Rows" = Table.Group( RemoveFirstColumn, {"Group"}, {{"Data", each _}} ), TransformTables = Table.Combine( List.Transform( #"Grouped Rows"[Data], (t) => fnTransformID(t) ) ) in TransformTablesFunction is slightly modifies
(tbl as table) => let RemoveExtra = Table.RemoveColumns(tbl,{"Index", "Group"}), names = Table.ColumnNames(RemoveExtra), ReplaceSpace = Table.ReplaceValue(RemoveExtra," ",null,Replacer.ReplaceValue,names), ReplaceEmpty = Table.ReplaceValue(ReplaceSpace,"",null,Replacer.ReplaceValue,names), ReplaceRoleWord = Table.ReplaceValue(ReplaceEmpty,"role",null,Replacer.ReplaceValue,{"Title"}), ToColumns = Table.ToColumns( ReplaceRoleWord ), RemoveNulls = List.Transform( ToColumns, (q) => List.RemoveNulls(q)), GetTable = Table.FromColumns( RemoveNulls, names ) in GetTable