Forum Discussion

T1moris's avatar
T1moris
Regular Visitor
7 months ago
Solved

Cannot reference column renamed to Week#(2) in Power Query (invalid identifier)

In Power BI (Power Query), I tried to rename a column and ran into a strange issue. When I rename the column to Week#(2) , the automatically generated M code is:   Renamed Columns2 =Table.RenameCo...
  • Omid_Motamedise's avatar
    7 months ago

    Hi T1moris 

     

    Power Query has two different concepts:

    Display name (what you see in the UI) => Week#(2)

    M language identifier (what the engine must use internally)

    M has strict identifier rules. A column name can be referenced directly only if it: Starts with a letter or underscore and Contains only letters, numbers, and underscores

    Your column name: Week#(2) violates three rules: # is special in M ( and ) are not allowed in identifiers

    In M: #"Some Text" means “treat this text literally as a name” So when Power Query internally generates: "Week#(#)(2)"

    The column name contains literal text Week#(2), and the # itself must be escaped This is not a rename mistake—it’s Power Query protecting itself from syntax errors.


    Why do [Week#(2)] and [Week#(#)(2)] both fail?
    Because square brackets only work for valid identifiers. This works: [SalesAmount] and This fails: [Week#(2)]

    Because Week#(2) is not a valid identifier, even if that looks like the column name.

    The CORRECT way to reference this column is: [#"Week#(2)"]