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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
ivanuska
Advocate I
Advocate I

Power Query - Dynamic selection of document name

Hello,

 

I would need your help with dynamic selection of excel file on OneDrive. We have script that is creating excel file (.xlsm) and saving it into OneDrive in format "Document Name - DD/MM/YYYY". Based on either timestamp in name or document creation date, I am able to create ranking of documents and define the newest file.

 

The problem appears, when I want to unpack the file by selecting Binary on Content column. Once selected, Power Query automatically creates step with hard-coded document name. Once the new file is generated, the query will fail on this step as the document name has changed. Please see below screenshots.

 

ivanuska_1-1736811648130.png

 

ivanuska_2-1736811779640.png

 

Is there any way how to overcome this issue by dynamic selection of document name? I am able to create query that will define the newest file - I just need to copy the name of the document into dynamic variable and then replace the hard-coded text by this variable.

 

Sorry but I have very limited knowledge to write own functions in M language so I would need step-by-step help (ideally with screenshots).

 

Thank you for any help!

Regards

Ivanuska

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @ivanuska 

The easiest way to fix this is to edit the code in the formula bar of your 2nd screenshot by replacing the code between the curly braces with "0"

In other words, change the code for this step to:

 

= #"Filtered Rows1"{0}[Content]

 

The zero corresponds to the first row of the table from the previous step named "Filtered Rows1" (using a zero-based index). Since you have already filtered the table to a single row, the first row will always correspond to the file you want to use.

 

Here is a short recording of me starting with a query similar to yours and editing the M code for that step:

File index zero.gif

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @ivanuska 

The easiest way to fix this is to edit the code in the formula bar of your 2nd screenshot by replacing the code between the curly braces with "0"

In other words, change the code for this step to:

 

= #"Filtered Rows1"{0}[Content]

 

The zero corresponds to the first row of the table from the previous step named "Filtered Rows1" (using a zero-based index). Since you have already filtered the table to a single row, the first row will always correspond to the file you want to use.

 

Here is a short recording of me starting with a query similar to yours and editing the M code for that step:

File index zero.gif

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thank you very much for super-fast and super-helpful response!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors