SOLVED

Combine power query output table with manually maintained column in one excel table

%3CLINGO-SUB%20id%3D%22lingo-sub-2084389%22%20slang%3D%22en-US%22%3ECombine%20power%20query%20output%20table%20with%20manually%20maintained%20column%20in%20one%20excel%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2084389%22%20slang%3D%22en-US%22%3E%3CP%3EI%20transform%20and%20load%20a%20CSV%20file%20into%20an%20excel%20sheet%20using%20Power%20Query%3A%3C%2FP%3E%3CTABLE%20width%3D%22377px%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22120.683px%22%3E%3CP%3E%3CSTRONG%3EColumn1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.667px%22%3E%3CP%3E%3CSTRONG%3EColumn2.1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.65px%22%3E%3CP%3E%3CSTRONG%3EColumn2.2%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22120.683px%22%3E%3CP%3E01.01.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.667px%22%3E%3CP%3EA%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.65px%22%3E%3CP%3EBC%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22120.683px%22%3E%3CP%3E01.02.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.667px%22%3E%3CP%3EM%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.65px%22%3E%3CP%3ENO%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22120.683px%22%3E%3CP%3E01.03.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.667px%22%3E%3CP%3EX%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22127.65px%22%3E%3CP%3EYZ%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3ECustomer%20wants%20to%20maintain%20next%20column%20of%20this%20table%20(%22My%20Col%22)%20manually%3A%3C%2FP%3E%3CTABLE%20width%3D%22378%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2279%22%3E%3CP%3E%3CSTRONG%3EColumn1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3E%3CSTRONG%3EColumn2.1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3E%3CSTRONG%3EColumn2.2%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22120%22%3E%3CP%3E%3CSTRONG%3EMy%20col%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2279%22%3E%3CP%3E01.01.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3E%3CSTRONG%3EA%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3EBC%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22120%22%3E%3CP%3E%3CSTRONG%3EA%3C%2FSTRONG%3E%20is%20first%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2279%22%3E%3CP%3E01.02.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3E%3CSTRONG%3EM%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3ENO%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22120%22%3E%3CP%3E%3CSTRONG%3EM%3C%2FSTRONG%3E%20is%20second%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2279%22%3E%3CP%3E01.03.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3E%3CSTRONG%3EX%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2289%22%3E%3CP%3EYZ%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22120%22%3E%3CP%3E%3CSTRONG%3EX%3C%2FSTRONG%3E%20is%20last%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3ESo%20far%20so%20good.%20The%20problem%20is%20that%20the%20next%20day%2C%20the%20CSV%20file%20can%20come%20in%20different%20order%20of%20records.%20And%20after%20Data-Update%20all%2C%20the%20table%20is%20updated%20in%20the%20this%20new%20order%2C%20but%20the%20manual%20column%20remains%20in%20the%20original%20order.%20Then%20we%20have%20data%20mismatch%3A%3C%2FP%3E%3CTABLE%20width%3D%22404px%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2287px%22%3E%3CP%3E%3CSTRONG%3EColumn1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3E%3CSTRONG%3EColumn2.1%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3E%3CSTRONG%3EColumn2.2%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22131.867px%22%3E%3CP%3E%3CSTRONG%3EMy%20col%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2287px%22%3E%3CP%3E01.02.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3E%3CSTRONG%3EM%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3ENO%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22131.867px%22%3E%3CP%3E%3CSTRONG%3EA%3C%2FSTRONG%3E%20is%20first%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2287px%22%3E%3CP%3E01.03.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3E%3CSTRONG%3EX%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3EYZ%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22131.867px%22%3E%3CP%3E%3CSTRONG%3EM%3C%2FSTRONG%3E%20is%20second%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2287px%22%3E%3CP%3E01.01.2021%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3E%3CSTRONG%3EA%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2292.0667px%22%3E%3CP%3EBC%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22131.867px%22%3E%3CP%3E%3CSTRONG%3EX%3C%2FSTRONG%3E%20is%20last%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3EWhat%20is%20the%20correct%20process%20of%20combining%20power%20query%20table%20columns%20with%20manually%20maintained%20columns%3F%3CBR%20%2F%3EThank%20You!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2084389%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2086128%22%20slang%3D%22en-US%22%3ERe%3A%20Combine%20power%20query%20output%20table%20with%20manually%20maintained%20column%20in%20one%20excel%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2086128%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F295513%22%20target%3D%22_blank%22%3E%40Zdenek_CK%3C%2FA%3E%26nbsp%3BNot%20too%20long%20ago%2C%20similar%20questions%20came%20up%20on%20this%20forum.%20Both%20were%20responded%20to%20by%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThought%20the%20technique%20to%20do%20this%20would%20come%20in%20handy%20but%20didn't%20think%20it%20was%20very%20straight-forward.%20So%2C%20I%20created%20some%20kind%20of%20tutorial%20for%20%3CU%3Emyself%3C%2FU%3E%2C%20writing%20the%20process%20down%20step-by-step.%20And%20it%20includes%20a%20working%2C%20tough%20very%20simple%2C%20example.%20See%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2088757%22%20slang%3D%22en-US%22%3ERe%3A%20Combine%20power%20query%20output%20table%20with%20manually%20maintained%20column%20in%20one%20excel%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2088757%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%2C%20I%20modified%20a%20bit%2C%20hope%20self-explainable%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powerquery%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22Source%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20Source3%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22Source3%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20SourceColumns%20%20%20%3D%20Table.ColumnNames(Source)%2C%0A%20%20%20%20SourceColumns3%20%20%3D%20Table.ColumnNames(Source3)%2C%0A%20%20%20%20FirstTime%20%3D%20List.ContainsAll(SourceColumns%2C%20SourceColumns3)%2C%0A%20%20%20%20Return%20%3D%20if%20FirstTime%20then%20Source%20else%0A%20%20%20%20%20%20%20%20Table.Join(%0A%20%20%20%20%20%20%20%20%20%20%20%20Source%2C%20%20SourceColumns%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20Source3%2C%20SourceColumns%0A%20%20%20%20%20%20%20%20)%0Ain%0A%20%20%20%20Return%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20table%20in%20your%20file.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I transform and load a CSV file into an excel sheet using Power Query:

