Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Original Post: https://un.reddit.com/r/excel/comments/7uzldp/looking_for_a_way_to_organise_files/
- Created By: Alex Powers
- Website: http://www.itsnotaboutthecell.com
- Contact: [email protected]
- Reddit: /u/itsnotaboutthecell
- Edits: /u/tirlibibi17
- */
- let
- Source = Csv.Document(File.Contents("C:\Users\xxxxx\Desktop\ocldb1517674051.29276.OSD.csv"),[Delimiter=",", Columns=7, Encoding=1252, QuoteStyle=QuoteStyle.None]),
- #"Trim All Text" = Table.TransformColumns(Source,{{"Column1", Text.Trim, type text}, {"Column2", Text.Trim, type text}, {"Column3", Text.Trim, type text}, {"Column4", Text.Trim, type text}, {"Column5", Text.Trim, type text}, {"Column6", Text.Trim, type text}, {"Column7", Text.Trim, type text}}),
- #"Filter: ""#-----..."" and ""END OF VARIABLES SECTION""" = Table.SelectRows(#"Trim All Text", each [Column1] <> "#--------------------------------------------------------------------------------" and [Column1] <> "END OF VARIABLES SECTION"),
- #"Grouped Rows" = Table.Group(#"Filter: ""#-----..."" and ""END OF VARIABLES SECTION""", {"Column1"}, {{"Count", each _, type table}}),
- #"Table To List" = Table.AddColumn(#"Grouped Rows", "Values", each Table.ToList([Count])),
- #"Remove Table Column" = Table.RemoveColumns(#"Table To List",{"Count"}),
- #"Extract List Values" = Table.TransformColumns(#"Remove Table Column", {"Values", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
- #"Split: "",""" = Table.SplitColumn(#"Extract List Values", "Values", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)),
- #"Transposed Table" = Table.Transpose(#"Split: "","""),
- #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
- #"Filter: Remove Header Labels" = Table.SelectRows(#"Promoted Headers", each ([CAST] <> "" and [CAST] <> "CAST" and [CAST] <> "WOD Unique Cast Number")),
- #"Replace: ""."" with (blank)" = Table.ReplaceValue(#"Filter: Remove Header Labels",".","",Replacer.ReplaceText,{"Accession Number", "Platform", "Bottom depth", "Database origin", "Institute", "High resolution CTD - Bottle"}),
- #"Removed Other Columns" = Table.SelectColumns(#"Replace: ""."" with (blank)",{"Year", "Month", "Day", "Latitude", "Longitude", "VARIABLES", "1", "2", "3", "4", "5", "6", "7", "8"}),
- #"Replace: (blank) with null" = Table.ReplaceValue(#"Removed Other Columns","",null,Replacer.ReplaceValue,{"Year", "Month", "Day", "Latitude", "Longitude", "VARIABLES", "1", "2", "3", "4", "5", "6", "7", "8"}),
- #"Filled Down" = Table.FillDown(#"Replace: (blank) with null",{"Year", "Month", "Day", "Latitude", "Longitude"}),
- #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([VARIABLES] = "pH")),
- #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Year", "Month", "Day", "Latitude", "Longitude", "VARIABLES"}, "Meters", "Value"),
- #"Filter: Top 1 Meter" = Table.SelectRows(#"Unpivoted Other Columns", each ([Meters] = "1")),
- #"Changed Types" = Table.TransformColumnTypes(#"Filter: Top 1 Meter",{{"Year", Int32.Type}, {"Month", Int8.Type}, {"Day", Int8.Type}, {"Latitude", type number}, {"Longitude", type number}, {"VARIABLES", type text}, {"Meters", Int64.Type}, {"Value", type number}}, "en-us"),
- #"Custom: Date(Year, Month, Day)" = Table.AddColumn(#"Changed Types", "Date", each #date([Year],[Month],[Day])),
- #"Removed Original Date Columns" = Table.SelectColumns(#"Custom: Date(Year, Month, Day)",{"Date", "Latitude", "Longitude", "VARIABLES", "Meters", "Value"}),
- #"Type: Date" = Table.TransformColumnTypes(#"Removed Original Date Columns",{{"Date", type date}}, "en-us")
- in
- #"Type: Date"
Add Comment
Please, Sign In to add comment