Power Query is a powerful data transformation and data preparation tool that allows users to connect to various data sources and transform data before loading it into Power BI. Power Query M Language is the language used by Power Query to express these transformations. In this article, we will explore how to use Power Query M Language code to connect to an XML data source from inside Power BI.



Before we dive into the Power Query M Language code, let’s first make sure we have all the prerequisites in place. We need to have Power BI Desktop installed on our machine, along with the Microsoft Power Query for Excel add-in. We also need to have an XML data source that we want to connect to, along with the necessary credentials to access the data source.

Connecting to the XML Data Source

Once we have all the prerequisites in place, we can start writing the Power Query M Language code to connect to our XML data source. Here is the code:



Source = XML.Tables(File.Contents(“C:pathtofile.XML“)),

#”Expanded Table1″ = Table.ExpandTableColumn(Source, “Table1”, {“Column1”, “Column2”, “Column3”}, {“Column1”, “Column2”, “Column3”})


#”Expanded Table1″

Let’s break down this code and understand what each part of it does.

The first line defines a variable called “Source” and uses the XML.Tables function to load the XML data from the specified file location. We need to replace the file path and name with the actual path to our XML file.

The second line uses the Table.ExpandTableColumn function to expand the “Table1” column in our XML data source and extract the values from the “Column1”, “Column2”, and “Column3” columns. We can replace “Table1”, “Column1”, “Column2”, and “Column3” with the actual names of the tables and columns in our XML data source.

The last line returns the expanded table.


In this article, we have learned how to use Power Query M Language code to connect to an XML data source from inside Power BI. We have also seen how to transform the data using the Table.ExpandTableColumn function. With this knowledge, we can now connect to and transform data from a wide variety of data sources using Power Query and Power BI.

Power BI Training Courses by G Com Solutions (0800 998 9248)

Contact Us


    Your Name (required)


    Email (required)


    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)

    Similar Posts