Progress.DataSourceProgress

D

T

The M Code Behind the Power Query M function Progress.DataSourceProgress

In this article, we will explore the M code behind the Progress.DataSourceProgress function, which is used to monitor the progress of data loading operations in Power Query.

What is Progress.DataSourceProgress?

Progress.DataSourceProgress is a Power Query M function that returns a record with information about the progress of a data loading operation. This function is typically used within custom functions or scripts to monitor the progress of a data load and to provide feedback to the user.

The record returned by Progress.DataSourceProgress contains the following fields:

– CurrentByteCount: The number of bytes that have been loaded so far.

– TotalByteCount: The total number of bytes that need to be loaded.

– IsDataAvailable: A Boolean value that indicates whether data is available for processing.

– IsDone: A Boolean value that indicates whether the data loading operation is complete.

– Message: A text message that describes the current state of the data loading operation.

How to use Progress.DataSourceProgress

To use Progress.DataSourceProgress, you need to include it in your custom functions or scripts. Here is an example of how to use Progress.DataSourceProgress to monitor the progress of a data loading operation:


let

Source = Excel.Workbook(File.Contents(“C:SalesData.xlsx”), null, true),

SalesData_Table = Source{[Item=”SalesData”,Kind=”Table”]}[Data],

ProgressMonitor = (Current, Total) =>

let

Progress = Progress.DataSourceProgress(),

Message = “Loading SalesData (” & Text.From(Progress[CurrentByteCount]) & ” of ” & Text.From(Progress[TotalByteCount]) & ” bytes)”

in

if Progress[IsDone] then

Message & ” – Done.”

else

Message,

#”Invoked Custom Function With Progress Monitor” = Table.TransformColumns(SalesData_Table, {“SalesAmount”, each ProgressMonitor(_, Table.RowCount(SalesData_Table))})

in

#”Invoked Custom Function With Progress Monitor”


In this example, we load the SalesData table from an Excel workbook and then apply a custom function called ProgressMonitor to the SalesAmount column. The ProgressMonitor function uses Progress.DataSourceProgress to monitor the progress of the data loading operation and provides feedback to the user.

Understanding the M code behind Progress.DataSourceProgress

To understand how Progress.DataSourceProgress works, let's take a closer look at the M code behind this function:


() =>

let

Progress = [CurrentByteCount = 0, TotalByteCount = 0, IsDataAvailable = false, IsDone = false, Message = “”],

InternalStepSize = 32 1024,

InternalCurrentByteCount = Extension.CurrentByteCount,

InternalTotalByteCount = Extension.TotalByteCount,

InternalIsDataAvailable = Extension.IsDataAvailable,

InternalIsDone = Extension.IsDone,

InternalMessage = Extension.Message

in

[

CurrentByteCount = if InternalCurrentByteCount <> null then InternalCurrentByteCount else Progress[CurrentByteCount],

TotalByteCount = if InternalTotalByteCount <> null then InternalTotalByteCount else Progress[TotalByteCount],

IsDataAvailable = if InternalIsDataAvailable <> null then InternalIsDataAvailable else Progress[IsDataAvailable],

IsDone = if InternalIsDone <> null then InternalIsDone else Progress[IsDone],

Message = if InternalMessage <> null then InternalMessage else Progress[Message]

]


The Progress.DataSourceProgress function is a function that takes no arguments and returns a record. The record is initialized with default values for each field using a let statement.

The function then retrieves the current progress values from the Extension object, which is an instance of the internal Power Query object model. The InternalStepSize variable is used to specify the size of the data chunks that are loaded during the data loading operation.

The function then updates the progress record with the current progress values retrieved from the Extension object. If any of the progress values are null, then the default values from the Progress record are used instead.

In conclusion, the Progress.DataSourceProgress function is a powerful tool that can be used to monitor the progress of data loading operations in Power Query. By including this function in your custom functions and scripts, you can provide feedback to the user and ensure that your data loading operations are running smoothly.

Understanding the M code behind the Progress.DataSourceProgress function is important for any Power Query user who wants to write custom functions and scripts. By studying the code and experimenting with different values, you can gain a deeper understanding of how Power Query works and how you can use it to transform and analyze your data.

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)