Data Sources

M Folder Source

Loading Folder Data

M folder source uses Folder.Files for batch imports.

Introduction to M Folder Source

The M Folder Source is a powerful feature used in data transformation processes to handle batch imports of files. It utilizes the Folder.Files function to retrieve files from a specified directory, making it easier to automate and process multiple files simultaneously.

How Folder.Files Function Works

The Folder.Files function in M language is designed to return a table of all files within a specified folder. This table includes metadata such as file name, date modified, and size, which can be useful for filtering and organizing the files before processing.

Here's the basic syntax for using Folder.Files:

Practical Example: Batch Importing CSV Files

Let's consider a scenario where you need to import multiple CSV files from a folder and combine them into a single table for analysis. You can use Folder.Files to achieve this efficiently. Below is an example:

In this example, Folder.Files retrieves all files from the specified directory. Table.SelectRows is then used to filter out only the CSV files. Finally, Table.Combine and Table.TransformRows are used to read and combine the data from each CSV file into a unified table.

Handling Different File Types

While the example above focuses on CSV files, the Folder.Files function can be adapted to handle different file types by altering the filtering logic. For instance, to process Excel files, you might filter for files ending with .xlsx and use the appropriate M functions to read Excel data.

Previous
XML Source