Power query append 3 workbooks and keep manual comments
I had used the code here https://www.reddit.com/r/excel/comments/ek1e4u/table_updates_via_power_query_whilst_retaining/ for a query that pulls from two workbooks and it works fine. However, when I introduce a third workbook, it breaks. New data added to the third workbook is somehow considered from the second workbook and it just duplicates the last row of second workbook.
When I flip the append query by putting the third query first then the second, it works in capturing the new data. However, this causes the manual comments I entered to disappear.
I am using an index column as a key and that's why this is happening. How can I fix this? I am thinking I would need to key by using index+workbook?
Q1
let Source = q4 in Source Q2
let Source = Excel.CurrentWorkbook(){[Name="data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Name", type text}, {"date", type datetime}, {"description", type text}, {"category", type text}, {"amount", Int64.Type}}) in #"Changed Type" Q3
let Source = Folder.Files("C:\Documents\testing"), #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "ytd w1.xlsx" or [Name] = "ytd w2.xlsx" or [Name] = "ytd w3.xlsx")), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path"}), #"Filtered Hidden Files1" = Table.SelectRows(#"Removed Columns", each [Attributes]?[Hidden]? <> true), #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])), #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function1",{"Name", "Transform File"}), #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))), #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"date", type date}, {"description", type text}, {"category", type text}, {"amount", Int64.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type), #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "Name", "date", "description", "category", "amount"}) in #"Reordered Columns" Q4
let Source = Table.Combine({q2, q3}), #"Removed Duplicates" = Table.Distinct(Source, {"Index"}) in #"Removed Duplicates" [link] [comments]
Want to read more?
Check out the full article on the original site