{"id":1281,"date":"2020-06-15T20:23:56","date_gmt":"2020-06-15T20:23:56","guid":{"rendered":"http:\/\/bi.unija.com\/en\/?p=1281"},"modified":"2020-09-01T11:42:17","modified_gmt":"2020-09-01T11:42:17","slug":"5-best-practices-for-data-modeling","status":"publish","type":"post","link":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/","title":{"rendered":"5 best practices for data modeling"},"content":{"rendered":"<p><em>For Power BI Desktop version 2.76.5678.782 (January\u00a02020).<\/em><\/p>\n<p>Data model is the core of every Power BI project. Building a good data model is crucial. In this article, we present 5 best practices to make sure your data model runs smoothly.<\/p>\n<h1>Mark as date table<\/h1>\n<p>Calendar table is the most important table in a data model. There are many ways to build a calendar table. Our choice is using an M function in Power Query, presented in Creating Dynamic Calendar in Power Query Using an M Function.<\/p>\n<p>After we create a calendar table, we need to mark it as such. We select the table and then <strong>Table Tools &gt; Mark as date table<\/strong>. We get asked for the date field. In our case, we choose a field named <em>Date<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"715\" height=\"472\" class=\"wp-image-1282\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-83.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-83.png 715w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-83-300x198.png 300w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/p>\n<p>Power BI checks if the field contains all the dates between the start and end date and confirms the validation.<\/p>\n<h1>Sort by other colum<\/h1>\n<p>Month field of the calendar table is just a text type data, which will by default be sorted according to alphabetical order. This is usually not helpful, we want months sorted chronologically in our reports.<\/p>\n<p>We create another field with month number, for example <em>Month No<\/em>. We can do this in few different ways.<\/p>\n<ul>\n<li>We open Power Query with <strong>Transform Data<\/strong>, choose the <em>Date<\/em> field of <em>Calendar<\/em> table and <strong>Add Column &gt; Date &gt; Month<\/strong>. We rename field to <em>Month No<\/em>. We close Power Query with <strong>Close&amp;Apply<\/strong>.<\/li>\n<li>We choose <em>Calendar <\/em>table in Power BI and click on <strong>Table Tools<\/strong> <strong>&gt;<\/strong> <strong>New column<\/strong>. We enter the formula <strong>= MONTH(Calendar[Date])<\/strong>, where <em>Calendar<\/em> is the name of our calendar table and <em>Date<\/em> is the name of the date field.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1248\" height=\"602\" class=\"wp-image-1283\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-85.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-85.png 1248w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-85-300x145.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-85-1024x494.png 1024w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-85-768x370.png 768w\" sizes=\"(max-width: 1248px) 100vw, 1248px\" \/><\/p>\n<p>We sort months chronologically by selecting the field with month names <em>Month<\/em> and then selecting <strong>Column Tools &gt; Sort By Column &gt; Month No<\/strong>. Similarly, we can sort days of the week.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"419\" class=\"wp-image-1284\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-87.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-87.png 814w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-87-300x154.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-87-768x395.png 768w\" sizes=\"(max-width: 814px) 100vw, 814px\" \/><\/p>\n<h1>Connecting tables to a star schema<\/h1>\n<p>When building a data model, we always pursue a <em>Star schema,<\/em> meaning one fact table and multiple dimension tables. Lets reiterate:<\/p>\n<p><em>Fact table <\/em>is a table, containing all the records we observe, for example a table of all the sales transactions. Fact tables are large and are growing daily<em>.<\/em><\/p>\n<p><em>Dimension tables <\/em>are tables describing attributes like when, who, where and similar. For example, <em>Products<\/em> is a dimension table containing a all the products sold in a store. Dimension tables are small and rarely change<em>.<\/em><\/p>\n<p>Example: image below shows the <em>fSales <\/em>table, which contains thousands of rows. Each rows represents one transaction. Smaller dimension tables are connected to the fact table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"676\" class=\"wp-image-1285\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-89.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-89.png 752w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-89-300x270.png 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/p>\n<p>Best practice is to use an ID column in all dimension tables. For Product table, we would use <em>Product ID<\/em>. Same field <em>Product ID<\/em> would also be included in the fact table. We can then connect the fields: we select <em>Product ID<\/em> from the fact table and drag it to the same field in the dimension table. All we need to ensure is that data types of field match. The relationship is formed. Most relationships are of type <em>Many to One<\/em>. We usually want to avoid other relationship types.<\/p>\n<p>We connect all other dimension tables in the same way. We get a shape of a star or a <em>Star schema<\/em>.<\/p>\n<h1>Hide connected fields<\/h1>\n<p>We hide the connected fields: right click on the field and <strong>Hide in report view<\/strong>. We hide the field in both fact and dimension tables. These fields usually contain numbers, which don&#8217;t carry any other information other than an index of an attribute. We&#8217;ll be using names in our filters, for example <em>Bike BMX-C203<\/em> or <em>California<\/em>. When we select a product in report we consequently filter the product <em>and<\/em> the fact table. That&#8217;s the idea of a <em>Star schema<\/em>.<\/p>\n<p>We usually go a step further and hide all the fields we don&#8217;t use. All that&#8217;s left visible in the fact table are measures.<\/p>\n<h1>Setting synonyms<\/h1>\n<p>Q&amp;A is a visual that allows us to display data using field names and filters.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"399\" class=\"wp-image-1286\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-91.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-91.png 553w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-91-300x216.png 300w\" sizes=\"(max-width: 553px) 100vw, 553px\" \/><\/p>\n<p>We can use synonyms for field names: we select a field name in our data model and enter synonyms in the Synonyms field. We can then call the same data using set synonyms.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1581\" height=\"953\" class=\"wp-image-1287\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92.png 1581w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92-300x181.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92-1024x617.png 1024w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92-768x463.png 768w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/word-image-92-1536x926.png 1536w\" sizes=\"(max-width: 1581px) 100vw, 1581px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For Power BI Desktop version 2.76.5678.782 (January\u00a02020). Data model is the core of every Power BI project. Building a good data model is crucial. In this article, we present 5 best practices to make sure your data model runs smoothly.<\/p>\n","protected":false},"author":5,"featured_media":1724,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[8],"class_list":["post-1281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-intermediate","tag-power-bi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>5 best practices for data modeling - Bi Unija<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"5 best practices for data modeling - Bi Unija\" \/>\n<meta property=\"og:description\" content=\"For Power BI Desktop version 2.76.5678.782 (January\u00a02020). Data model is the core of every Power BI project. Building a good data model is crucial. In this article, we present 5 best practices to make sure your data model runs smoothly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/\" \/>\n<meta property=\"og:site_name\" content=\"Bi Unija\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-15T20:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-01T11:42:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Branka Trifunovi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Branka Trifunovi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/\",\"url\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/\",\"name\":\"5 best practices for data modeling - Bi Unija\",\"isPartOf\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg\",\"datePublished\":\"2020-06-15T20:23:56+00:00\",\"dateModified\":\"2020-09-01T11:42:17+00:00\",\"author\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\"},\"breadcrumb\":{\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage\",\"url\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg\",\"contentUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg\",\"width\":720,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bi.unija.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"5 best practices for data modeling\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bi.unija.com\/en\/#website\",\"url\":\"https:\/\/bi.unija.com\/en\/\",\"name\":\"Bi Unija\",\"description\":\"Just another Bi site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bi.unija.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\",\"name\":\"Branka Trifunovi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g\",\"caption\":\"Branka Trifunovi\u0107\"},\"url\":\"https:\/\/bi.unija.com\/en\/author\/branka\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"5 best practices for data modeling - Bi Unija","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/","og_locale":"en_US","og_type":"article","og_title":"5 best practices for data modeling - Bi Unija","og_description":"For Power BI Desktop version 2.76.5678.782 (January\u00a02020). Data model is the core of every Power BI project. Building a good data model is crucial. In this article, we present 5 best practices to make sure your data model runs smoothly.","og_url":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/","og_site_name":"Bi Unija","article_published_time":"2020-06-15T20:23:56+00:00","article_modified_time":"2020-09-01T11:42:17+00:00","og_image":[{"width":720,"height":480,"url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg","type":"image\/jpeg"}],"author":"Branka Trifunovi\u0107","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Branka Trifunovi\u0107","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/","url":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/","name":"5 best practices for data modeling - Bi Unija","isPartOf":{"@id":"https:\/\/bi.unija.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage"},"image":{"@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage"},"thumbnailUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg","datePublished":"2020-06-15T20:23:56+00:00","dateModified":"2020-09-01T11:42:17+00:00","author":{"@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10"},"breadcrumb":{"@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#primaryimage","url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg","contentUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/06\/ENG9-1.jpg","width":720,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/bi.unija.com\/en\/5-best-practices-for-data-modeling\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bi.unija.com\/en\/"},{"@type":"ListItem","position":2,"name":"5 best practices for data modeling"}]},{"@type":"WebSite","@id":"https:\/\/bi.unija.com\/en\/#website","url":"https:\/\/bi.unija.com\/en\/","name":"Bi Unija","description":"Just another Bi site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bi.unija.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10","name":"Branka Trifunovi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec99f651bcc98a163161515ec254b974?s=96&d=mm&r=g","caption":"Branka Trifunovi\u0107"},"url":"https:\/\/bi.unija.com\/en\/author\/branka\/"}]}},"_links":{"self":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1281"}],"collection":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/comments?post=1281"}],"version-history":[{"count":1,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1281\/revisions"}],"predecessor-version":[{"id":1694,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1281\/revisions\/1694"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media\/1724"}],"wp:attachment":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media?parent=1281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/categories?post=1281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/tags?post=1281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}