Search code examples
powerbipowerquery

How do I append a column from one dataframe to another dataframe in power query?


How do I append a column from one dataframe to another dataframe in power query?

  • note

    • The num of rows are the same.
  • note

    • (I cannot do this in Python, as that will cause the lose of binary files.)
    • (why I do such following ex -- this is just a dummy example)
    • (I dont have any id as join column)
    • (when I tried to convert that to a List then append, the same happens...)
  • ambiguity

    • for append a column, I mean merge/join in power query terminology. (see eg below)

eg:

  • given

    | Content              | Name           | Extension  | Date accessed       | Date modified       | Date created        | Attributes | Folder Path                                                              |
    |----------------------|----------------|------------|---------------------|---------------------|---------------------|------------|--------------------------------------------------------------------------|
    | Binary.FromText(...) | .gitignore     | .gitignore | 2023/12/12 21:14:57 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  |
    | Binary.FromText(...) | 01-01-2021.csv | .csv       | 2023/12/12 22:16:12 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  |
    | Binary.FromText(...) | 01-01-2022.csv | .csv       | 2023/12/12 22:19:20 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  |
    | Binary.FromText(...) | 01-01-2023.csv | .csv       | 2023/12/12 22:19:20 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  |
    
  • expected

    | Content              | Name           | Extension  | Date accessed       | Date modified       | Date created        | Attributes | Folder Path                                                              | filterout     |
    |----------------------|----------------|------------|---------------------|---------------------|---------------------|------------|--------------------------------------------------------------------------|---------------|
    | Binary.FromText(...) | .gitignore     | .gitignore | 2023/12/12 21:14:57 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  | AppendedData1 |
    | Binary.FromText(...) | 01-01-2021.csv | .csv       | 2023/12/12 22:16:12 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  | AppendedData1 |
    | Binary.FromText(...) | 01-01-2022.csv | .csv       | 2023/12/12 22:19:20 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  | AppendedData1 |
    | Binary.FromText(...) | 01-01-2023.csv | .csv       | 2023/12/12 22:19:20 | 2023/12/12 15:24:49 | 2023/12/12 15:24:49 | [Record]   | G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports\  | AppendedData1 |
    
  • attempt fail

    let
        Source = Folder.Files("G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports"),
        Source2 = Folder.Files("G:\wsp\dataset\COVID-19\csse_covid_19_data\csse_covid_19_daily_reports"),
        // #"appendedTable" = Table.AddColumn(Source, "filterout", each [Name]) // now "filterout" each contains a String of name << correct
        #"appendedTable" = Table.AddColumn(Source, "filterout", each Source2[Name]) //  now "filterout" each contains a List of names << wrong
    in
        appendedTable
    
    • (I dont understand why after the append, each row contains a List?
      #"appendedTable" = Table.AddColumn(Source, "filterout", each Source2[Name]) // now "filterout" each contains a List of names << wrong)

Solution

  • To append column Name from table Source2 to Source

     Append = Table.FromColumns ( Table.ToColumns(Source) & {Source2[Name]},Table.ColumnNames(Source)&{"Name"} )