Forum Discussion

jaryszek's avatar
jaryszek
Super User
1 year ago
Solved

Power Query Folding breaking query

Hi Guys,

I have notied that when i am using path like this within Folder.Files: 

 

let
path = Text.Combine("D:\BundleSetsRepositories\cost-mgmt-data1")
in
path

everything is working but when i am trying to use dynamic path like :

let
path = Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\")
in
path

 

power bi hangst while publishin into workspace. 
Why? 
How to fix it?

Best,
Jacek

  • jaryszek's avatar
    jaryszek
    1 year ago

    thanks,

    i tried your proposition: 

    let
    getSource = () =>
    Folder.Files(Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\")),
    
    Source = if Environment = "Local" then getSource() else #table({}, {})
    in
    Source

     

    It still hanging power bi while publishing. It is like it skipping if else statement and triggering dynamic path no matter of it. 

    I created support case.
    Best,
    Jacek

11 Replies

  • jaryszek 

    Because Folder.Files() (and similar M functions that reference local paths) are NOT supported in Power BI Service.

    Power BI service (Fabric workspace) cannot access your local machine's file system like D:\... drive.
    It expects:

    • Cloud paths (SharePoint, OneDrive, Azure)

    • Or properly parameterized Web.Contents() links

    When you publish, Power BI tries to validate the data source path and cannot resolve your dynamic local path ➔ it hangs or errors.

    Even hardcoded local paths sometimes cause issues — but with dynamic path, Power BI cannot even check or cache the path ahead of time, making it worse.

    If you must use Folder.Files locally ➔ disable loading it in the service

    You can:

    • Wrap your local source logic inside an if block based on a parameter.

    Example:
    let
    Source = if Environment = "Local"
    then Folder.Files(Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\"))
    else null
    in
    Source

    You create a parameter called Environment with values "Local" or "Service".

    This way ➔ When you publish, and Environment is "Service" ➔ it does NOT try to access local path, avoiding crash.

    Switch to SharePoint, OneDrive, or Azure for file storage

    If these files are important, move them to SharePoint Document Library or Azure Blob Storage, and connect via SharePoint.Files() or AzureStorage.DataLake().

    Use a Dataflow / Lakehouse instead of direct local files

    Instead of trying to pull files at report level ➔ you can use Dataflows or Fabric Lakehouses to land the files, then connect.
    let
    path = Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\"),
    Source = if Environment = "Local" then Folder.Files(path) else #table({}, {})
    in
    Source

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!






    • jaryszek's avatar
      jaryszek
      Super User

      Wow thanks!

      Switch to SharePoint, OneDrive, or Azure for file storage
      If these files are important, move them to SharePoint Document Library or Azure Blob Storage, and connect via SharePoint.Files() or AzureStorage.DataLake().


      It means that it will work without any issues? 

      And another, more important question. 
      The same is for Web.Contents... https://raw.githubusercontent.com/ . 
      It means that I have to hardcode it within code? 
      How to skip this error? 
      The only way is to create custom connector or howto handle web.Contents to provide parameter? 

      Best,
      Jacek

  • Ok i tried:

    Example:
    let
    Source = if Environment = "Local"
    then Folder.Files(Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\"))
    else null
    in
    Source


    but it seems that is not solving the case for me...can anybody try?
    It still reading Folder.Files as dynamic one. 

    I tried to put it into function or Expression.Evaluate but effect was the same...
    Ah how to solve the case using M Code not having sharepoints or blob storagas involved? 

    Best,
    Jacek

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

      Hi jaryszek ,

      Thank you for reaching out to Microsoft Fabric Community.

      Thank you lbendlin johnbasha33  for the prompt response.

      A better way is to use a lambda function to defer execution — this avoids Power BI evaluating the Folder.Files line unless explicitly called:

      let
      getSource = () =>
      Folder.Files(Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\")),

      Source = if Environment = "Local" then getSource() else #table({}, {})
      in
      Source

      This ensures Folder.Files is only invoked when Environment = "Local".

      It means that I have to hardcode it within code? How to skip this error? 

      No.You can parameterize Web.Contents, but you must follow Power BI's rules for safe and static URL paths.

      Safe usage of Web.Contents with parameters:

      Let
      baseUrl = "https://raw.githubusercontent.com/",
      filePath = "your-org/repo/main/data.csv",
      fullUrl = baseUrl & filePath,
      Source = Web.Contents(baseUrl, [RelativePath = filePath])
      in
      Source

      This is considered "safe" and Power BI can validate it. But passing the full URL as a single dynamic string like Web.Contents(dynamicUrl) can break the validation engine.

       

      If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

       Thank you.

       

       

       

      • jaryszek's avatar
        jaryszek
        Super User

        thanks,

        i tried your proposition: 

        let
        getSource = () =>
        Folder.Files(Text.Combine({Text.Replace(paramLocalRepositoryPath, "/", "\\"), paramRepository}, "\\")),
        
        Source = if Environment = "Local" then getSource() else #table({}, {})
        in
        Source

         

        It still hanging power bi while publishing. It is like it skipping if else statement and triggering dynamic path no matter of it. 

        I created support case.
        Best,
        Jacek

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

    Hi jaryszek ,

    I wanted to check if you received any insights from the case that was raised.If so, please consider sharing the solution in the forum and marking it as accepted, this will help other members find the answer more easily.

    Thank you.

    • jaryszek's avatar
      jaryszek
      Super User

      nope, we are waiting, support is not working from Microsoft

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

    Hi jaryszek ,

    We are following up once again regarding your query. Could you please confirm whether the issue has been resolved through your support ticket with Microsoft?

    If so, we would appreciate it if you could share the resolution or any key insights here to benefit others in the community. If we don’t receive a response, we will proceed with closing this thread.

    If you need further assistance in the future, feel free to start a new thread in the Microsoft Fabric Community Forum. We will be happy to support you there.

    Thank you.

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

    Hi jaryszek ,

    Thank you for your patience. The concerned team is looking into the issue, but it may take some time to resolve. As there is already an open ticket with Microsoft, we are closing this thread for now. If you encounter any further issues, please feel free to start a new thread in the community forum, we will be happy to assist you.

     

    Thank you for being part of Fabric community Forum.