The ability to use Get Data from Folder in Power BI is a very useful option. However, if your sheet names are different in the list of Excel files, then you will face a problem. In this blog article, I’ll explain a method you can use that works regardless of the sheet names.
Sample Dataset
I have a set of Excel files like below;
Each file has the same structure of the data, but their sheet name is different;
Problem with Get Data from Folder
If you use the “Get Data from Folder” option in Power BI Desktop and Combine the Files, you would get the below results:
The Combine process, asks one of the files to be a template, and from that template, I need to choose the Sheet Name that contains the data which I want to be combined across all files.
Because in my files, this sheet name only exists in one file, it means the combined result would only work for one of the file, and not the others!
Solution 1: Use Sheet Index Not the Name
The first solution to use for the problem above is that you can use the index of the sheet, which means the order of the sheet among other sheets. for example in the scenario below, that order can be like this (start from zero on the left side).
Now that you know the sheet index, you can fix the function that is automatically created by the Power Query when you combined files. This should be under a folder and named something like “Transform Sample File”.
Note that the above query can be found in Power Query Editor, which is accessible using “Transform Data” in the Power BI Desktop.
After finding the query, go and find the Navigation step, with selecting this step, you will see the formula bar’s expression. Enable the formula bar in the View tab if you cannot see it in the editor.
This step, sometimes might be called other things and you might need to check the 2nd or the 3rd step after the Source to find it.
Now use the Sheet index inside the {} instead of anything written there.
The code should looks like this now;
This action should also automatically fix the function associated with that query, and as a result your combined result should be all working without any errors;
Caution 1: Remove Unnecessary Items
The method above might not work if you have other items in addition to the sheet, such as a table or anything else. so make sure to filter the Kind field in the Source tab to only Sheets (or anything else you are looking for);
Caution 2: Remove Unnecessary Steps
Sometimes, there is a little difference in the content of each Excel file, and you might have a column or two that do not exists in other files. You need to scan the list of steps, and remove any step that has something hardcoded with the column names in it, for example; remove Changed Type steps.
Solution 2: Filter to the Name Template
If the sheet you are looking for is not always at the same position (index) in all the files, then find other alternatives. For example, try to find a name template. Let’s say, they all start with 20…., such as 201506, 201507….201601…
Then if you filter it for that name, then it is very likely that the only sheet with that name template would be in the result set which is then accessible with sheet index 0.
To filter the sheet names based on a template you can use this approach:
Insert the new step, and then enter the characters you expect in all sheet names;
Now in the result set, it is very likely that you have one sheet only, which can be accessed using the sheet index zero;
You can also use any other combinations of text filters, such as Contains, ends with etc.
Download Sample Power BI File
Download the sample Power BI report here:
Excelent Sir….
Hi Reza, i’m learning a lot from your articles.
but i encountered a error when i tried to download any of the books from the email replied from you.
Server failure
Hi Reza, Awesome trick, really appreciate…thank you RADACAD
thank you
Thanks so much, exactly what I was looking for
I am glad it helped
Cheers
Reza
Very helpful and precise guidance.. thank you for step by step instructions
Thank you very much Reza, this really exactly what I am looking for.
thank you, Reza, for Solution 1, along with the Cautions. Great job!
Thank you. Very useful tutorial 😊
Thanks. I am glad it helped.
Very helpful and easy to follow! Suit my case perfectly and works a charm. Thank you!
Thanks Jing. I am glad it helped.
thanks, i was looking for this solution from months…
I am glad it helps 🙂 Thanks!
Amazing, thank you very much. I’ve spend hours trying to fix it before reading this post.
Thank you so much, this was unbelievably helpful – I was stuck for ages.
Many thanks! Really apreciate your work and teachings!
Thank you for sharing. Is this also available for Sharepoint data sources? I cannot seem to find it.
Yes. I have a video about getting data from OneDrive (which is similar to SharePoint structure)