Forum Discussion

Mohit009's avatar
Mohit009
New Member
26 days ago
Solved

Power Query Refresh Failing After Source File Structure Changed

I have a Power BI report pulling monthly Excel files from a SharePoint folder using the "Combine Files" option in Power Query. Everything was working fine until a new file was added this month. Now refresh fails with

Expression.Error: The column 'Customer_ID' of the table wasn't found.

The latest file has the same data, but the column was renamed to CustomerID (without the underscore). I don't want to manually fix this every month. Is there a way to make the query handle this variation automatically?

  • Mohit009​  You can use MissingField.Ignore it skips any rename whose source column isn’t in that file, so older files with Customer_ID pass through untouched. Please refer the Power Query below on how to use the MissingField.Ignore function. Add new variants to the list as they appear.

    let
        Source = Data
        PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    
        // Map of known variants
        Renames = {
            {"CustomerID", "Customer_ID"},
            {"Customer ID", "Customer_ID"},
            {"CustomerId", "Customer_ID"}
        },
    
        Renamed = Table.RenameColumns(PromotedHeaders, Renames, MissingField.Ignore)
    in
        Renamed

     

3 Replies

  • Hi Mohit009​,

    You can handle this in Power Query by standardizing the column name and renaming the variant to the expected name.

    = Table.RenameColumns(
        #"Promoted Headers",
        {
            {"CustomerID", "Customer_ID"},
            {"CustomerName", "Customer_Name"}
        },
        MissingField.Ignore
    )

    In the above query, Power Query checks for the CustomerID and CustomerName columns and renames them to Customer_ID and Customer_Name, respectively, if they exist. If either column is missing, it simply ignores it without throwing an error.

    🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
    💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
    🎖 As a proud SuperUserand Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
    🔗 Curious to explore more? [Discover here].
    Let’s keep building smarter solutions together!

  • Hi Mohit009​ 

    You can handle this automatically in Power Query by standardizing the column names in the Transform Sample File query.

    Add a step immediately after the source/navigation step, before any transformations that reference the column:

    = Table.RenameColumns( #"Previous Step", {{"CustomerID", "Customer_ID"}}, MissingField.Ignore )

    This way:

    • Files containing CustomerID will have the column renamed to Customer_ID.
    • Files already containing Customer_ID will remain unchanged.
    • Subsequent transformation steps can consistently reference Customer_ID.

    Since you're using Combine Files, make sure this logic is applied in the transformation function used for each file, not just in the final combined query.

    Also, check the automatically generated Changed Type, Removed Columns, and Expanded Table Column steps, as they may still reference the old structure.

    One important consideration: this handles known naming variations, not arbitrary future column changes. For a more robust solution, I would recommend standardizing the source file schema whenever possible.

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

     

  • Mohit009​  You can use MissingField.Ignore it skips any rename whose source column isn’t in that file, so older files with Customer_ID pass through untouched. Please refer the Power Query below on how to use the MissingField.Ignore function. Add new variants to the list as they appear.

    let
        Source = Data
        PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    
        // Map of known variants
        Renames = {
            {"CustomerID", "Customer_ID"},
            {"Customer ID", "Customer_ID"},
            {"CustomerId", "Customer_ID"}
        },
    
        Renamed = Table.RenameColumns(PromotedHeaders, Renames, MissingField.Ignore)
    in
        Renamed