Table.FromPartitions

D

T

The M Code Behind the Power Query M function Table.FromPartitions

Understanding the Table.FromPartitions Function

The Table.FromPartitions function works by combining data from multiple partitions, which are essentially subsets of a larger dataset. This can be useful when working with data that is too large to handle in a single table, or when dealing with data that is stored in multiple files or databases.

To use Table.FromPartitions, you must first create a list of partitions that contain the data you want to merge. These partitions can be generated using the Table.Partition function, which splits a larger dataset into smaller, manageable pieces.

Once you have your list of partitions, you can use the Table.FromPartitions function to combine them into a single table. The resulting table will contain all of the data from all of the partitions, allowing you to work with a complete dataset without having to manually merge individual tables.

Writing the M Code for Table.FromPartitions

To write the M code for Table.FromPartitions, you must first define your list of partitions. This can be done using the Table.Partition function, as mentioned earlier.

For example, suppose you have a dataset that is stored in two separate CSV files. You could create a list of partitions using the following M code:


let

Source1 = Csv.Document(File.Contents("C:Datafile1.csv"),[Delimiter=",", Encoding=1252, QuoteStyle=QuoteStyle.None]),

Source2 = Csv.Document(File.Contents("C:Datafile2.csv"),[Delimiter=",", Encoding=1252, QuoteStyle=QuoteStyle.None]),

Partition1 = Table.Partition(Source1, "PartitionColumn", [1,2,3]),

Partition2 = Table.Partition(Source2, "PartitionColumn", [4,5,6]),

Partitions = {Partition1, Partition2}

in

Partitions


In this example, we first use the Csv.Document function to load the contents of each CSV file into a table. We then create two partitions using the Table.Partition function, specifying which rows to include in each partition based on the value of a specific column (“PartitionColumn” in this case).

Once we have our list of partitions, we can use the Table.FromPartitions function to combine them into a single table:


let

Source1 = Csv.Document(File.Contents("C:Datafile1.csv"),[Delimiter=",", Encoding=1252, QuoteStyle=QuoteStyle.None]),

Source2 = Csv.Document(File.Contents("C:Datafile2.csv"),[Delimiter=",", Encoding=1252, QuoteStyle=QuoteStyle.None]),

Partition1 = Table.Partition(Source1, "PartitionColumn", [1,2,3]),

Partition2 = Table.Partition(Source2, "PartitionColumn", [4,5,6]),

Partitions = {Partition1, Partition2},

CombinedTable = Table.FromPartitions(Partitions)

in

CombinedTable


The resulting table will contain all of the data from both CSV files, merged into a single table.

The Table.FromPartitions M function is a powerful tool for working with large datasets in Power Query. By combining data from multiple partitions into a single table, users can automate data processing tasks and work with complete datasets without having to manually merge individual tables.

To use Table.FromPartitions, you must first create a list of partitions using the Table.Partition function. You can then use the Table.FromPartitions function to merge these partitions into a single table. With this M code, you can work with large datasets efficiently and effectively in Power Query.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)