Forum Discussion

annatan's avatar
annatan
Helper II
1 year ago
Solved

Power Query - Dynamically referring to correct file name in one drive

Hi,

Can I have your help on dynamically referring to correct file name in one drive?

Situation

In one drive, there are multiple file created, such as the file name ending with "2025 - 06" and "2025 - 07" and "2025 - 08" and etc.
And I have a financial schedule, like "2025 - 07" file will not be final until Aug 13, therefore, I initiated a schedule table depending on the current date, like today is Aug 9, we use "2025 - 06". Then starting on Aug 13, we can use "2025 - 07" file.
In Power query, I have connected to schedule table and initiate a new query to look for version based on the current date. Today is Aug 9, so we use version 06. Finally, turn 06 as text "Today Version" in the new query.

Question

In the query which I connected to file, the source step has the following path
"\\mob\2025 - 06.xlsx"

I would like to dynamically change the file path by replacing 06 with "Today Version", and I have tried this

"\\mob\2025 - " & Today Version & ".xlsx"

But it was not working. I have this error message

 

Expression.SyntaxError: Token',' expected.

 

Can you please help me to see if I missed anything there? Thanks,

4 Replies

  • Please ignore my inquiry. I figured it out now. 

  • Hello annatan 

     

    If in your situation I would create a Parameter (FileVersion) in Power Query and use it in the source.

    For Parameter, set its default value from your schedule table and reference this parameter in the file path as in below M. 

    let
        Source = Excel.Workbook(File.Contents("\\mob\2025 - " & FileVersion & ".xlsx"), null, true),
        ...
    in
        Source

     

    If you would like to try this, please also make sure "Today Version" is a single text value and verify the path syntax.

     

    Hope it helps:)

    • annatan's avatar
      annatan
      Helper II

      Hi MasonMA 

       

      May I know what you meant by "For Parameter, set its default value from your schedule table"? Do I need to manually input the version value from schedule table? I would like it to be dynamic and controlled by the schedule table automatically. 

       

      Thanks,

  • v-sdhruv's avatar
    v-sdhruv
    Community Support

    Hi annatan ,

    Good to know that you were able to resolve the issue on your own. If you'd like to share with us what worked for you, it would be great! Since this would help the other community members facing the same issue .

    Thank you