Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Value.Metadata Function Guide and Usage

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Value.Metadata function in Power Query is used to retrieve the hidden metadata associated with a value, such as a table, list, or record. While most users interact only with the visible data in a column, Power Query attaches a hidden record of metadata to values—often containing information about the data source, column descriptions, or custom attributes assigned during the transformation process. By using Value.Metadata(value), you can extract this hidden record and turn it into visible data that can be used for auditing, dynamic labeling, or advanced data validation.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • Access to the Power Query Editor (Get Data > Launch Power Query Editor).
  • A dataset that contains metadata (such as a table imported from a database with column descriptions or a custom value where metadata was manually added using Value.ReplaceMetadata).
  • Basic familiarity with the Power Query formula bar and the M language.

Step-by-Step

  1. Open the Power Query Editor: Launch Power BI Desktop or Excel. Navigate to the Data tab, select Get Data, and choose your source. Once the data is loaded, click Transform Data to open the Power Query Editor window.
  2. Identify the Value for Inspection: Metadata is not visible in the standard grid view. To see it, you must target a specific value. For example, if you have a table named "SalesData", the table itself is a value that can have metadata.
  3. Create a Custom Step: Click the fx button next to the formula bar. This creates a new step in the Applied Steps pane.
  4. Apply the Value.Metadata Function: In the formula bar, type the function following this syntax: = Value.Metadata(PreviousStepName). Replace "PreviousStepName" with the name of the step immediately preceding the current one (e.g., = Value.Metadata(#"Filtered Rows")).
  5. Analyze the Result: Upon pressing Enter, the Power Query preview window will change. Instead of your data table, you will see a Record. This record contains all the metadata associated with the value from the previous step. If no metadata exists, the result will be an empty record [].
  6. Extract Specific Metadata Fields: If the resulting record contains multiple fields (such as "Description" or "Source"), you can click on the specific field value within the record to drill down, or use the formula Value.Metadata(PreviousStepName)[FieldName] to extract a specific piece of information directly.
  7. Integrating into a Column: To use Value.Metadata for every row in a table, go to the Add Column tab and select Custom Column. Use a formula that targets the specific cell or value. Note that most standard table cells do not have individual metadata unless specifically assigned; usually, metadata is attached to the table object or the column object.

Common Mistakes

One of the most frequent errors is attempting to use Value.Metadata on a value that simply does not have any metadata assigned. Many users assume that every piece of data in Power Query has a hidden set of properties like "Date Created" or "Author." In reality, Power Query metadata is sparse. Unless the data source provides it (like some SQL Server descriptions) or the developer manually adds it using Value.ReplaceMetadata, the function will return an empty record, leading users to believe the function is broken.

Another common mistake is confusing Value.Metadata with the properties of a table (such as Table.ColumnNames or Table.Schema). Value.Metadata retrieves the metadata record attached to the object, not the structural schema of the table. For example, if you want to know the data type of a column, you should use Table.Schema; if you want to retrieve a custom description attached to that table object, you use Value.Metadata.

Users also frequently forget that metadata is volatile during certain transformations. Some Power Query operations strip away the metadata from the original value and return a new value without that metadata. If you find that your metadata disappeared after a specific transformation step, you may need to move the Value.Metadata call earlier in your query sequence or re-apply the metadata using Value.ReplaceMetadata after the transformation.

Tips

To make Value.Metadata truly useful, pair it with Value.ReplaceMetadata. This allows you to "tag" your data. For instance, if you are building a complex template for other users, you can attach a metadata record to a table that includes instructions or version numbers. Later in the query, or in a separate auditing query, you can use Value.Metadata to extract those instructions and display them in a report.

When working with large datasets, avoid calling Value.Metadata inside a custom column for every single row unless absolutely necessary. While retrieving metadata is generally fast, adding complex M functions to every row can increase the refresh time of the query. Instead, retrieve the metadata once at the table level and store it in a variable using a let...in block.

If you are extracting metadata from a database source, check your database permissions. Some connectors only pull metadata (like column comments) if the user account has specific administrative or schema-reading permissions on the server. If Value.Metadata returns an empty record for a source you know has descriptions, the issue is likely at the connection or permission level.

Troubleshooting

If the function returns an empty record [] but you expect data, first verify the source. Try using a simple Value.ReplaceMetadata step immediately before the Value.Metadata call to see if the function is working as intended. For example, use = Value.ReplaceMetadata(#"PreviousStep", [Test="Success"]). If the subsequent Value.Metadata call returns "Success", then the function is working, and your original data source simply contains no metadata.

If you encounter a "Formula.Error: The field 'FieldName' of the record wasn't found," it means you are trying to access a specific metadata property that does not exist in the record. To prevent this, use the Record.FieldOrDefault function. Instead of Value.Metadata(Step)[Description], use Record.FieldOrDefault(Value.Metadata(Step), "Description", "No Description Available"). This ensures your query doesn't crash when a piece of metadata is missing.

If the query performance drops significantly after adding metadata calls, check if you are triggering multiple requests to the data source. Metadata calls can sometimes break "Query Folding," meaning Power Query has to download the data to your local machine to process the metadata rather than letting the server handle it. To fix this, perform all your filtering and joining first, and only call Value.Metadata at the very end of the process.

Frequently Asked Questions

Does Value.Metadata show the data type of a column?

No, Value.Metadata retrieves the metadata record associated with the value. To find the data type of columns in a table, you should use the Table.Schema function, which returns a table detailing the types, names, and constraints of every column.

Can I add my own metadata to a table?

Yes, you can use the Value.ReplaceMetadata function. This allows you to take an existing value (like a table) and either add a new metadata record or replace the existing one with your own custom record of information.

Is metadata stored in the final Excel or Power BI report?

No, metadata retrieved via Value.Metadata is only available within the Power Query engine during the data transformation process. If you want the metadata to appear in your final report, you must transform that metadata into a standard table column or a scalar value that is loaded into the data model.

Why is Value.Metadata returning an empty record for my CSV file?

CSV files are plain text files and do not support embedded metadata in the way that SQL databases or specialized file formats do. Unless you manually add metadata using M code within the query, Value.Metadata will always return an empty record for a CSV import.

Can Value.Metadata be used to find the file path of a source?

Generally, no. The file path is usually part of the source function arguments (like File.Contents("C:\path\file.csv")) rather than being stored as metadata on the resulting table value. You would need to create a custom parameter or a separate query to track the source path.