{"id":1974,"date":"2026-03-31T15:16:37","date_gmt":"2026-03-31T07:16:37","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=1974"},"modified":"2026-03-28T03:41:23","modified_gmt":"2026-03-28T03:41:23","slug":"how-to-use-applicationcalculateuntilasyncqueriesdone-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcalculateuntilasyncqueriesdone-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.CalculateUntilAsyncQueriesDone in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Application.CalculateUntilAsyncQueriesDone<\/code> property is a member of the Excel object model that provides control over the calculation process when asynchronous queries, such as those from Power Query (Get &amp; Transform Data), are involved. In scenarios where a workbook contains data connections that refresh asynchronously, Excel&#8217;s standard calculation might proceed before these queries have fully completed. This can lead to formulas returning results based on outdated or incomplete data. The <code>CalculateUntilAsyncQueriesDone<\/code> property addresses this by forcing Excel to pause further calculation until all pending asynchronous queries have finished refreshing. This ensures subsequent calculations operate on the complete, current dataset.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, you access this property through the <code>Application<\/code> object. The property is a read\/write Boolean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>xlwings API Syntax and Parameters<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The property is accessed directly on the <code>app<\/code> object (an instance of <code>xw.App<\/code>). There are no method parameters as it is a property, not a method.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Get the current value:<\/strong> <code>current_state = app.api.CalculateUntilAsyncQueriesDone<\/code><\/li>\n\n\n\n<li><strong>Set the value:<\/strong> <code>app.api.CalculateUntilAsyncQueriesDone = True<\/code> or <code>app.api.CalculateUntilAsyncQueriesDone = False<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Property Value:<\/strong><br>The property accepts and returns a Boolean value.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Value<\/th><th class=\"has-text-align-left\" data-align=\"left\">Meaning<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>True<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">Excel will wait for all asynchronous queries to complete before continuing with any pending calculations.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>False<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">(Default) Excel will not wait for asynchronous queries to finish; calculations may proceed with potentially stale query data.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Usage Example with xlwings<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A typical use case is to set this property to <code>True<\/code> before triggering a full workbook calculation or before running a macro that depends on the latest query data. It is good practice to restore the original setting afterward.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance or create a new one\napp = xw.apps.active\n\n# Store the original setting\noriginal_setting = app.api.CalculateUntilAsyncQueriesDone\nprint(f\"Original CalculateUntilAsyncQueriesDone setting: {original_setting}\")\n\ntry:\n    # Ensure Excel waits for async queries\n    app.api.CalculateUntilAsyncQueriesDone = True\n\n    # Refresh all data connections (queries)\n    app.api.ActiveWorkbook.RefreshAll()\n\n    # Now perform a full calculation. Excel will wait for RefreshAll to finish.\n    app.api.Calculate()\n\n    # Your code to work with the calculated data...\n    ws = app.api.ActiveSheet\n    print(f\"Value in A1 after refresh and calculation: {ws.Range('A1').Value}\")\n\nfinally:\n    # Restore the original setting\n    app.api.CalculateUntilAsyncQueriesDone = original_setting\n    print(f\"CalculateUntilAsyncQueriesDone restored to:      {app.api.CalculateUntilAsyncQueriesDone}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.CalculateUntilAsyncQueriesDone` property is a member of the Excel object model that&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1974","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=1974"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1974\/revisions"}],"predecessor-version":[{"id":3006,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1974\/revisions\/3006"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=1974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=1974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=1974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}