Column1

Column2.1

Column2.2

01.01.2021

A

BC

01.02.2021

M

NO

01.03.2021

X

YZ

Customer wants to maintain next column of this table ("My Col") manually:

Column1

Column2.1

Column2.2

My col

01.01.2021

A

BC

A is first

01.02.2021

M

NO

M is second

01.03.2021

X

YZ

X is last

So far so good. The problem is that the next day, the CSV file can come in different order of records. And after Data-Update all, the table is updated in the this new order, but the manual column remains in the original order. Then we have data mismatch:

Column1

Column2.1

Column2.2

My col

01.02.2021

M

NO

A is first

01.03.2021

X

YZ

M is second

01.01.2021

A

BC

X is last

What is the correct process of combining power query table columns with manually maintained columns?
Thank You!

9 Replies
best response confirmed by Zdenek_Moravec (Contributor)
Solution

@Zdenek_Moravec Not too long ago, similar questions came up on this forum. Both were responded to by 

@Sergei Baklan 

 

Thought the technique to do this would come in handy but didn't think it was very straight-forward. So, I created some kind of tutorial for myself, writing the process down step-by-step. And it includes a working, tough very simple, example. See attached.

 

@Riny_van_Eekelen , I modified a bit, hope self-explainable

 

let
    Source  = Excel.CurrentWorkbook(){[Name="Source"]}[Content],
    Source3 = Excel.CurrentWorkbook(){[Name="Source3"]}[Content],
    SourceColumns   = Table.ColumnNames(Source),
    SourceColumns3  = Table.ColumnNames(Source3),
    FirstTime = List.ContainsAll(SourceColumns, SourceColumns3),
    Return = if FirstTime then Source else
        Table.Join(
            Source,  SourceColumns,
            Source3, SourceColumns
        )
in
    Return

 

Another table in your file.

Hello @Riny_van_Eekelen and @Sergei Baklan 

Your solutions are already an Excel University, but it is understandable and it really works

Thank You very much!

Zdenek Moravec

Cesky Krumlov, Czech Republic

@Riny_van_Eekelen 

I am a bit of novice but am able to follow. In your example, both sources are existing tables. Is it possible to replicate this if the original source is a file in a folder? 

@TdotnotbotThis relates to a rather old post and I believe it relates to connecting to one source and then adding information to it manually, and keep it synchronised with the original source data. It doesn't really matter where the original file sits. What exactly are you looking at?

@Riny_van_Eekelen 

Below is a sample of the code following what I believe to be step-for-step as per instructions. When files are added and refreshed to the source folder, the manually updated rows remain in the same position in the workbook. Thank you for any help you might offer. This is driving me insane.

 

PQCodeComplianceReport.jpg

@Tdotnotbot Difficult to diagnose without having a close look at the file. First, make sure that the added column is in fact part of the table you connect to in Source2. If it's just "hanging" on to the right-hand side without being part of the table it will certainly not work. 

 

The only other thing that comes to mind is that "SequenceNumber" in both tables are not aligned/unique. Are you sure that, for instance, an item with SequenceNumber 1 in Source2 is in fact the same item with that number in the table resulting from the #"Remove duplicates" step? 

 

Rather than working on big tables from combined files from a folder, can you get the technique to work on a single file? Easier to debug that way.