{"id":94302,"date":"2022-05-25T21:00:23","date_gmt":"2022-05-25T21:00:23","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=94302"},"modified":"2022-05-24T15:45:26","modified_gmt":"2022-05-24T15:45:26","slug":"datamarts-and-exploratory-analysis-using-power-bi","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/datamarts-and-exploratory-analysis-using-power-bi\/","title":{"rendered":"Datamarts and exploratory analysis using Power BI"},"content":{"rendered":"<p><strong>Power BI Datamarts<\/strong> is an important new feature announced during BUILD. This new feature expands <strong>Power BI<\/strong> possibilities in directions which may be unexpected to many <strong>Power BI<\/strong> users. Next, discover more about what this means for <strong>Power BI<\/strong> users and developers.<\/p>\n<h2>What\u2019s a single source of truth?<\/h2>\n<p>Before explaining Datamarts, I will need to start from the beginning. Every company needs a single source of truth.<\/p>\n<p>Could you imagine if, when checking the total of active customers in the company, one e-mail report has a number, one Power BI dashboard has a different number, and the production database has a third one?<\/p>\n<p>In my country we have an old saying \u201cWho has one watch knows the time, who has two watches only knows the average\u201d. Every company needs to be sure to have a single watch and keep it always on time. A single source of truth.<\/p>\n<p>Data warehouses are one implementation of this single source of truth. It\u2019s beyond the <strong>Power BI<\/strong> work. <strong>ETL<\/strong> is used to extract data from all production databases to a Data Warehouse. <strong>Power BI<\/strong> uses the Data Warehouse as a source and becomes the serving layer for the company\u2019s data platform.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94303\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/diagram-description-automatically-generated-2.png\" alt=\"Image showing data starts at several data sources, moves to Data Factory for Ingestion, moves to Data Lake House, to Data Models and Reporting and Analysis\" width=\"1280\" height=\"684\" \/><\/p>\n<p>This is a good practice. It\u2019s not always followed or a technical requirement, but it\u2019s a good practice. I wrote before about the relation between <strong>ETL<\/strong> and <strong>Power BI<\/strong> in this other article: <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/power-bi-etl-or-not-etl-thats-the-question\/\">https:\/\/www.red-gate.com\/simple-talk\/blogs\/power-bi-etl-or-not-etl-thats-the-question\/<\/a><\/p>\n<h2>What\u2019s a data mart?<\/h2>\n<p>According to its theorical definition, a data mart is a subset of the data warehouse. A data warehouse can contain complex structures, such as slowly changing dimensions (also know as dimension type 2). These structures are not simple to be used by an end user.<\/p>\n<p>These complex structures hold important historical information which can be useful, but most users will need more focused information. That\u2019s where the data marts come to the rescue.<\/p>\n<p>A data mart can be a more focused and more user-friendly set of data, extracted from the data warehouse and prepared for the end user. 90% of the time the user requirements will be fulfilled by dashboards and reports created from the data mart. But there is also those 10% of questions which appear out of the blue from a CEO request. These questions may require an exploratory analysis over the data mart or even the data warehouse. That\u2019s why there is the old saying \u201cA data warehouse doesn\u2019t have a response time, but a delivery time\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94304\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/a-picture-containing-text-clipart-screenshot-de.jpeg\" alt=\"Image showing Data Warehouse vs Data Mart\" width=\"612\" height=\"290\" \/><\/p>\n<p>Power BI, working as a serving layer, can use a data warehouse or a data mart as a source. More than that, many people, including me, would consider Power BI as a tool to build data marts using a data warehouse as a source.<\/p>\n<h2>Exploratory analysis vs explanatory analysis<\/h2>\n<p>You may have heard before about how Story Telling knowledge is important to build <strong>Power BI<\/strong> reports. It is. That\u2019s because <strong>Power BI <\/strong>reports are very powerful for explanatory analysis.<\/p>\n<p>You start with the data. A lot of historical data inside the company data warehouse. From this data, conclusions need to be made and call to actions based on these conclusions need to be defined. Once conclusions are made, the reports are the tool used to explain it to the end users, convincing them about your conclusions.<\/p>\n<p>Using <strong>Power BI<\/strong> reports, you can make explanatory analysis in <strong>Power BI<\/strong> applying story telling techniques. But what about exploratory analysis? What can <strong>Power BI<\/strong> offer for exploratory analysis? Explore the possibilities next.<\/p>\n<h2>Exploring data with Power BI interactive reports<\/h2>\n<p>As you may know, <strong>Power BI<\/strong> reports are interactive. The user can view the reports in different ways, in different points of view.<\/p>\n<p>The question you may need to ask is: Are the interactive reports enough for exploratory analysis?<\/p>\n<p>I will use some concepts from books about story telling to try to answer this question. I like one analogy from one specific book. Exploratory analysis is the work of opening 100 oysters to find 1 pearl. Explanatory analysis is the work of explaining about that pearl to your users. It\u2019s a bad practice to provide the users with the 100 oysters and leave to them the work to find the pearl.<\/p>\n<p>However, while studying storytelling, you also need to know your users. You tell stories to your end user, such as a businessman who wants to know what\u2019s hidden in the middle of the data. But if your user is a data analyst whose responsibility is to explore the data and find new possibilities, this guy will need to see the 100 oysters and find the pearl by himself.<\/p>\n<p>There are many tricks to achieve this. Creating dynamic measures on the visuals, allowing the user to change the measure in the visual, creating dynamic hierarchies and much more.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94305\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-description-automaticall.jpeg\" alt=\"Image showing Power BI vs Excel\" width=\"612\" height=\"290\" \/><\/p>\n<p>In my humble opinion, with a good amount of work you can fulfil the user needs up to a point. But you know your users need more when the users keep asking you to receive the data in Excel. This is how the users tell you they want more exploratory power over the data.<\/p>\n<h2>Power BI building tools<\/h2>\n<p>Before building a report, you need to import data and build a model. You can use <strong>Power Query<\/strong> to import data with an entire language for this, the <strong>M<\/strong> language. For the model, there is <strong>DAX<\/strong> to build measures.<\/p>\n<p>These tools focus is to build a model and from there build a story. However, they can be used for exploratory analysis. <strong>Power Query<\/strong> can be used to build different transformations on the source and check the results. You can build, edit, drop, build again, the entire back-and-forth of an exploratory analysis. The same can be done with <strong>DAX<\/strong> measures. You can create, change, adjust, in such a way to explore the existing data and discovering what\u2019s needed.<\/p>\n<p>Besides these tools, there are also an <strong>R<\/strong> visual and a <strong>Python<\/strong> visual, both allowing analysis of data using these languages.<\/p>\n<p>All these tools enable using <strong>Power BI<\/strong> for exploratory analysis. However, is this analysis so easy as something done directly in <strong>SQL<\/strong>, <strong>Python <\/strong>or <strong>R<\/strong> over the data source?<\/p>\n<p>In my humble opinion, using these tools for exploratory analysis is possible, but it\u2019s a work around. That\u2019s what is about to change with the use of <strong>Power BI Datamarts.<\/strong><\/p>\n<h2>Bottom-UP design<\/h2>\n<p>Building a data warehouse, data marts and using <strong>Power BI<\/strong> as the serving layer is a state-of-the-art scenario, but you don\u2019t always have the option to build it this way.<\/p>\n<p>Many times, the data is spread among many different data sources. Sometimes these data sources can be set of Excel files, SharePoint lists or many other data sources which would make the <strong>ETL<\/strong> process more complex.<\/p>\n<p>These data sources, using technologies built for modest sized data, will start to grow and will create problems during their growth.<\/p>\n<p>This is the kind of scenario where building a data warehouse can happen in the reverse order: You start building small data marts, using the data sources and resources you have available. Later, you can merge these data marts into a single data warehouse. This is called a bottom-up design.<\/p>\n<p>Building a data warehouse is a challenge regardless of top-down or bottom-up design. When using the bottom-up architecture, the risk is to end up with many data marts that can\u2019t be merged, because they don\u2019t fit in a bigger scenario. It\u2019s like a puzzle. Working on isolated pieces without a view of the entire image may result in pieces that don\u2019t match.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94306\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/logo-description-automatically-generated.png\" alt=\"Image showing Top Down vs Bottom Up\" width=\"800\" height=\"575\" \/><\/p>\n<p>Once again, the Datamart feature in <strong>Power BI<\/strong> can help with the bottom-up scenario. When you face the need to retrieve the data from many disconnected and not so trustworthy sources, you can use the Datamarts in Power BI as a starting point to consolidate the data sources.<\/p>\n<h2>What\u2019s Power BI Datamarts?<\/h2>\n<p><strong>Power BI Datamart<\/strong> is a new feature announced in public preview during Microsoft BUILD. This feature requires the use of <strong>Power BI Premium<\/strong> or <strong>Premium Per User (PPU)<\/strong>.<\/p>\n<p>The Datamart uses an underlying <strong>Azure SQL Database<\/strong> to store its data. This creates very powerful possibilities. When creating a Datamart, you can import the data from many different sources to this <strong>Azure SQL Database<\/strong> using <strong>Power Query<\/strong>. The Datamart will also automatically create and manage a dataset linked to the internal <strong>Azure SQL Database<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94307\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/diagram-description-automatically-generated-3.png\" alt=\"Image showing data flowing from sources to Data Mart to SQL to Dataset\" width=\"1160\" height=\"703\" \/><\/p>\n<p>Some architectural details:<\/p>\n<ul>\n<li>The dataset model is built on the <strong>Datamart<\/strong><\/li>\n<li>Renaming the Datamart renames the dataset<\/li>\n<li>The tables in the dataset use direct query but have support for caching, which is done transparently for us<\/li>\n<li>It also supports dataflows as sources<\/li>\n<li>You have limited control over the settings of the dataset<\/li>\n<li>You have very limited control over the underlying <strong>Azure SQL Database<\/strong>. It\u2019s provisioned by <strong>Power BI<\/strong>.<\/li>\n<\/ul>\n<p>After learning about the architecture, here are the main features you can expect from the Power BI Datamart:<\/p>\n<ul>\n<li>It provides a UI to build a data mart in the portal<\/li>\n<li>This UI is basically the use of <strong>Power Query<\/strong> to import data. The portal doesn\u2019t support the use of <strong>Power Query<\/strong> with datasets, you need to use <strong>Power BI<\/strong> desktop.<\/li>\n<li>Using <strong>Datamarts,<\/strong> you can build <strong>Power Query ETLs<\/strong> using the portal. The data imported by <strong>Power Query<\/strong> will be saved in the <strong>Azure SQL Database<\/strong><\/li>\n<li>You can build a model using the imported tables.<\/li>\n<li>You can define relationships, create measures, and configure the attributes and tables.<\/li>\n<li>The UI provides additional resources for exploratory analysis<\/li>\n<li>The Datamart UI provides data exploration features<\/li>\n<\/ul>\n<p>There are two new tabs, one for query design, another one for <strong>SQL<\/strong>. On both tabs you can explore the data to discover useful information in your data.<\/p>\n<p>The UI also allows you to download the query results to Excel, to expand the exploratory analysis possibilities<\/p>\n<ul>\n<li>Support for incremental refresh<\/li>\n<\/ul>\n<p>Incremental refresh is essential for big tables, and they are expected in a data mart. The configuration is very similar to the incremental refresh configuration you may already know, but the data is being inserted in the <strong>Azure SQL Database<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94308\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description.png\" alt=\"Image showing the incremental refresh dialog\" width=\"468\" height=\"710\" \/><\/p>\n<ul>\n<li>Support for role-based permissions configuration<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94309\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-1.png\" alt=\"Image showing the Row security settings\" width=\"1156\" height=\"720\" \/><\/p>\n<ul>\n<li>Integrated with <strong>Power BI Deployment Pipelines<\/strong><\/li>\n<li>Datamarts allow a read-only connection to the <strong>Azure SQL Database<\/strong>. This is probably the most powerful tool for exploratory analysis<\/li>\n<\/ul>\n<p>To understand this new feature, implement a Datamart step-by-step.<\/p>\n<p><strong>Important:<\/strong> The new Power BI feature is called \u201cDatamart\u201d, while the theoretical concept is called \u201cData mart\u201d.<\/p>\n<h2>Implementing a Power BI Datamart<\/h2>\n<p>This will be the starting point:<\/p>\n<ul>\n<li>An <strong>Azure SQL Database<\/strong> using the sample <em>AdventureWorskLT<\/em><\/li>\n<li>You need to execute the script <em>Make_big_adventure.SQL<\/em> adapted for the <em>AdventureWorksLT<\/em>. You can find it on <a href=\"https:\/\/github.com\/DennesTorres\/BigAdventureAndQSHints\/blob\/main\/make_big_adventureLT.sql\">https:\/\/github.com\/DennesTorres\/BigAdventureAndQSHints\/blob\/main\/make_big_adventureLT.sql<\/a><\/li>\n<li>You need a premium Power BI workspace, either premium by capacity or premium per user<\/li>\n<li>Recommendation: The <strong>Azure SQL Database<\/strong> is recommended to have 10 DTU\u2019s or more. Less than that and some slowness may be noticed<\/li>\n<li>Recommendation: If you create a non-clustered index on the table <em>BigTransactionhistory<\/em>, column <em>TransactionDate<\/em>, the access to the database will be faster.<\/li>\n<\/ul>\n<p>After preparing the environment, it\u2019s time to start to build the Datamart.<\/p>\n<h2>Creating the Datamart: First stage, importing the tables<\/h2>\n<ol>\n<li>In the premium workspace, click <em>New<\/em> button and select the <em>Datamart<\/em> menu item<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94310\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr.png\" alt=\"An image showing the New menu with Datamart (Preview) selected\" width=\"342\" height=\"720\" \/><\/p>\n<ol start=\"2\">\n<li>On the Datamart design window, click the <em>Import data from SQL Server<\/em> image in the centre of the screen<\/li>\n<\/ol>\n<p>Mind you also have options for <em>Excel<\/em> and <em>Dataflows<\/em> highlighted, but you also can use the <em>Get Data<\/em> button and use different kinds of data sources<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94311\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-website-de.png\" alt=\"An image showing the Start building your datamat dialog. You can start with SQL Server, Excel, or Datflow\" width=\"1280\" height=\"600\" \/><\/p>\n<ol start=\"3\">\n<li>In the <em>Connect To Data Source<\/em> window, fill the <em>Server<\/em> textbox with the address of your <strong>Azure SQL Database<\/strong><\/li>\n<li>On the <em>Connect To Data Source<\/em> window, fill the <em>Database <\/em>textbox with the database name<\/li>\n<li>On the <em>Connect To Data Source<\/em> window, fill the user name and password with the <em>Azure SQL Authentication<\/em><\/li>\n<\/ol>\n<p>If your data source were on premises, you could use a gateway for it, but in this case, it\u2019s not needed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94312\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-table-desc.png\" alt=\"A dialog showing the connection properties to the database\" width=\"848\" height=\"645\" \/><\/p>\n<ol start=\"6\">\n<li>Click <em>Next<\/em> button<\/li>\n<li>On the <em>Power Query<\/em> window, under <em>Choose Data<\/em>, select the tables you will include in your Datamart. In this example, include<em> bigTransactionHistory<\/em>, <em>bigProduct<\/em> and <em>SalesLT.ProductModel<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94313\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-1.png\" alt=\"A dialog showing the Power Query Choose data list. SalesLT.ProductModel, bigProduct and bitTransactionHistory are selected\" width=\"376\" height=\"720\" \/><\/p>\n<ol start=\"8\">\n<li>Click the <em>Transform data<\/em> button<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"352\" height=\"60\" class=\"wp-image-94314\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/a-picture-containing-graphical-user-interface-des.png\" alt=\"A picture containing graphical user interface\n\nDescription automatically generated\" \/><\/p>\n<ol start=\"9\">\n<li>On the <em>Power Query<\/em> window, under <em>Queries<\/em>, click the table <em>bigProduct<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94315\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-2.png\" alt=\"An image showing Queries [3] bigProduct, bigTransactionHistory, and SalesLT ProductModel\" width=\"248\" height=\"168\" \/><\/p>\n<ol start=\"10\">\n<li>On the <em>Query Settings<\/em> tab, rename it to <em>Product<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94316\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-2.png\" alt=\"An image showing the Query settings Properties Name bigProduct. Applied steps source, Navigation1\" width=\"243\" height=\"263\" \/><\/p>\n<ol start=\"11\">\n<li>Repeat the steps to rename the table <em>bigTransactionHistory<\/em> to <em>TransactionHistory<\/em><\/li>\n<li>Select the <em>Product table<\/em><\/li>\n<li>Select the columns <em>Size<\/em>, <em>Weight<\/em>, <em>SellStartDate<\/em>, <em>SellEndDate<\/em> and <em>DiscontinuedDate<\/em><\/li>\n<li>Use the button <em>Remove Column<\/em> to remove the unneeded columns<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94317\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-table-word.png\" alt=\"An image showing the column view and removing a column\" width=\"1076\" height=\"348\" \/><\/p>\n<ol start=\"15\">\n<li>Right-click the table <em>SalesLT ProductModel<\/em><\/li>\n<li>Disable the option <em>Enable Load<\/em><\/li>\n<\/ol>\n<p>You will merge the information about the product model with the product details. You don\u2019t need the <em>ProductModel<\/em> table as part of the model. When the Enable Load is disabled, the name of the table appears in <em>Italic<\/em> among the queries<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94318\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-3.png\" alt=\"An image showing SalesLT ProductModel and right-click menu with Enable load selected\" width=\"313\" height=\"566\" \/><\/p>\n<ol start=\"17\">\n<li>Select the table <em>Product<\/em><\/li>\n<li>Click the <em>Merge queries<\/em> button<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94319\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-1.png\" alt=\"An image showing the choices Merge queries and Merge queries as new\" width=\"254\" height=\"121\" \/><\/p>\n<ol start=\"19\">\n<li>On the <em>Merge<\/em> window, on the <em>Right table for merge<\/em>, select the table <em>SalesLT ProductModel<\/em><\/li>\n<li>On the<em> Merge<\/em> window, <em>Product<\/em> table, select the <em>ProductModelID<\/em> field<\/li>\n<li>On the <em>Merge<\/em> window, <em>SalesLT ProductModel<\/em> table, select the <em>ProductModelID<\/em> table<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94320\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated.png\" alt=\"An image showing the Merge dialog. Select a table and matching columns to create a merged table. Product table with several rows returned. Right table for Merge SalesLT ProductModel. Join kind Left outer\" width=\"692\" height=\"720\" \/><\/p>\n<ol start=\"22\">\n<li>Once the match message appears in a green bar on the lower side of the window, click the <em>Ok<\/em> button<\/li>\n<li>On the new <em>SalesLT ProductModel<\/em> column, click the expand button<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94321\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-1.png\" alt=\"Image showing the SalesLT ProductModel and expand button\" width=\"199\" height=\"238\" \/><\/p>\n<ol start=\"24\">\n<li>On the window opened from the expand button, select the <em>Name<\/em> field, and uncheck all the others<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94322\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-2.png\" alt=\"Image showing the columns ListPrice ProductModelId and table SalesLT ProductModel under that Name is selected\" width=\"435\" height=\"426\" \/><\/p>\n<ol start=\"25\">\n<li>Click the <em>OK<\/em> button<\/li>\n<li>Double click the <em>Name.1<\/em> column header and change the name to <em>ProductModel<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94323\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-2.png\" alt=\"Image showing where to change the column name\" width=\"195\" height=\"180\" \/><\/p>\n<p>All the steps executed so far are registered on the properties window, <em>Applied Steps<\/em>. This is exactly how <strong>Power Query<\/strong> works, but until now this experience was available only on dataflows or in Power BI desktop.<\/p>\n<p>One important performance detail about the steps is to know if the steps will be executed in the source database, converted into a single native query on the source database, or if the sequence of transformations prevent this.<\/p>\n<p>The usual way to check this is to right click the last transformation and check if the option <em>View Data Source Query<\/em> is available. If it\u2019s available, it means the transformations are good enough to be executed as a single native query.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94324\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-4.png\" alt=\"Image showing query settings and how to View data source query\" width=\"452\" height=\"667\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94325\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/text-description-automatically-generated.png\" alt=\"An image showing the data source query\" width=\"833\" height=\"456\" \/><\/p>\n<p>The UI in the portal has some additional features beyond the desktop UI. If you move the mouse over the last step, it tells you how the step will be executed. You can see the same on every step.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94326\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-5.png\" alt=\"An image showing This step will be evaluated by the data source\" width=\"607\" height=\"262\" \/><\/p>\n<h2>Creating the Datamart: Second stage, creating a date dimension<\/h2>\n<p>A model needs a date dimension. Every fact happens on a date and the date is an important dimension to analyse the fact. In this example, the <em>TransactionDate<\/em> column is found in the <em>TransactionHistory<\/em> table.<\/p>\n<p>Why is the <em>TransactionDate<\/em> field is not enough, you may ask.<\/p>\n<p>When analysing the facts, it might be analyzed by Year, Month, Day, Day of the week, and much more. If relying only on the <em>TransactionDate<\/em> field, you will need to create <strong>DAX<\/strong> measures, and this would impact the performance of your model.<\/p>\n<p>Building a date dimension, which will be stored in the underlying <strong>Azure SQL Database<\/strong> for the Datamart, you will not have the need to build so many <strong>DAX<\/strong> expressions and the model will have better performance.<\/p>\n<p>You could say there is a \u201cnot so old saying\u201d about this: The better the underlying model, the fewer custom <strong>DAX<\/strong> expressions will be needed to build in the model. The date dimension is one great example of this, and the Datamart brings the possibility to create a better underlying model, leaving the <strong>DAX<\/strong> expressions only for dynamic calculations which really can\u2019t be created in the underlying model.<\/p>\n<p>There are many different methods to create a date dimension. In this example, I will use the M scrips created by Chris\u00a0Webb on the following blog: <a href=\"https:\/\/blog.crossjoin.co.uk\/2013\/11\/19\/generating-a-date-dimension-table-in-power-query\/\">https:\/\/blog.crossjoin.co.uk\/2013\/11\/19\/generating-a-date-dimension-table-in-power-query\/<\/a><\/p>\n<p>Execute these step-by-step directions to create the date dimension:<\/p>\n<ol start=\"27\">\n<li>On the top menu, click <em>New Query<\/em> -&gt; <em>Blank Query<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94327\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-6.png\" alt=\"An image showing the Power Query menus and Get Data Blank Query\" width=\"431\" height=\"481\" \/><\/p>\n<ol start=\"28\">\n<li>Paste the query copied from Chris Webb\u2019s blog above<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94328\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-3.png\" alt=\"An image showing Connect to data source and the query pasted in\" width=\"1166\" height=\"720\" \/><\/p>\n<ol start=\"29\">\n<li>Click <em>Next<\/em> button<\/li>\n<li>In the Properties window, change the name of the new query to <em>BuildDateDimension<\/em><\/li>\n<\/ol>\n<p>You may notice this query is in fact a custom <strong>M<\/strong> function. The details about custom <strong>M<\/strong> functions are beyond this article, but you can learn more about them watch the recording of some technical sessions about advanced <strong>ETL<\/strong> with power query: <a href=\"https:\/\/www.youtube.com\/watch?v=IjLlqTdF2bg&amp;list=PLNbt9tnNIlQ6s597rRyoGx_sLn4rrHOzv\">https:\/\/www.youtube.com\/watch?v=IjLlqTdF2bg&amp;list=PLNbt9tnNIlQ6s597rRyoGx_sLn4rrHOzv<\/a><\/p>\n<p>This function requires two parameters, <em>StartDate<\/em> and <em>EndDate<\/em>, to build the date dimension. You can provide these parameters dynamically, so you will always have an updated date dimension. On the next steps, retrieve these values from the <em>TransactionHistory<\/em> table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94329\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-7.png\" alt=\"Query settings menu Properties Name BuildDataDim\" width=\"247\" height=\"222\" \/><\/p>\n<ol start=\"31\">\n<li>Right click the TransactionHistory table and click the Duplicate option in the context menu<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94330\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-word-descr.png\" alt=\"Image showing right-click menu with Duplicate selected\" width=\"418\" height=\"245\" \/><\/p>\n<ol start=\"32\">\n<li>Repeat the previous step, resulting in two copies of the <em>TransactionHistory<\/em> table.<\/li>\n<\/ol>\n<p>Why duplicate and not reference? Since all the transformations will be converted to native queries anyway, duplicating makes it easy to convert each of the queries into an independent native <strong>SQL<\/strong> query. If you use reference, future changes to the source query would affect the new query.<\/p>\n<p>I wrote a blog post exactly about this example, you can read more on https:\/\/www.red-gate.com\/simple-talk\/blogs\/power-bi-when-a-power-query-native-query-is-not-enough\/.\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94331\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/diagram-description-automatically-generated-with.png\" alt=\"An image showing a list of queries including TransactionHistory (2) and TransactionHistory (3)\" width=\"240\" height=\"242\" \/><\/p>\n<ol start=\"33\">\n<li>Select the first duplicated query<\/li>\n<li>Select the <em>TransactionDate<\/em> field<\/li>\n<li>Right-click the column header and click the <em>Remove other columns <\/em>in the context menu<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94332\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-word-descr-1.png\" alt=\"An image showing the right-click menu of TransactionDate. Remove other columns is selected\" width=\"443\" height=\"249\" \/><\/p>\n<ol start=\"36\">\n<li>Click the button on the <em>TransactionDate<\/em> header<\/li>\n<li>Click the <em>Sort Ascending<\/em> menu item<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94333\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-4.png\" alt=\"Right-click menu of TransactionDate and Sort Ascending is selected\" width=\"636\" height=\"275\" \/><\/p>\n<ol start=\"38\">\n<li>Click the <em>Keep top rows<\/em> menu item<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94334\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-word-descr-2.png\" alt=\"Image showing menu. Keep Rows --&gt; Keep top rows\" width=\"555\" height=\"338\" \/><\/p>\n<ol start=\"39\">\n<li>On the <em>Keep to Rows<\/em> window, type 1<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94335\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-8.png\" alt=\"Image showing Keep top rows. Specify how many rows to keep. Number of rows 1\" width=\"439\" height=\"268\" \/><\/p>\n<ol start=\"40\">\n<li>Click the <em>Ok<\/em> button<\/li>\n<li>On the top menu, change the data type to <em>Date<\/em><\/li>\n<\/ol>\n<p>A date dimension should never include time. If your business needs time, you would need to create a time dimension and include date and time information in different fields<\/p>\n<p>However, these sample tables don\u2019t include time, so changing the data type just ignores the time.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94336\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-9.png\" alt=\"Image showing list of data types. Date is selected\" width=\"240\" height=\"565\" \/><\/p>\n<ol start=\"42\">\n<li>Right-click the date value and select the item <em>Drill down<\/em> on the context menu<\/li>\n<\/ol>\n<p>Even after reaching a single value, the result is still a table. The parameter for the function, on the other hand, needs to be a value. Using the Drill down option you are retrieving the date as a single value<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94337\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-5.png\" alt=\"Images showing TransactionDate menu. Drill down is selected\" width=\"376\" height=\"204\" \/><\/p>\n<ol start=\"43\">\n<li>Right-click the duplicated table you are working with and disable the option <em>Enable Load<\/em><\/li>\n<\/ol>\n<p>This query will be used only as parameter for the function, you don\u2019t need it in the model. Besides this, if you don\u2019t disable the load, the <strong>Power Query<\/strong> UI will convert the single value to table again, adding a new step to the query.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94338\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-10.png\" alt=\"Image showing menu for TransactionHistory (3). Enable Load is selected\" width=\"394\" height=\"175\" \/><\/p>\n<ol start=\"44\">\n<li>Repeat the steps 33-43 for the 2<sup>nd<\/sup> duplicated query, but this time sorting the data in descending order<\/li>\n<li>Click the first duplicated table and rename it to <em>MinDate<\/em><\/li>\n<li>Click the second duplicated table and rename it to<em> MaxDate<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94339\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-with-me.png\" alt=\"An image showing list of Queries and last two are changed to MaxDate and MinDate\" width=\"246\" height=\"243\" \/><\/p>\n<p>The steps of these queries show some additional features. On the image below you may notice a red database symbol besides one step. This means that step will not be transformed into the native data source query. As a result, all the steps after it will also not be part of the native data source query, they will be executed by <strong>Power BI<\/strong>.<\/p>\n<p>On this example, these are the last steps, conversion of the last value retrieved, so there is no problem at all<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94340\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-6.png\" alt=\"An image showing the applied steps\" width=\"246\" height=\"362\" \/><\/p>\n<ol start=\"47\">\n<li>Select the <em>BuildDateDimension<\/em> function<\/li>\n<li>On the button besides the <em>StartDate<\/em> parameter, change the option to query<\/li>\n<li>On the <em>StartDate<\/em> drop down, select the<em> MinDate<\/em> query<\/li>\n<li>On the button besides the <em>EndDate<\/em> parameter, change the option to query<\/li>\n<li>On the <em>EndDate<\/em> drop down, select the <em>MaxDate<\/em> query<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94341\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-email-desc.png\" alt=\"An image showing Enter parameters. StartDate is MinDate. EndDate is MaxDate\" width=\"505\" height=\"312\" \/><\/p>\n<ol start=\"52\">\n<li>Click the <em>Invoke<\/em> function<\/li>\n<\/ol>\n<p>A new query will be created using the <strong>M<\/strong> code needed to invoke the function, what will produce the date dimension<\/p>\n<ol start=\"53\">\n<li>Rename the new query as<em> DateDim<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94342\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-11.png\" alt=\"An image showing QuerySettings Properties. Name DateDim Applied steps Fx source\" width=\"225\" height=\"212\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94343\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-with-me-1.png\" alt=\"An image showing list of Queries. DateDim is now added\" width=\"231\" height=\"262\" \/><\/p>\n<ol start=\"54\">\n<li>Click the <em>Save<\/em> button<\/li>\n<\/ol>\n<p>After clicking the save button, the data will be loaded into the Datamart.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94344\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-3.png\" alt=\"An image showing Objects --&gt; Tables. DateDim, Product, TransactionHistory\" width=\"242\" height=\"244\" \/><\/p>\n<h2>Renaming the Datamart<\/h2>\n<p>The Datamart is created with an auto-generated name. At some point you would like to rename the Datamart.<\/p>\n<p>Clicking on the workspace name in the list of workspaces on the left side, you will see the Datamart and the auto-generated dataset.<\/p>\n<p>On the Datamart menu, you will find a Rename command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94345\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-12.png\" alt=\"An image showing the datasets and datamarts and how to rename the datamart.\" width=\"840\" height=\"632\" \/><\/p>\n<p>Once you rename the Datamart, the auto-generated dataset will be renamed at the same time.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94346\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-13.png\" alt=\"An image showing the Rename Datamart dialog\" width=\"426\" height=\"219\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94347\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-7.png\" alt=\"An image showing the list of datasets and datamarts and this time they are renamed to a friendly name AdvWorks\" width=\"832\" height=\"336\" \/><\/p>\n<h2>Building the model<\/h2>\n<p>The fourth tab on the lower toolbar inside the Datamart is the Model tab. On this tab, you can make model configurations for the tables. It\u2019s time to build the model.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94348\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-description-automaticall.png\" alt=\"An image showing the icons and the meaning of each one. Data, Design, SQL, Model\" width=\"248\" height=\"145\" \/><\/p>\n<ol start=\"55\">\n<li>Click the <em>Model<\/em> tab<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94349\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-14.png\" alt=\"An image showing the Model and there are 3 tables shown\" width=\"1035\" height=\"341\" \/><\/p>\n<ol start=\"56\">\n<li>Organize the tables, leaving the fact table, <em>TransactionHistory<\/em>, in the middle.<\/li>\n<li>Drag the Date field from <em>DateDim<\/em> table to the <em>TransactionDate<\/em> field in the <em>TransactionHistory<\/em> table<\/li>\n<li>On the <em>Create Relationship<\/em> window, adjust the cardinality of the relationship. It needs to be 1 to many from <em>DateDim<\/em> to <em>TransactionHistory<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94350\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-3.png\" alt=\"An image showing the Create Relationship dialog\" width=\"904\" height=\"720\" \/><\/p>\n<ol start=\"59\">\n<li>Drag the <em>ProductId<\/em> field from the Product table to the <em>ProductId<\/em> field on the <em>TransactionHistory<\/em> table<\/li>\n<li>On the <em>Create Relationship<\/em> window, adjust the cardinality of the relationship. It needs to be 1 to many from <em>Product<\/em> to <em>TransactionHistory<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94351\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-description-automaticall-1.png\" alt=\"An image showing the model but now the tables are connected with one-to-many arrows\" width=\"942\" height=\"380\" \/><\/p>\n<ol start=\"61\">\n<li>Select the <em>ActualCost<\/em> field in the<em> TransactionHistory<\/em> table<\/li>\n<li>On the top toolbar, change the format of the field to <em>Currency<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94352\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-word-descr-3.png\" alt=\"An image showing how to change the format to currency\" width=\"901\" height=\"495\" \/><\/p>\n<ol start=\"63\">\n<li>Right click the <em>DateDim <\/em>table and click the menu item <em>Mark as Date Table<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94353\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-15.png\" alt=\"An image showing the right-click image and Mark as date Table\" width=\"610\" height=\"323\" \/><\/p>\n<ol start=\"64\">\n<li>On the <em>Mark as Date Table<\/em> window, select the <em>Date<\/em> field<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94354\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-4.png\" alt=\"An image showing Mark as date table dialog\" width=\"811\" height=\"442\" \/><\/p>\n<ol start=\"65\">\n<li>Select the <em>TransactionDate<\/em> field in the <em>TransactionHistory<\/em> table.<\/li>\n<li>On the <em>Properties<\/em> window located on the right side, under <em>Formatting<\/em>, select the date format containing only the date<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94355\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-8.png\" alt=\"An image showing the format of TransactionDate\" width=\"678\" height=\"250\" \/><\/p>\n<ol start=\"67\">\n<li>Select the <em>Date<\/em> field in the <em>DateDim<\/em> table<\/li>\n<li>On the properties window located on the right side, under Formatting, select the date format containing only the date<\/li>\n<\/ol>\n<p>The newly built model will be stored in the auto-generated dataset created together in the Datamart. This dataset can become the base model for all users of the Datamart. Of course, there are many modelling features still missing, such as hierarchies and aggregation tables, but it\u2019s a good start.<\/p>\n<h2>Exploratory Analysis: The Design tab<\/h2>\n<p>The Design tab is one of the two tabs available to allow exploring the data in the Datamart. Here\u2019s a small example:<\/p>\n<ol start=\"69\">\n<li>Drag the <em>TransactionHistory <\/em>table to the middle of the <em>Design<\/em> tab<\/li>\n<li>Drag the <em>DateDim<\/em> table to the middle of the <em>Design<\/em> tab<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94356\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-16.png\" alt=\"An image showing TransactionHistory and DateDim in the design tab\" width=\"340\" height=\"253\" \/><\/p>\n<ol start=\"71\">\n<li>Click the \u201c+\u201d sign on the <em>TransactionHistory <\/em>table and select the <em>Merge queries<\/em> option<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94357\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-17.png\" alt=\"An image showing the right-click menu and Merge queries is selected\" width=\"516\" height=\"595\" \/><\/p>\n<ol start=\"72\">\n<li>On the <em>Merge<\/em> window, under the Right table for merge, select the <em>DateDim<\/em> table<\/li>\n<li>On the <em>Merge<\/em> window, in the <em>TransactionHistory<\/em> table, select the <em>TransactionDate<\/em> field<\/li>\n<li>On the <em>Merge<\/em> window, in the <em>DateDim<\/em> table, select the Date field<\/li>\n<li>Click the <em>Ok<\/em> button<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94358\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-4.png\" alt=\"An image showing the Merge dialog. TransactionHistory and right table is DateDim. Join kind is left join\" width=\"782\" height=\"720\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94359\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/a-picture-containing-diagram-description-automati.png\" alt=\"An image showing DateDim and TransactionHistory. Both are connected\" width=\"894\" height=\"155\" \/><\/p>\n<ol start=\"76\">\n<li>On the lower window with the table visualization, click the <em>Expand <\/em>button besides the new <em>DateDim<\/em> column<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94360\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-table-desc-1.png\" alt=\"The DateDim table with expand icon\" width=\"116\" height=\"146\" \/><\/p>\n<ol start=\"77\">\n<li>On the window with the field names to expand, uncheck all the fields and check only <em>Year <\/em>and <em>MonthName<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94361\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-table-description-autom.png\" alt=\"An image showing the fields. Year and MonthName are selected\" width=\"428\" height=\"553\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94362\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-5.png\" alt=\"An image showing the design. Year and Month name are now in the list of fields\" width=\"1044\" height=\"480\" \/><\/p>\n<ol start=\"78\">\n<li>On the merged query, click the \u201c+\u201d sign and select the <em>Group By<\/em> option<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94363\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-table-description-autom-1.png\" alt=\"An image showing the menu. Group By is selected\" width=\"743\" height=\"602\" \/><\/p>\n<ol start=\"79\">\n<li>On the <em>Group By<\/em> window, select the option <em>Advanced<\/em><\/li>\n<li>On the <em>Group By<\/em> window, click the <em>Add Grouping<\/em> button once to complete 3 grouping fields<\/li>\n<li>On the <em>Group By<\/em> window, click the <em>Add aggregation<\/em> button once to complete 2 aggregation fields<\/li>\n<li>On the <em>Group By<\/em> window, select <em>Year<\/em>, <em>MonthNumberOfYear <\/em>and <em>MonthName<\/em> as the 3 grouping fields<\/li>\n<li>Under <em>New Column Name<\/em>, type <em>QtyOrders<\/em><\/li>\n<li>On <em>Operation<\/em> drop down to the right of <em>QtyOrders<\/em>, select <em>Count Rows<\/em><\/li>\n<li>On the 2<sup>nd<\/sup> <em>New Column Name<\/em>, type <em>OrdersTotal<\/em><\/li>\n<li>On the <em>Operation<\/em> drop down to the right of <em>OrdersTotal<\/em>, select <em>Sum<\/em><\/li>\n<li>On the <em>Column<\/em> drop down, to the right of <em>Sum<\/em> operation, select <em>ActualCost<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94364\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/a-picture-containing-diagram-description-automati-1.png\" alt=\"An image showing the Group by dialog\" width=\"875\" height=\"700\" \/><\/p>\n<ol start=\"88\">\n<li>Click <em>Ok<\/em> button<\/li>\n<\/ol>\n<p>As a result, you have the total of the orders by month<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94365\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-9.png\" alt=\"An image showing the results. For each year and month there are totals for QtyOrders and OrderTotal \" width=\"1280\" height=\"462\" \/><\/p>\n<h2>Exploratory Analysis: The SQL tab<\/h2>\n<p>The 2<sup>nd<\/sup> tab which allows exploratory analysis is the <strong>SQL<\/strong> table. You can execute <strong>SQL <\/strong>statements over the Datamart<\/p>\n<p>Type the following statement on the SQL tab:<\/p>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">select Year, MonthName,sum(ActualCost) as OrdersTotal\r\n from TransactionHistory\r\ninner join DateDim\r\n    on TransactionHistory.TransactionDate=DateDim.Date\r\nGroup By Year, MonthName<\/pre>\n<p>Click the <em>Run<\/em> button to execute the query<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94366\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-description-18.png\" alt=\"An image showing the Run icon\" width=\"344\" height=\"358\" \/><\/p>\n<p>At the moment I\u2019m writing this article, the results window still has a small secret. You can view the results together with the <strong>SQL<\/strong> statement, but you need to resize the window from top to bottom for that.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94367\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-6.png\" alt=\"An image showing the results\" width=\"507\" height=\"327\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94368\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-7.png\" alt=\"An image showing that it's possible to see then query when expanding the top\" width=\"770\" height=\"456\" \/><\/p>\n<p>The user can click the <strong>Excel<\/strong> button to open the query result in <strong>Excel<\/strong><\/p>\n<p>An <strong>Excel<\/strong> file will be downloaded. Once you open it, you will need to click the button <em>Enable Editing<\/em>. After that, a second message will appear, and you will need to click the button <em>Enable Content<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94369\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-10.png\" alt=\"An image showing Enable Editing\" width=\"1091\" height=\"90\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94370\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-application-word-descr-4.png\" alt=\"An image showing Enable Content\" width=\"805\" height=\"202\" \/><\/p>\n<p><strong>Excel <\/strong>will connect directly to the <strong>Azure SQL Database<\/strong> and execute the query. The user using <strong>Excel<\/strong> needs permission to connect to the underlying <strong>Azure SQL Database<\/strong>.<\/p>\n<p>On the <em>Native Database Query<\/em> window, click the <em>Run<\/em> button. The query will be executed, and the result inserted in Excel.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94371\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-5.png\" alt=\"An image showing the Native Database Query and the Run button\" width=\"690\" height=\"638\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94372\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-excel-description-automatically-generated.png\" alt=\"An image showing the results in Excel\" width=\"421\" height=\"445\" \/><\/p>\n<h2>Yes, you have access to SQL<\/h2>\n<p>The Power BI Datamarts underlying technology is an <strong>Azure SQL database<\/strong>. After all the exploratory analysis features mentioned above, the icing on the cake is a direct connection to <strong>Azure SQL Database<\/strong>.<\/p>\n<p>First, you need to locate the connection string for the <strong>Azure SQL Database<\/strong>. In the Datamart settings, under <em>Server Settings<\/em>, you can find the connection string and copy it to be used for connection in another application. For example, you can use <strong>SSMS<\/strong>, paste this connection on <strong>SSMS<\/strong> connection string to access the <strong>Azure SQL Database<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94373\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-descr-11.png\" alt=\"An image for AdwWorks settings\" width=\"1280\" height=\"430\" \/><\/p>\n<p>The authentication is made with <em>Active Directory \u2013 Universal with MFA<\/em>. The login is the <strong>Power BI<\/strong> login.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94374\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-text-application-email-6.png\" alt=\"An image showing the Connect to Server dialog for SQL Server\" width=\"633\" height=\"384\" \/><\/p>\n<p>You may notice there are no tables in the database, only views. All the tables created in the model appear as views. The database is completely read only, but the ability to connect to the Datamart using any tool capable to connect to <strong>SQL<\/strong> is a very powerful feature.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94375\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/graphical-user-interface-description-automaticall-2.png\" alt=\"An image showing the list of database objects in Object Explorer and the Views in the dataset\" width=\"429\" height=\"353\" \/><\/p>\n<p>On my blog about <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/power-bi-etl-or-not-etl-thats-the-question\/\">Power BI and ETL<\/a>, one of my arguments was the fact the ETL in <strong>Power BI<\/strong> was only capable to save the data to <strong>Power BI<\/strong>. The evolution of the technology always makes the borders between different technologies more difficult to find. I may need to update that article soon.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-94376\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2022\/05\/table-description-automatically-generated-8.png\" alt=\"An image showing the results of running select top 10 * from transactionhistory\" width=\"618\" height=\"371\" \/><\/p>\n<h2>Using the Datamart to build reports<\/h2>\n<p>The Datamart should become the central single source of truth for one area of the company. Whether the Datamart is built using a top-down or bottom-up approach, it\u2019s still a central single source of truth.<\/p>\n<p>For example, if the Datamart is using the bottom-up approach, it will be the central point to integrate all user\u2019s data sources, such as excel, sharepoint lists and many kinds of data sources starting from a small spreadsheet and growing in an uncontrolled rate. It will not be the central point for the entire company, but for one company branch, for example.<\/p>\n<p>On the other hand, in a top-down approach the Datamart is built as a subset of the company data warehouse. This subset may be focused on one branch, and it will be the single source of truth to this branch.<\/p>\n<p>These are some important points which makes the Datamart a good local single point of truth:<\/p>\n<ul>\n<li>Calculations which in other ways would be made using <strong>DAX<\/strong> formulas and turn the model slower, can be done using physical tables and result in a better model<\/li>\n<li>The model stored in the auto-generated dataset can be used as a base for all local reports and additional models.<\/li>\n<li>There are many features for exploratory analysis, including direct <strong>SQL<\/strong> access to the data<\/li>\n<\/ul>\n<p>There are three different methods to use the Datamart:<\/p>\n<ul>\n<li>Use the portal to create reports based on the auto-generated dataset<\/li>\n<\/ul>\n<p>The reports will be using the auto-generated dataset directly. Depending on the number of different departments using the auto-generated dataset, this may not be the best solution<\/p>\n<ul>\n<li>Create reports directly accessing the underlying <strong>Azure SQL connection<\/strong><\/li>\n<\/ul>\n<p>This is a very good solution, but every report solution using this direct connection would need to build the model again, without re-using the model already built in the auto-generated dataset<\/p>\n<ul>\n<li>Use Power BI desktop to create reporting solutions using the auto-generated dataset as a source<\/li>\n<\/ul>\n<p>This is probably the best solution for the use of the Datamart. You will be able to re-use the model built in the auto-generated dataset and customize it with additional information needed.<\/p>\n<h2>Summary<\/h2>\n<p>The Datamarts are more than a very powerful feature, it\u2019s also a critical point in the <strong>Power BI<\/strong> evolution. More consistent data exploration tools and consistent tools to create a local single source of truth. It has the potential to change the architectures used to build in <strong>Power BI,<\/strong> and I believe everyone all will be looking forward to the new features to come.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>During Build 2022, Microsoft announced a new feature, Datamarts for Power BI. MVP Dennes Torres explains this new feature and provides and example. &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":[143528,53],"tags":[95506],"coauthors":[6810],"class_list":["post-94302","post","type-post","status-publish","format-standard","hentry","category-bi-sql-server","category-featured","tag-automate"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/94302","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=94302"}],"version-history":[{"count":10,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/94302\/revisions"}],"predecessor-version":[{"id":94460,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/94302\/revisions\/94460"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=94302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=94302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=94302"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=94302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}