r/ExcelPowerQuery • • 3h ago

Error in Power Query editor

Newbie here! I'm trying to combine multiple Excel files in a folder. Just the first file transforms and loads into the pivot table. I dont see the other months' files, and when I try to add new files to the folder, I get an error message " The key didn't match any rows in the table."

Please help 🙏

2 Upvotes

4 comments sorted by

1

u/Weaver707 3h ago

Does each file contain the same table or sheet name? Usually this pops up if you have variation in the naming of the content in each individual file.

For example: File name#1-"monthly data" -worksheet name is Jan 26

File name #2- "monthly data" - worksheet name is Feb 26

PQ is looking at the worksheet name and isn't able to find a match between them.

There are some methods that will work around this but it does depend heavily on the structure of the source files. If that is the root cause, it doesn't require going in and changing the source, but does require a slightly different approach to selecting the target worksheet.

1

u/Less-Doughnut1071 2h ago

Thanks alot for responding. Its similar names but I can change to; 01, 02 etc

Whats the other approach to select target worksheet?

Also, I combine 4 sheets but I see only data from one sheet after loading to pivot table. Not sure why? Can you please advise? Thanks

1

u/Weaver707 1h ago

Is there only one tab in each target workbook?

No need to change anything yet.

When PQ leverages the sample file and generated the custom function, it hard codes the target name. If there is only one worksheet in the target files you can leverage this. You can change the generated "Transform Sample File" a little bit to always grab the first worksheet it finds regardless of the actual name.

In the Transform Sample File you would see something like:

Source = excel.workbook(Parameter...) Sheet1_Sheet = Source([Item ="Sheet1".....

This is where it hardcodes the name. In my example it is the "Sheet1".

Instead you can alter that second step. Again there is an assumption that there is only one worksheet.

Instead change the second part of the process to look like this

ExtractData = Table.SelectRows(Source, each [Kind] = "Sheet"){0}[Data]

Hopefully that made sense. Typing on my phone so hopefully there are no typos in the code. The zero represents the record found in the first position. The great about knowing that is that if you said oh, there are two tabs but the first one is just a definitions page, you could change that 0 to a 1 and it would pull the record found in the second position.

1

u/Weaver707 1h ago

You may need to add a promote headers step in there too.