Table.ApproximateRowCount

D

T

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

Introduction to Power Query

Power Query is a data transformation and cleansing tool that is used to extract, transform, and load (ETL) data from a variety of sources. It is a part of Microsoft Excel and is also available as a separate add-in for Excel 2010 and 2013. Power Query allows you to transform and cleanse data from a variety of sources such as text files, Excel workbooks, databases, web pages, and more. Power Query is a part of the Power BI suite and is also integrated with other Microsoft products such as SharePoint, SQL Server, and Power Apps.

What is Table.ApproximateRowCount?

Table.ApproximateRowCount is a Power Query M function that returns an estimate of the number of rows in a table. This function is used to improve the performance of your Power Query queries by providing an estimate of the number of rows in a table before it is loaded into memory. This estimate is used to optimize the loading and transformation of data, which can significantly improve the performance of your queries.

How to use Table.ApproximateRowCount

To use Table.ApproximateRowCount, you need to provide a table or a reference to a table. The function then returns an estimate of the number of rows in the table. The syntax of the function is as follows:


Table.ApproximateRowCount(table as table) as number


The function takes a single argument, which is the table or a reference to the table. The function then returns an estimate of the number of rows in the table.

The following example demonstrates how to use Table.ApproximateRowCount in Power Query:


let

Source = Excel.Workbook(File.Contents("C:Sales.xlsx"), null, true),

Sales_Table = Source{[Item="Sales",Kind="Table"]}[Data],

RowCount = Table.ApproximateRowCount(Sales_Table)

in

RowCount


In the above example, the function is used to estimate the number of rows in a table named Sales. The function is invoked using the Table.ApproximateRowCount(Sales_Table) syntax, where Sales_Table is a reference to the Sales table.

How Table.ApproximateRowCount works

Table.ApproximateRowCount works by reading the metadata of the table to estimate the number of rows. The metadata of the table contains information such as the number of columns, column types, data types, and encoding. This information is used to estimate the number of rows in the table based on statistical models.

The function does not read the entire table to estimate the number of rows. Instead, it reads a sample of the table to estimate the number of rows. The size of the sample is determined by the size of the table and the complexity of the data. The function uses statistical models to estimate the number of rows in the table based on the sample data.

Benefits of using Table.ApproximateRowCount

There are several benefits of using Table.ApproximateRowCount in Power Query:

1. Improved performance – The function provides an estimate of the number of rows in the table before it is loaded into memory. This estimate is used to optimize the loading and transformation of data, which can significantly improve the performance of your queries.

2. Reduced memory usage – The function reduces the memory usage of your queries by providing an estimate of the number of rows in the table before it is loaded into memory. This estimate is used to optimize the loading and transformation of data, which can reduce the memory usage of your queries.

3. Better query optimization – The function provides an estimate of the number of rows in the table, which can be used to optimize the query plan. This can result in a better query execution plan and improved query performance.

Table.ApproximateRowCount is a powerful function in Power Query that can be used to improve the performance of your queries. The function provides an estimate of the number of rows in a table before it is loaded into memory, which can significantly improve the performance of your queries. By providing an estimate of the number of rows in the table, the function can also reduce the memory usage of your queries and improve query optimization. If you are working with large datasets in Power Query, it is recommended that you use Table.ApproximateRowCount to improve the performance of your queries.

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)