{"id":90891,"date":"2021-05-11T17:00:12","date_gmt":"2021-05-11T17:00:12","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=90891"},"modified":"2024-09-03T20:15:20","modified_gmt":"2024-09-03T20:15:20","slug":"power-query-transforming-desktop-queries-in-dataflows","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/power-query-transforming-desktop-queries-in-dataflows\/","title":{"rendered":"Power Query: Transforming Desktop Queries in Dataflows"},"content":{"rendered":"<p>.There are some interesting ways to transform queries from Power BI Desktop to Power BI dataflows in the portal.<\/p>\n<p>The UI can be a bit confusing. I made some mistakes in the middle as well. Let\u2019s see some options to make the conversion.<\/p>\n<h2>Leaving Blank Query Blank<\/h2>\n<ol>\n<li>Create a new dataflow<\/li>\n<li>Select Blank Query as the source<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"986\" height=\"173\" class=\"wp-image-90892\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-59.png\" \/><\/p>\n<ol>\n<li>Select the gateway used to access the on premise servers<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"169\" class=\"wp-image-90893\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-60.png\" \/><\/p>\n<p>It seems strange to select a gateway for a blank query. This makes the UI a bit confusing. However, the gateway will be set for the entire dataflow, not only for the blank query<\/p>\n<ol>\n<li>On Power BI Desktop, copy the query you would like to convert<\/li>\n<li>Use CTRL+V on the keyboard to past the query to the Query Window, inside the dataflow<\/li>\n<li>Click the button <em>Configure Connection<\/em> to define the credential for the query<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"951\" height=\"102\" class=\"wp-image-90894\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-61.png\" \/><\/p>\n<p>Since you already selected the gateway, if the server and database name are configured with the same case as in the gateway, Power BI will recover the authentication information from the gateway automatically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"479\" class=\"wp-image-90895\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-62.png\" \/><\/p>\n<p>If the case of server and database name is different, it\u2019s better to edit the code first, ensure the case of the server and database name are correct and define the credential later.<\/p>\n<p>If you left the gateway empty, you may notice the button <em>Configure Credential<\/em> will not recognize the gateway neither leave you an option to choose it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"481\" class=\"wp-image-90896\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-63.png\" \/><\/p>\n<p>After having reach the query editor, if you need to change the gateway it needs to be done on the dataflow level. On the menu, <em>Home -&gt; Options -&gt; Project Options<\/em> allows you to set the gateway<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"227\" class=\"wp-image-90897\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-64.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"492\" class=\"wp-image-90898\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-65.png\" \/><\/p>\n<h2>Blank Query for a single Query<\/h2>\n<p>If you would like to convert a single query, you don\u2019t need to get into the query editor. This small secret seems so simple, but it\u2019s not so obvious.<\/p>\n<p>Once you select the Blank Query as source, you can past your query from the Power BI desktop in the code area. Power BI will be responsible to understand what you are pasting and will include the code of your query.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"246\" class=\"wp-image-90899\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-66.png\" \/><\/p>\n<p>You still need to define the gateway on the option for this on the same screen.<\/p>\n<h2>Blank Query for Multiple Queries<\/h2>\n<p>This is a combination of the previous methods and there are two ways to do it:<\/p>\n<ol>\n<li>First method: add a dummy blank query and past the desktop queries on the editor later. You have the option to choose the gateway for the blank query or configure the gateway later, on the project options for the dataflow<\/li>\n<li>Second method: create a useful first query, choosing one of your on-premise queries, anyone, and past it on the code area of the first blank query. Then you past the rest on the query area, inside the query editor. You will need to choose the gateway for the first query.<\/li>\n<\/ol>\n<h2>Web Source<\/h2>\n<p>The message you receive when migrating one query using web source from the desktop to a dataflow may appear to be different, but it\u2019s very simple: The Web source requires a gateway. You need to have a gateway with the Web source configured so it will work inside a data flow as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"87\" class=\"wp-image-90900\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-67.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"753\" height=\"359\" class=\"wp-image-90901\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-68.png\" \/><\/p>\n<h2>Functions<\/h2>\n<p>When we copy a query using custom M functions, Power BI copy the function as well.<\/p>\n<p>Power BI Desktop organizes the functions in folders and for each function we have one query. We can edit the query visually without touching the function code.<\/p>\n<p>In the dataflow, on the other hand, only the function is copied. Any future edit will need to be made on the function code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"378\" height=\"132\" class=\"wp-image-90902\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-69.png\" \/><\/p>\n<p>One additional detail: On the desktop, we disable the load of the function query and it works fine. In a dataflow, the function will be imported with <em>Enable Load<\/em> activated and we probably would like to disable it.<\/p>\n<p>In fact, if we don\u2019t disable it, the query using the functions may become a computed table, making the refresh only available on premium. Once we disable the load of the functions, the table becomes a regular query and the refresh may be allowed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"395\" height=\"210\" class=\"wp-image-90903\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-70.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"143\" class=\"wp-image-90904\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-71.png\" \/><\/p>\n<h2>\nExternal Tool<\/h2>\n<p>Marcus Wegener <a href=\"https:\/\/twitter.com\/PowerBIler\">(@PowerBIler<\/a>) created an external tool which exports all queries from a power BI file and allow us to import as a dataflow.<\/p>\n<p>The tool exports the queries as a JSON file. We will be able to use the option <em>Import Model<\/em> to create a new dataflow on the portal<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"253\" height=\"365\" class=\"wp-image-90905\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-72.png\" \/><\/p>\n<p>The external tool is included in the <a href=\"https:\/\/powerbi.tips\/product\/business-ops\/\">Business Ops<\/a> tool, which help us to install many very interesting and important external tools in Power BI at once.<\/p>\n<p>There are some differences between the tool and the simple copy and paste, especially in relation to the validation of the query. Anyway, I\u2019m still trying to understand to what scenario each one will be better.<\/p>\n<h2>Conclusion<\/h2>\n<p>Although everything starts with a Copy\/Paste, transferring Power BI queries from desktop to the portal has some tricks and secrets.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.There are some interesting ways to transform queries from Power BI Desktop to Power BI dataflows in the portal. The UI can be a bit confusing. I made some mistakes in the middle as well. Let\u2019s see some options to make the conversion. Leaving Blank Query Blank Create a new dataflow Select Blank Query as&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,159166],"tags":[4472,101611,143554],"coauthors":[6810],"class_list":["post-90891","post","type-post","status-publish","format-standard","hentry","category-blogs","category-powerbi","tag-dataflow","tag-power-bi","tag-power-query"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/90891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=90891"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/90891\/revisions"}],"predecessor-version":[{"id":90906,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/90891\/revisions\/90906"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=90891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=90891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=90891"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=90891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}