{"id":5982,"date":"2022-09-05T09:28:32","date_gmt":"2022-09-05T09:28:32","guid":{"rendered":"https:\/\/www.stl-training.co.uk\/b\/?p=5982"},"modified":"2023-12-30T23:03:16","modified_gmt":"2023-12-30T23:03:16","slug":"power-bi-mysterious-calculate-function-3-time-intelligence","status":"publish","type":"post","link":"https:\/\/www.stl-training.co.uk\/b\/power-bi-mysterious-calculate-function-3-time-intelligence\/","title":{"rendered":"Power BI Mysterious Calculate Function 3: Time Intelligence"},"content":{"rendered":"<p>DAX (Data Analysis eXpressions) is the function language in <a href=\"https:\/\/www.stl-training.co.uk\/ao\/71\/microsoft-power-bi-training-courses-london-uk.html\">Power BI desktop<\/a>. When <a href=\"https:\/\/www.stl-training.co.uk\/syl\/356\/dax-bi-training-courses-london.html\">DAX<\/a> is used to create measures, it can hard to understand the logic at times. Especially one function, the Calculate function, can be challenging.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5986 size-full\" title=\"intelligence\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4.jpg\" alt=\"intelligence\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4.jpg 1920w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4-300x169.jpg 300w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4-1024x576.jpg 1024w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4-768x432.jpg 768w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic4-1536x864.jpg 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>We visit the mysterious Calculate Function for the third time, in this four part series of blogs.<\/p>\n<p>The Calculate function reacts differently to row, column, filter, and table context than the other DAX functions and the Calculate function is important for nesting other functions.<\/p>\n<p>In this blog post you will see some examples of how the calculate function works with time-intelligence.<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Time Intelligence<\/strong><\/h2>\n<p>The time-intelligence functions that\u00a0enable you to control data using time periods, including days, months, quarters, and years, and then build and compare calculations over those periods.<\/p>\n<p>Most time-intelligence functions need to be nested inside the Calculate function.<\/p>\n<p>In this example, sales need to be compared up against previous year.<\/p>\n<p>The structure of the Calculate function:<\/p>\n<p>CALCULATE(&lt;expression&gt;[, &lt;filter1&gt; [, &lt;filter2&gt; [, \u2026]]])<\/p>\n<p>In all the examples the expression will be total sales and in the filter arguments, the time-intelligence functions will be nested.<\/p>\n<p>First, the SamePeriodLastYear function.<\/p>\n<p>All time-intelligence functions need to know the primary key in the Dates table (Calendar Table).<\/p>\n<p>Last year = CALCULATE([sales],SAMEPERIODLASTYEAR(Dates[Dates]))<\/p>\n<p>&nbsp;<\/p>\n<p>Below in the example a Gauge visual is used. The Sales are added to Value and above measure to Target. The page is filtered to show 2016 by a slicer.<\/p>\n<p>The blue part of the Gauge chart (\u00a320.42m) is the sales for 2016, and the line in the Gauge chart (\u00a313.99m) is last year. In this example 2015.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5983 size-full\" title=\"time\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic1.png\" alt=\"intelligence\" width=\"903\" height=\"404\" srcset=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic1.png 903w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic1-300x134.png 300w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic1-768x344.png 768w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Below the page is filtered by two slicers to February 2016. The blue part of the Gauge chart (\u00a320.42) is the sales for February 2016, and the line in the Gauge chart (\u00a313.99) is February 2015. The combination of the Calculate and SamePeriodLastYear function will always go back to the same period last year. In this case, to February 2015.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5984 size-full\" title=\"time\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic2.png\" alt=\"February\" width=\"903\" height=\"492\" srcset=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic2.png 903w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic2-300x163.png 300w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic2-768x418.png 768w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In the next example of the combination of the Calculate and SamePeriodLastYear function. The sales growth needs to be visualised.<\/p>\n<p>The DAX measure used for this: % Growth = DIVIDE([sales]-[Last year],[Last year],0)<\/p>\n<p>The sales minus last year\u2019s sales divided with last year\u2019s sales.<\/p>\n<p>The Last year sales measure from the previous example above, has just been reused here. In the Matrix below right, the Matrix display the percentage difference from previous year and same month previous year.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5985 size-full\" title=\"intelligence\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic3.png\" alt=\"Matrix\" width=\"903\" height=\"542\" srcset=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic3.png 903w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic3-300x180.png 300w, https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/09\/JensDax3pic3-768x461.png 768w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>I call the Calculate function the mother of DAX functions. It is the most important <a href=\"https:\/\/docs.microsoft.com\/en-us\/dax\/\">DAX<\/a> function (my opinion), but to get the most out of it you will need to understand, how the function reacts to row, column, filter, and table context, and how the Calculate function takes care of other functions<\/p>\n<p>This is part 3 of a series of blog posts as mentioned at the top about the mysterious Calculate function.<\/p>\n<p>In the next blog post in this series, you will see how the mysterious Calculate function is different from other DAX functions when it comes to filter context.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DAX (Data Analysis eXpressions) is the function language in Power BI desktop. When DAX is used to create measures, it can hard to understand the logic at times. Especially one function, the Calculate function, can be challenging. &nbsp; We visit the mysterious Calculate Function for the third time, in this four part series of blogs. [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[637,6,8,650],"tags":[78,665,666],"class_list":["post-5982","post","type-post","status-publish","format-standard","hentry","category-application","category-hints-tips","category-microsoft","category-power-bi","tag-calculate","tag-intelligence","tag-time"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/comments?post=5982"}],"version-history":[{"count":4,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5982\/revisions"}],"predecessor-version":[{"id":6023,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5982\/revisions\/6023"}],"wp:attachment":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/media?parent=5982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/categories?post=5982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/tags?post=5982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}