Excel - Power Query Import And Clean Fixed Width Text Files - Episode 2539

Поділитися
Вставка
  • Опубліковано 12 вер 2024

КОМЕНТАРІ • 30

  • @vlookup_tim
    @vlookup_tim Рік тому +2

    30 years ago I was the guy spending that hour on a payroll text file in excel every month to reconcile the bank account at university. Now I’m using Power Query to cleanse a csv file from the bank in seconds for a small municipality. Progress!

    • @MrXL
      @MrXL  Рік тому +1

      That is awesome. What is too bad is the lack of knowledge that Power Query exists. Once I can show people they will see the light.

  • @ricos1497
    @ricos1497 Рік тому +4

    You can sort of do it in Power Query. Right click and select Duplicate on the name column and call the new column "Names" (just change in the formula bar). Then add another step in the applied steps window, and use:
    =Table.Combine({#"Duplicated Column", Table.FromList(List.Distinct(#"Duplicated Column"[#"Names"]), null, {"Names"})})
    This step (and you can separate into a few if easier) takes a distinct list of all the names in the duplicated column and converts to a table, which is then combined with the original data, giving you a list of null lines with only the duplicate name field populated.
    You can then sort this by your name column, but first you have to replace values again in the actual column that you wish to sort by, replacing null with "" (replace null in all other columns created by the combined tables too). Then sort by duplicated name column and then delete the duplicated name column and you're left with the data with spaces.
    Obviously, the correct answer is that spaces are for satan.

    • @ricos1497
      @ricos1497 Рік тому +2

      Or a function might be better. Copy this into a blank query and you can call it from your own query. Pass the table (previous step name), the column name you want to create a blank row under and the column that you next want to sort by after your column name. Should work nicely (edited from first post because it didn't work nicely!):
      (sourceTable as table, columnName as text, nextSortColumnName as text) as table =>
      let
      Source = Table.DuplicateColumn(sourceTable, columnName, columnName & "_"),
      columnNames = List.RemoveMatchingItems(Table.ColumnNames(Source),{columnName & "_"}),
      distinctRowsAsTable = Table.FromList(List.Distinct(Table.Column(Source,columnName & "_")),null,{columnName & "_"}),
      newTable = List.Accumulate(columnNames, distinctRowsAsTable, (state, current) => Table.AddColumn(state, current, each "")),
      sortedData = Table.Sort(Table.Combine({Source,newTable}),{columnName & "_",nextSortColumnName}),
      result = Table.RemoveColumns(sortedData, {columnName & "_"})
      in
      result

  • @toanh249
    @toanh249 Рік тому +1

    Before watching this video, I had a lot of trouble with reports like this, and didn't know how to use it with power query to automate it, many thanks Mr Excel

    • @myresearchonmicroornithopt4423
      @myresearchonmicroornithopt4423 7 місяців тому

      Even with this solution, we can't automate it. Because If we get the data with any different positions, It fails. Did you find any different way for that?

  • @jessicadawson9708
    @jessicadawson9708 4 місяці тому

    You just made my life so much easier. Thank you!!!!

  • @chrism9037
    @chrism9037 Рік тому

    Thanks Mr Excel! Power Query continues to amaze me with all its capabilities

    • @ExcelInstructor
      @ExcelInstructor Рік тому

      yeah, and this is one of the most basic barly automated solution with a lot of manual inputs.
      Imagine what is possible when all is automated!

  • @Milhouse77BS
    @Milhouse77BS 6 місяців тому

    Thanks! Thanks, hard to believe that Power Query can't figure out the fixed-width delimiters.

  • @ronlo8498
    @ronlo8498 Рік тому

    Thank you, this is great! I have been trying to solve this for over five years!

  • @canirmalchoudhary8173
    @canirmalchoudhary8173 Рік тому +2

    Fill down with null values is cool feature

    • @MrXL
      @MrXL  Рік тому

      Right! Easier that Home, Find & Select, Go To Special, Blanks, OK, = UpArrow Ctrl+Enter!

  • @sandravukovic2901
    @sandravukovic2901 Місяць тому

    Very cool! Thank you!! Working with the same kind of csv file, is there a way do delete all rows after a cell with a specific text value? The text may appear in several rows, but I'd like to delete everything after the first instance.

  • @walkedspoon
    @walkedspoon Рік тому

    I LOVE YOU, thank you

  • @nadermounir8228
    @nadermounir8228 Рік тому

    Thank you Mr Excel for this amazing video. 👏

  • @Hyperion9997
    @Hyperion9997 8 місяців тому

    Hahaha this looks like the output from out 'new' system. I just spent an hour making a 'companion' table to the data using offsets and =MID only to find there's a secondary row "sometimes" that has important data as they have offset rows of data.
    I'm going to use these tips to import the sheet two ways, one for the main row, one for the offset rows, then recombine them I think..... Thanks MrExcel!

  • @danielmpinga4102
    @danielmpinga4102 5 місяців тому

    Thank you this worked out ...

  • @zuhairalmutawa9941
    @zuhairalmutawa9941 Рік тому

    That is amazing. thank you for the new information.

  • @BillSzysz1
    @BillSzysz1 Рік тому +2

    Empty row after each Name? No problem😁
    WithEmptyRow = Table.Combine(Table.Group( MrExcelLastStep, {"Name"}, {{"tbl", each _ & #table({"Name"}, {{null}}), type table}})[tbl])
    in
    WithEmptyRow

  • @djl8710
    @djl8710 Рік тому

    Excellent Thanks!!!! 🤩

  • @johnborg5419
    @johnborg5419 Рік тому

    Thanks Mr Excel!!! :)

  • @kebincui
    @kebincui Рік тому

    Amazing ❤

  • @myresearchonmicroornithopt4423
    @myresearchonmicroornithopt4423 7 місяців тому

    Hey, Thanks for the Video, It was very helpful. But I couldn't automate the report with this solution, As I am getting different position of column every day, Any idea for that??

    • @MrXL
      @MrXL  7 місяців тому +1

      I do not. But Ken Puls might have a solution. Google him.

  • @aaleyr1
    @aaleyr1 Рік тому

    This was amazing . But my file has headers spread into 2 rows and data is 2 rows seperated by a blank row . it runs into many pages . how to clean it ?

  • @ExcelInstructor
    @ExcelInstructor Рік тому +1

    Can I have this file?
    I would love to play around with it in PQ

    • @MrXL
      @MrXL  Рік тому

      Yes. Just went to your About tab but no email there. Send an email to me (it’s on the About tab) and I will send you the txt file.

  • @GeertDelmulle
    @GeertDelmulle Рік тому

    Hey Mr.Excel,
    You can insert the blank row in Power Query quite easily:
    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    DuplicateName = Table.DuplicateColumn(Source, "Name", "Name2"),
    Combine = Table.Combine({DuplicateName,Table.Distinct(DuplicateName[[Name2]])}),
    SortRows = Table.Sort(Combine,{{"Name2", Order.Ascending}, {"Value", Order.Ascending}}),
    RemoveColumnRow = Table.Skip(Table.RemoveColumns(SortRows,{"Name2"}),1)
    in
    RemoveColumnRow