{"id":3922,"date":"2022-01-13T16:40:56","date_gmt":"2022-01-14T00:40:56","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=3922"},"modified":"2022-01-13T16:40:58","modified_gmt":"2022-01-14T00:40:58","slug":"how-to-enable-assume-referential-integrity-to-speed-up-directquery","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=3922","title":{"rendered":"How to Enable &#8220;Assume referential integrity&#8221; to Speed Up DirectQuery"},"content":{"rendered":"\n<p>When connecting to a data source using&nbsp;<strong>DirectQuery<\/strong>, you can use the&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;selection to enable running more efficient queries against your data source. This feature has a few requirements of the underlying data, and it is only available when using&nbsp;<strong>DirectQuery<\/strong>.<\/p>\n\n\n\n<p>Setting&nbsp;<strong>Assume referential integrity<\/strong>&nbsp;enables queries on the data source to use&nbsp;<strong>INNER JOIN<\/strong>&nbsp;statements rather than&nbsp;<strong>OUTER JOIN<\/strong>, which improves query efficiency.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/media\/desktop-assume-referential-integrity\/assume-referential-integrity_1.png\" alt=\"Screenshot of an Edit Relationship dialog to select Assume referential integrity.\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"requirements-for-using-assume-referential-integrity\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/desktop-assume-referential-integrity#requirements-for-using-assume-referential-integrity\"><\/a>Requirements for using Assume referential integrity<\/h2>\n\n\n\n<p>This is an advanced setting, and is only enabled when connecting to data using&nbsp;<strong>DirectQuery<\/strong>. The following requirements are necessary for&nbsp;<strong>Assume referential integrity<\/strong>&nbsp;to work properly:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Data in the&nbsp;<strong>From<\/strong>&nbsp;column in the relationship is never&nbsp;<em>Null<\/em>&nbsp;or&nbsp;<em>blank<\/em><\/li><li>For each value in the&nbsp;<strong>From<\/strong>&nbsp;column, there is a corresponding value in the&nbsp;<strong>To<\/strong>&nbsp;column<\/li><\/ul>\n\n\n\n<p>In this context, the&nbsp;<strong>From<\/strong>&nbsp;column is the&nbsp;<em>Many<\/em>&nbsp;in a&nbsp;<em>One-to-Many<\/em>&nbsp;relationship, or it is the column in the first table in a&nbsp;<em>One-to-One<\/em>&nbsp;relationship.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-assume-referential-integrity\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/desktop-assume-referential-integrity#example-of-using-assume-referential-integrity\"><\/a>Example of using Assume referential integrity<\/h2>\n\n\n\n<p>The following example demonstrates how&nbsp;<strong>Assume referential integrity<\/strong>&nbsp;behaves when used in data connections. The example connects to a data source that includes an&nbsp;<strong>Orders<\/strong>&nbsp;table, a&nbsp;<strong>Products<\/strong>&nbsp;table, and a&nbsp;<strong>Depots<\/strong>&nbsp;table.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>In the following image that shows the&nbsp;<strong>Orders<\/strong>&nbsp;table and the&nbsp;<strong>Products<\/strong>&nbsp;table, note that referential integrity exists between&nbsp;<strong>Orders[ProductID]<\/strong>&nbsp;and&nbsp;<strong>Products[ProductID]<\/strong>. The&nbsp;<strong>[ProductID]<\/strong>&nbsp;column in the&nbsp;<strong>Orders<\/strong>&nbsp;table is never&nbsp;<em>Null<\/em>, and every value also appears in the&nbsp;<strong>Products<\/strong>&nbsp;table. As such,&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;should be set to get more efficient queries (using this setting does not change the values shown in visuals).<img decoding=\"async\" src=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/media\/desktop-assume-referential-integrity\/assume-referential-integrity_2.png\" alt=\"Screenshot of Orders table and Products table.\"><\/li><li>In the next image, notice that no referential integrity exists between&nbsp;<strong>Orders[DepotID]<\/strong>&nbsp;and&nbsp;<strong>Depots[DepotID]<\/strong>, because the&nbsp;<strong>DepotID<\/strong>&nbsp;is&nbsp;<em>Null<\/em>&nbsp;for some&nbsp;<em>Orders<\/em>. As such,&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;should&nbsp;<em>not<\/em>&nbsp;be set.<img decoding=\"async\" src=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/media\/desktop-assume-referential-integrity\/assume-referential-integrity_3.png\" alt=\"Screenshot of Orders table and Depots table.\"><\/li><li>Finally, no referential integrity exists between&nbsp;<strong>Orders[CustomerID]<\/strong>&nbsp;and&nbsp;<strong>Customers[CustID]<\/strong>&nbsp;in the following tables; the&nbsp;<strong>CustomerID<\/strong>&nbsp;contains some values (in this case,&nbsp;<em>CustX<\/em>) that do not exist in the&nbsp;<em>Customers<\/em>&nbsp;table. As such,&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;should&nbsp;<em>not<\/em>&nbsp;be set.<img decoding=\"async\" src=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/media\/desktop-assume-referential-integrity\/assume-referential-integrity_4.png\" alt=\"Screenshot of Orders table and Customers table.\"><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-assume-referential-integrity\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/desktop-assume-referential-integrity#setting-assume-referential-integrity\"><\/a>Setting Assume referential integrity<\/h2>\n\n\n\n<p>To enable this feature, select the checkbox next to&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;as shown in the following image.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/media\/desktop-assume-referential-integrity\/assume-referential-integrity_1.png\" alt=\"Screenshot of an Edit Relationship dialog that allows you to select Assume referential integrity.\"\/><\/figure>\n\n\n\n<p>When selected, the setting is validated against the data to ensure there are no&nbsp;<em>Null<\/em>&nbsp;or mismatched rows.&nbsp;<em>However<\/em>, for cases with a very large number of values, the validation is not a guarantee that there are no referential integrity issues.<\/p>\n\n\n\n<p>In addition, the validation occurs at the time of editing the relationship, and does&nbsp;<em>not<\/em>&nbsp;reflect any subsequent changes to the data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-happens-if-you-incorrectly-set-assume-referential-integrity\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/desktop-assume-referential-integrity#what-happens-if-you-incorrectly-set-assume-referential-integrity\"><\/a>What happens if you incorrectly set Assume referential integrity?<\/h2>\n\n\n\n<p>If you set&nbsp;<strong>Assume Referential Integrity<\/strong>&nbsp;when there are referential integrity issues in the data, this will not result in errors. However, it will result in apparent inconsistencies in the data. For example, in the case of the relationship to the&nbsp;<strong>Depots<\/strong>&nbsp;table described above, it would result in the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A visual showing the total\u00a0<em>Order Qty<\/em>\u00a0would show a value of 40<\/li><li>A visual showing the total\u00a0<em>Order Qty by Depot City<\/em>\u00a0would show a total value of only\u00a0<em>30<\/em>, because it would not include Order ID 1, where\u00a0<strong>DepotID<\/strong>\u00a0is\u00a0<em>Null<\/em>.<\/li><\/ul>\n\n\n\n<p>Ref: https:\/\/docs.microsoft.com\/en-us\/power-bi\/connect-data\/desktop-assume-referential-integrity<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When connecting to a data source using&nbsp;DirectQuery, you can use the&nbsp;Assume Referential Integrity&nbsp;selection to enable running more efficient queries against your data source. This feature has a few requirements of the underlying data, and it is only available when using&nbsp;DirectQuery. Setting&nbsp;Assume referential integrity&nbsp;enables queries on the data source to use&nbsp;INNER JOIN&nbsp;statements rather than&nbsp;OUTER JOIN, which <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=3922\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,621],"tags":[1046,1047],"class_list":["post-3922","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-power-bi","tag-assume-referential-integrity","tag-speed-up-directquery"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3922"}],"version-history":[{"count":1,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3922\/revisions"}],"predecessor-version":[{"id":3923,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3922\/revisions\/3923"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}