In Power Query, Expression.Error: The module 'X' is not defined occurs when M-code references an external module, custom connector, shared library section, or query package that the local Power Query runtime environment cannot resolve. This error is common when opening workbooks created in custom developer environments, using third-party Power Query extensions, or copying enterprise M-code that relies on custom M shared sections.
Quick Answer
Check whether your query depends on a custom data connector (
.mezor.pqxfile) that is missing from your machine’sDocuments\Power BI Desktop\Custom Connectorsor Excel add-in folder. If the error appears after copying M-code between workbooks, verify whether the script calls a custom function query or shared module that was omitted during the migration.
What “Module Not Defined” Means in M-Code
Under the hood, Power Query organizes its internal libraries and user queries into logical containers called sections and modules. Standard standard library functions live inside modules built directly into the runtime (such as Table, List, Text, Date, and Web).
When you see:
Expression.Error: The module 'CustomConnector' is not defined.
orExpression.Error: The module 'SharedFunctions' is not defined.
it means the formula engine encountered a reference formatted like Module.Item or a section import statement that points to an identifier outside the standard M library, and your local Excel or Power BI client does not have that component registered.
Primary Causes and Targeted Solutions
1. Missing Custom Connector (.mez / .pqx Files)
Custom connectors allow developers to build tailored API integrations using the Power Query SDK. These connectors compile into files with .mez or .pqx extensions and must be installed locally on every machine that executes the query.
If an analyst built a query using a custom CRM connector and sent you the workbook, your machine cannot evaluate the source steps without that file.
- Fix:
- Obtain the compiled
.mezor.pqxconnector file from the workbook’s creator or your system administrator. - For Excel: Ensure the appropriate third-party extension registry keys or custom add-in paths are configured.
- For Power BI / Analysis Services: Place the file in:
[Documents]\Power BI Desktop\Custom Connectors - In Excel / Power BI options, check the security settings under Data Extension Security to ensure custom connectors are permitted to load.
- Obtain the compiled
2. Copying M-Code Without Supporting Function Queries
Enterprise queries often rely on central user-defined functions (UDFs) stored as separate queries within the same workbook.
For example, a query might call FxCleanDates[CleanColumn](Source). If you copy the main query’s M-code into a fresh workbook but fail to copy the supporting FxCleanDates query, the new workbook does not recognize FxCleanDates as a valid module or object.
- Fix:
- Return to the original source workbook.
- Inspect the Queries pane on the left side of the Power Query window.
- Locate any custom functions or supporting queries referenced by your main query.
- Copy and paste those functions into the new workbook before running the primary query.
3. Misspelled Standard Library Names or Casing Errors
Power Query M is strictly case-sensitive. While rare, attempting to invoke core namespaces with incorrect casing or invalid syntax can trigger module resolution failures:
- Faulty Example:
While simple casing mistakes usually reportThe name 'x' wasn't recognized, referencing internal modules or record-level scopes incorrectly can confuse the parser into looking for external modules. Always use standard camelCase or PascalCase conventions according to the Power Query standard library specification.// Writing Table with lowercase or misspelling native namespaces #"Result" = table.SelectRows(Source, each [Active] = true)
4. Section Document Execution Mismatches
Advanced developers sometimes write standalone M scripts using formal section declarations:
section MyReportModule;
shared FetchData = () => ...;
Excel’s standard UI query editor does not support importing raw .m section documents directly into standard formula bars, it expects self-contained let ... in expressions. If raw section code was pasted into a standard query, delete the section header and convert the logic into a standard let-expression.
Diagnostic Escalation
If you have confirmed that no custom connector was used and all helper queries are present:
- Open the broken query in the Advanced Editor.
- Perform a text search for the module name cited inside the error string.
- If the module name points to a legacy corporate database provider or third-party web driver, check Fixing “The provider ‘Microsoft.ACE.OLEDB.12.0’ is not registered” (Driver errors) to confirm whether an underlying data provider driver requires local re-installation.