Forum Discussion

MichaelF1's avatar
MichaelF1
Icon for Helper III rankHelper III
4 years ago
Solved

How to edit sheet name in Excel doc when source is a folder

Hi everyone,

 

I have a PBI report that uses a folder of excel docs as the data source.

 

I want to change the excel docs and I think I need to change the name of the actual tab in the excel file within power query editor. However, I can't see where the name of the tab is referred to in my M code.

 

Can anyone give some help with this please?

 

Cheers,

 

Michael

 

 

13 Replies

    • MichaelF1's avatar
      MichaelF1
      Icon for Helper III rankHelper III

      Hi amitchandak , thanks for the reply.

       

      Your video shows how to change the data source if you change the name of the excel file itself, but I want to edit the name of the actual tab in the file. Hope this makes sense, I'll attach the error message.

      Thanks again,

       

      Michael

       

       

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        MichaelF1 , Change sheet name in Item

         

        Source = Excel.Workbook(File.Contents("C:\Users\Amit Chandak\Downloads\PivotData (1).xlsx"), null, true),
        Pivot_Sheet = Source{[Item="Pivot",Kind="Sheet"]}[Data],

         

         

        Pivot is my sheet name

         

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MichaelF1 

     

    It's been a long time since you queried this issue but I've experienced the same issue and couldn't find any satisfying solution in forums until I consulted ChatGPT 🙂 I wanted to change the sheet name in Excel from "Billing details_C2S2" to "Billing details". Here's it's answer that perfectly solved my issue:

     

    From the M code you provided, it looks like the sheet name is not explicitly referenced because you are using a folder query (Folder.Files), which transforms multiple files in the folder, and the transformation is done via a custom function (Transform File (11)).

    The problem likely stems from the step where this custom function is called. Since you renamed the sheet inside the Excel file, the function "Transform File (11)" might still expect the original sheet name, "Billing details_C2S2", leading to the error.

    Here’s what you can do to fix it:

    Steps to Edit the Custom Function:

    1. In Power Query Editor, go to the Queries pane on the left and locate the query named "Transform File (11)" (this is the custom function).
    2. Click on this function to view its steps.
    3. Inside this function, find where it refers to the sheet name "Billing details_C2S2".
    4. Update this reference to "Billing details" (the new sheet name).
    5. Apply the changes and re-run the query.