Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JMSNYC
Helper III
Helper III

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.

 

1 ACCEPTED SOLUTION

You can leave that as it is. It's just a variable name (now) and has no connection to your actual data.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

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

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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

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-b...

 

"YourCode1" & Parameter1 & "YourCode2"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thank you Imke for taking the time to answer my questions. Issue is that I am pretty new at PowerBI and that I do not understand your recommendation about using parameters:

 

My first request is about this issue:

 

 

Today, all my queries/transformations for this file is based on this file name.

 

By Feb. 1, 2019, a new file will be posted on the blob server with the name ... "GERS/SWO_Facteur9_STATHOP_PDV_3647050001000102_M201901 txt" ... and I will need to use this new file to run the previous transformations. 

 

TODAY: in order to do that, I get into the "Advanced Editor", and manually change 201812 into 201901, and it transforms the data of the 201901 file the same way it did with the 201812 file

 

MY QUESTION: I need to automate this manual step. Hence, how can PowerBI change this last part of the file name, or does not see this last part of the file name, so it picks the updated file rather than the previous file ?

 

If I recall, in Excel you were able to transform the file name into "GERS/SWO_Facteur9_STATHOP_PDV_3647050001000102_* txt" ... and it would pick any file with the same first set of characters

 

My second request is about this issue:

 

 

A file - with the same name - is posted weekly on our Azure blob. This issue, is that the name of the only Sheet of the workbook changes randomly ... last week it was "report1548055718808" ... this week it is "report1449053718936" ... hence, it breaks my M-code.

 

TODAY: in order to address that, I get into the "Advanced Editor", and manually change "report1548055718808" by "report1449053718936" wherever the Sheet name is used (for instance at 3 locations in the M-code)

 

MY QUESTION: I need to automate this manual step. Hence, how can PowerBI is indifferent of the Sheet Name so it does not break the code ?

 

I hope that the description of my two issues helps you better understand the issues I am facing.

 

Thank you for your help

 

 

Hi @JMSNYC,

1) you can simply filter your filenames after a "Begins With"-string:

 image.png

 

 

2) If there's just one sheet in the file, this expression will adress it dynamically, irrespective of its name:

 

 

#"Imported Excel"{[Kind="Sheet"]}[Data]

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Hi, Imke.

 

Re: issue #1 : 

 

Great suggestion. It works perfectly. Thank you so much. Will post that as a solution.

 

Re: issue #2 : 

 

There is still a problem in the code:

 

 

For whatever reason, row 6 starts with the Sheet Name. Your suggestion helped to replace the "report..." written in red ... but how to avoid for row 6 to start with the Sheet Name ?

 

Thanks

 

You can leave that as it is. It's just a variable name (now) and has no connection to your actual data.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.