Power Query can read an XML file and flatten its nested structure into a table you can filter, join and load to Excel or Power BI. You do this through the Get Data or Data > Get Data route, choosing an XML source, then expanding the record and list cells with the expand buttons and the "Into Rows" option. The one thing to understand before starting is that XML is hierarchical: a single node can contain child nodes, repeated elements and attributes, so Power Query first shows you a small navigation table and you drill into it before the full table appears. Menu labels differ slightly between Excel and Power BI Desktop and between versions, so if a label is not exactly as described, look for the nearest equivalent.

What You'll Need

  • Excel (Microsoft 365 or a recent perpetual version with Power Query) or Power BI Desktop. The core XML connector exists in both.
  • An XML file saved locally, on a network share, or accessible via a URL you can reach.
  • A basic sense of the file's structure: open it in a text editor and look at the repeating element names, their child elements and any attributes.
  • Optionally, a schema file (.xsd) if the source provides one, which helps Power Query interpret the table shape.

Step-by-Step

  1. Inspect the XML first. Open the file in Notepad or any plain text editor. Note the name of the root element, the name of the repeating element that represents one row of data, and the names of its children. This saves you guessing later. For example, a file might repeat an Order element, each containing OrderID, Customer and LineItems.
  2. Start the import. In Excel, go to the Data tab and choose Get Data, then From File, then From XML. In Power BI Desktop, choose Home, then Get data, then XML. Paste a URL instead if the file is served over the web.
  3. Check the preview and load. The preview shows whichever node powers the first view. Confirm it looks like your data, then choose Transform Data rather than Load, so you can clean it before it lands in a worksheet.
  4. Drill into the right node. The Power Query Editor opens with a navigation table listing Name and Value. Find the row whose name matches the repeating element you identified in step 1 and click the word Table in its Value column. Do not click the checkbox next to the row, which loads every node as a separate query.
  5. Review the initial table. You will usually see one column whose cells say Record (the child nodes) plus any attributes. Click the double-headed expand arrow in that column header.
  6. Expand into columns. In the dialog that appears, clear the Use original column name as prefix checkbox if you want clean headers, then tick the child fields you need. Choosing Expand (rather than Expand and Aggregate) keeps every row. Repeat this for each nested record until you reach the level where the actual values sit.
  7. Handle repeated child lists. If a field contains List rather than Record, that element repeats within a parent. Expand it with Extract Values if you want a comma-separated string, or choose Expand to New Rows to turn each list item into its own row. The new-rows option multiplies parent data, so duplicates of the parent are expected and intended.
  8. Set data types. Click the type icon in each column header and set whole numbers for IDs, decimal for amounts, date for dates and text for everything else. Doing this deliberately beats the automatic change-type step that Power Query sometimes adds, which can error on mixed values.
  9. Remove what you do not need. Delete helper columns, rename headers, filter out blank rows and sort as required. Keep the steps simple and readable in the Applied Steps list.
  10. Load the result. Choose Close & Load to send the table to a worksheet or data model, or Home then Close & Load To to pick a table, a PivotTable or the model. For Power BI, the equivalent is Close & Apply.
  11. Refresh later. Because the query remembers the file path or URL, you can refresh when the source changes. Keep the source file at the same location and name, or update the path in the query's source step.

Common Mistakes

Ticking the box instead of clicking Table. The navigation dialog has both; the checkbox creates one query per node, which multiplies objects and slows refreshes. Click the Table link only.

Expanding the wrong level. Expanding a record before it holds the values you want produces columns full of Record or Table entries. Keep expanding one level at a time until real text and numbers appear.

Losing the parent identifier. When you use Expand to New Rows for line items, the parent order information repeats on each row. If a parent has no ID in the original file, add an index column before expanding so you can regroup later.

Mixed data types. A column containing both numbers and text (or blanks) will throw errors when formatted as a number. Set it to text first, clean it, then change the type.

Moving the source file. Queries store an absolute path. Move or rename the file and the refresh fails with a file-not-found message.

Tips

  • Open the Advanced Editor once the query works to see the M code. It helps you understand and reuse the transformation on other XML files with the same shape.
  • Give each applied step a descriptive name so a colleague can follow the logic.
  • If the same parent element has inconsistent children (some records have extra fields), expanding all available fields is still the right move; missing values simply appear as null.
  • For very large files, filter rows early and remove unneeded columns before the final load to keep refreshes fast.
  • Use a sample or trimmed copy of a huge XML file for development so each change previews quickly.

Troubleshooting

If the file will not open, first confirm it is valid XML by opening it in a browser, which shows a parse error for malformed files. Fix the source or ask whoever exports it; Power Query cannot repair broken markup.

If refreshes fail with a path error, use the source step's gear icon or the Data source settings option to repoint the query at the file's current location, then refresh.

If columns are full of [Table] or [Record] text, the expansion was not deep enough or the wrong field was expanded. Step back through the Applied Steps and expand again.

If a refresh asks for credentials, check whether the source is a secured URL and supply the account your organisation uses. For local files the prompt usually means the path changed or access permissions changed.

If numbers or dates come through as text, use the type icon and set the correct type; if errors appear, use Replace Errors or clean the values with Replace Values first.

If new rows appear after expanding a nested list, that is the intended behaviour of Expand to New Rows, not a duplicate bug.

Frequently Asked Questions

Does Power Query handle XML attributes?

Yes. When you expand a record, attributes can appear as separate columns alongside child elements; tick them in the expand dialog.

Can I combine several XML files at once?

Yes. Point From Folder at the folder, then use the combine or expand content options to load each XML file and apply the same transformation. All files should share the same structure.

Why does one field show List instead of Record?

That element repeats inside its parent. Use Extract Values for one string per parent, or Expand to New Rows for one row per item.

Can I load the result to the Excel data model?

Yes. Use Close & Load To and choose Only Create Connection plus Add this data to the Data Model, then build PivotTables from it.

Do I need to know the M language?

No, the ribbon handles most XML imports. The Advanced Editor is useful only for repeating custom transformations across files.