Forum Discussion
Transfer one query from one data model to another
- 7 years ago
It's in the Advanced Editor. You were pasting M code so I figured you knew how to find it. Uploaded an example.
- one - this is an original query to a CSV built using the GUI
- two - another orginal query to a CSV built using the GUI
- Append1 - An "Append as New" query built using the GUI
- Query1 - This is a hand-built query that started with a Blank query. I copied and pasted the M code from the other queries and made the necessary edits as specified in the original article.
The important thing to remember when copying and pasting M code is to make sure that the references in each subsequent step refer to the correct previous step in the query. Also, watch your commas.
Right, so start with a blank query and then use this:
let
Source1 = Excel.Workbook(File.Contents("C:\Users\Andrei\Desktop\File1.xlsx"), null, true)
Navigation1 = Source1{[Item="File1",Kind="Sheet"]}[Data]
PromotedHeaders1 = Table.PromoteHeaders(File1, [PromoteAllScalars=true])
Source2 = Excel.Workbook(File.Contents("C:\Users\Andrei\Desktop\File2.xlsx"), null, true)
Navigation2 = Source{[Item="File2",Kind="Sheet"]}[Data]
PromotedHeaders2 = Table.PromoteHeaders(File2, [PromoteAllScalars=true])
Append = Table.Combine(PromotedHeaders1,PromotedHeaders2)
in
Append
It's exactly the same concept as the article I sent you except that you are doing a Table.Combine instead of a Merge.
Where do you put all this code?
it is not letting me add 2 sources in the same query.
Kind regards,
Andrei
- Greg_Deckler7 years agoCommunity Champion
It's in the Advanced Editor. You were pasting M code so I figured you knew how to find it. Uploaded an example.
- one - this is an original query to a CSV built using the GUI
- two - another orginal query to a CSV built using the GUI
- Append1 - An "Append as New" query built using the GUI
- Query1 - This is a hand-built query that started with a Blank query. I copied and pasted the M code from the other queries and made the necessary edits as specified in the original article.
The important thing to remember when copying and pasting M code is to make sure that the references in each subsequent step refer to the correct previous step in the query. Also, watch your commas.
- Andrei7 years agoRegular Visitor
Thank you very much. You made my life allot easier.
Andrei
- Andrei7 years agoRegular Visitor
Hi,
Would you please be able to recommend some resources to learn more about Power Query, Advanced Editor and M Code.
I find it allot more powerfull then simple Excel.
Again, thank you for your help.
Kind regards,
Andrei