Binary.Buffer

D

T

The M Code Behind the Power Query M function Binary.Buffer

What is Binary.Buffer?

Binary.Buffer is a Power Query M function that allows you to cache the results of a query or subquery. The function takes a single argument, the query or subquery to cache, and returns a binary value that can be used to retrieve the cached results.

Here’s an example of how Binary.Buffer can be used in a query:


let

Source = Sql.Database("localhost", "MyDatabase"),

CachedQuery = Binary.Buffer(

Source{[Schema="dbo",Table="MyTable"]}[Data]

),

FilteredQuery = Table.SelectRows(

CachedQuery,

each [Column1] = "Value"

)

in

FilteredQuery


In this example, we’re using Binary.Buffer to cache the results of a SQL query. The CachedQuery variable contains the cached results, which we then filter using Table.SelectRows.

How Does Binary.Buffer Work?

When you use Binary.Buffer to cache a query or subquery, Power Query stores the results in memory. The function returns a binary value that represents the cached results. This binary value can be used to retrieve the cached results later on.

Here’s how the caching process works:

1. The query or subquery is executed and the results are stored in memory.

2. Binary.Buffer generates a binary value that represents the cached results.

3. The binary value is returned by Binary.Buffer and stored in memory.

4. Later on, when the cached results are needed, the binary value is passed to the Binary.Buffer function.

5. Binary.Buffer retrieves the cached results from memory using the binary value.

By caching the results of a query or subquery, you can avoid sending unnecessary queries to the data source. This can help improve the performance of your Power Query workflows.

Best Practices for Using Binary.Buffer

While Binary.Buffer can be a powerful tool for optimizing your Power Query workflows, it’s important to use it correctly. Here are some best practices for using Binary.Buffer:

1. Only use Binary.Buffer on queries or subqueries that are expensive to execute. Caching small queries can actually decrease performance.

2. Be aware of the amount of memory being used by cached queries. If you cache too many queries, it can negatively impact performance.

3. Use Binary.Buffer strategically. Caching queries that are used frequently can improve performance, while caching queries that are only used once may not provide any benefit.

4. Make sure to refresh cached queries periodically to ensure the data is up-to-date.

By following these best practices, you can use Binary.Buffer effectively to optimize the performance of your Power Query workflows.

In this article, we’ve explored the M code behind the Binary.Buffer function and how it can be used to optimize the performance of your Power Query workflows. By caching the results of expensive queries or subqueries, you can avoid unnecessary queries to the data source and improve the overall performance of your queries. Remember to use Binary.Buffer strategically and follow best practices to ensure optimal performance.

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)