Forum Discussion
Import files with different files names - Change dynamically files names
Hi,
I read some of your solutions to address the changes of files names in PowerBI, but I cannot transpose any of them to my own issues. Could you please help ?
1/ File Name
The file is replaced each month by a new file whose suffix (yyyymm) changes. Hence, I have to update manually my code for the new posted file to be recognized. How can I avoid that ?
2/ Excel Sheet Name. In this example, the name of the source file stays the same, but the Sheet name changes for each new file that crushes the previous one. Hence, I have to change manually the code at these 3 different spots. Can it be automatically updated, whatever the Sheet name is ?
Thank you so much in advance for any help.
You can leave that as it is. It's just a variable name (now) and has no connection to your actual data.
7 Replies
- Greg_Deckler
Community Champion
Going to refer you to ImkeF on this one but a couple of thoughts.
You could solve this using parameters, that would prevent you from having to update your code.
In the first case, you could probably calculate out the next file by doing something around grabbing the current date and time.
For the second case, I believe that there is a way to grab a sheet by it's "order" instead of its name. There is a way to return the tables (sheets) in an Excel Workbook, https://docs.microsoft.com/en-us/powerquery-m/excel-currentworkbook
- JMSNYC
Helper III
Thank you for your referral
Re: issue #1: this is not possible, since I have many files listed that I have to take into account
Re: issue #2: will explore based on your link.
Thanks
- ImkeF
Community Champion
Not sure if I understand your request correctly, but you can use paramters in Power BI that let basically pass variables to your queries. You can edit them in the UI without having to edit the M-code: https://www.red-gate.com/simple-talk/sql/bi/power-bi-introduction-working-with-parameters-in-power-bi-desktop-part-4/
"YourCode1" & Parameter1 & "YourCode2"