{"id":1775,"date":"2020-09-25T09:42:01","date_gmt":"2020-09-25T09:42:01","guid":{"rendered":"https:\/\/bi.unija.com\/en\/?p=1775"},"modified":"2020-10-22T11:47:45","modified_gmt":"2020-10-22T11:47:45","slug":"context-transition-in-power-bi","status":"publish","type":"post","link":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/","title":{"rendered":"Context Transition in Power BI"},"content":{"rendered":"<p><em>For Power BI version 2.76.5678.782 (December 2019).<\/em><\/p>\n<p>Filter context, row context and context transition from row to filter context are most challenging topics when learning DAX. We have already talked about filter and row context in previous articles <a href=\"https:\/\/bi.unija.com\/en\/filter-context-in-power-bi\/\">Filter Context in Power BI<\/a> and <a href=\"https:\/\/bi.unija.com\/en\/row-context-in-power-bi\/\">Row Context in Power BI<\/a>. Here we&#8217;ll show how we transition from row context to filter context.<\/p>\n<h1>Filter and row context<\/h1>\n<p><strong>Filter context <\/strong>is any filtering that comes from report visualizations. We separate filter sources into four groups:<\/p>\n<ol>\n<li>Rows (#1)<\/li>\n<li>Columns (#2)<\/li>\n<li>Filters (#3)<\/li>\n<li>Slicers (#4)<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1121\" height=\"587\" class=\"wp-image-1776\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image.png 1121w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-300x157.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-1024x536.png 1024w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-768x402.png 768w\" sizes=\"(max-width: 1121px) 100vw, 1121px\" \/><\/p>\n<p>For every cell of matrix the tables are filtered in the model according to columns name, row and all additional filters, for example values selected in the slicer. Filtered table in the model is then aggregated into a single result, that is printed in the cell of the matrix.<\/p>\n<p>Filter affects all the tables in the data model. If tables are connected filter flows down in the direction of the connection. With usual positioning of the tables (dimension table high and the fact table below) we say <em>filter flows downward<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"705\" class=\"wp-image-1777\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-1.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-1.png 780w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-1-300x271.png 300w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-1-768x694.png 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/p>\n<p><strong>Row context <\/strong>is property of being aware of rows. Row context means function is <em>applied to every row separately<\/em>. Expression of the function is calculated for each row and then aggregated into one final result value.<\/p>\n<p>Row context is the property of:<\/p>\n<ul>\n<li>X-functions, for example <strong>SUMX()<\/strong>, <strong>AVERAGEX()<\/strong><\/li>\n<li>Function <strong>FILTER()<\/strong><\/li>\n<li>Calculated columns<\/li>\n<\/ul>\n<p>Let&#8217;s look at example using the function <strong>SUMX<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"411\" height=\"79\" class=\"wp-image-1778\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-2.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-2.png 411w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-2-300x58.png 300w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><\/p>\n<p>Function <strong>SUMX()<\/strong> creates a row context in the table <strong>Sales<\/strong> (#1). It then iterates through the table, row by row. In each row it takes the value of columns <strong>Price<\/strong> (#2) and <strong>Tax<\/strong> (#3) and sums them up. In the end, it sums up all the sums into one result value (#4).<\/p>\n<h1>Row context doesn&#8217;t always create filter context<\/h1>\n<p>Like we saw in the Row context in Power BI article, row context doesn&#8217;t always create a filter context. Let&#8217;s again look at the following example.<\/p>\n<p>We add calculated column to the <strong>Products<\/strong> table: <strong>TotalSales = SUM(Sales[Value])<\/strong>. Column will sum up all the values in the <strong>Value<\/strong> column of the <strong>Sales <\/strong>table. What do we expect as a result? Will result differ for each product? The answer is no, result will be the same for all rows.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"492\" class=\"wp-image-1779\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-3.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-3.png 651w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-3-300x227.png 300w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/p>\n<p>The reason here is: row context doesn&#8217;t always create filter context. Value is calculated for each row separately, but product in the row can&#8217;t filter the <strong>Sales<\/strong> table. <strong>Sales<\/strong> table remains completely unfiltered and the result is the same for each row.<\/p>\n<h1>Transition from row to filter context: CALCULATE()<\/h1>\n<p>We can still create row context in the example above. We call this <strong>context transition<\/strong>. All we need to do is to use a <strong>CALCULATE()<\/strong> function. Let&#8217;s try to add column like before, only in this case we also use <strong>CALCULATE()<\/strong> function. We get the following result.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"489\" class=\"wp-image-1780\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-4.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-4.png 604w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-4-300x243.png 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/p>\n<p>Function <strong>CALCULATE() <\/strong>&#8220;turns on&#8221; the filter. This means filter from the <strong>Products<\/strong> table will now also filter the <strong>Sales<\/strong> table according to the product in each line and return the result accordingly.<\/p>\n<p>Context transition exists in:<\/p>\n<ul>\n<li>X-functions, for example <strong>SUMX()<\/strong>, <strong>AVERAGEX()<\/strong><\/li>\n<li>Function <strong>FILTER()<\/strong><\/li>\n<li>Calculated columns<\/li>\n<\/ul>\n<h1>Implicit CALCULATE() in measures<\/h1>\n<p>Every measure actually contains a hidden implicit <strong>CALCULATE().<\/strong> Let&#8217;s look at what this means through an example. We&#8217;ll create a measure using the same formula as we used for calculated column.<\/p>\n<p>We follow the steps bellow.<\/p>\n<p>1. Right click the <strong>Products<\/strong> table and select <strong>New measure<\/strong>.<\/p>\n<p>2. Enter the formula <strong>TotalSales_def = SUM(Sales[Value])<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"295\" height=\"42\" class=\"wp-image-1781\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-5.png\" \/><\/p>\n<p>3. We use the measure in a new column. Select <strong>New Column<\/strong> and enter <strong>TotalSales_Measure<\/strong> = [<strong>TotalSales_def<\/strong>].<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"512\" class=\"wp-image-1782\" src=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-6.png\" srcset=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-6.png 725w, https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/10\/word-image-6-300x212.png 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/p>\n<p>We get an identical column of the <strong>TotalSales_CALCULATE <\/strong>column. We would expect the column to be the same as <strong>TotalSales<\/strong>, since we didn&#8217;t use <strong>CALCULATE() <\/strong>function in the measure. But <strong>CALCULATE() <\/strong>is hidden and implicit in every measure, we just can&#8217;t see it. The lesson again is: measures already contain the <strong>CALCULATE() <\/strong>function.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For Power BI version 2.76.5678.782 (December 2019). Filter context, row context and context transition from row to filter context are most challenging topics when learning DAX. We have already talked about filter and row context in previous articles Filter Context<\/p>\n","protected":false},"author":5,"featured_media":1784,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[8],"class_list":["post-1775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced","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>Context Transition in Power BI - 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\/context-transition-in-power-bi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Context Transition in Power BI - Bi Unija\" \/>\n<meta property=\"og:description\" content=\"For Power BI version 2.76.5678.782 (December 2019). Filter context, row context and context transition from row to filter context are most challenging topics when learning DAX. We have already talked about filter and row context in previous articles Filter Context\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/\" \/>\n<meta property=\"og:site_name\" content=\"Bi Unija\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-25T09:42:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-22T11:47:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png\" \/>\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\/png\" \/>\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\/context-transition-in-power-bi\/\",\"url\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/\",\"name\":\"Context Transition in Power BI - Bi Unija\",\"isPartOf\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png\",\"datePublished\":\"2020-09-25T09:42:01+00:00\",\"dateModified\":\"2020-10-22T11:47:45+00:00\",\"author\":{\"@id\":\"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10\"},\"breadcrumb\":{\"@id\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage\",\"url\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png\",\"contentUrl\":\"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png\",\"width\":720,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bi.unija.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Context Transition in Power BI\"}]},{\"@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":"Context Transition in Power BI - 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\/context-transition-in-power-bi\/","og_locale":"en_US","og_type":"article","og_title":"Context Transition in Power BI - Bi Unija","og_description":"For Power BI version 2.76.5678.782 (December 2019). Filter context, row context and context transition from row to filter context are most challenging topics when learning DAX. We have already talked about filter and row context in previous articles Filter Context","og_url":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/","og_site_name":"Bi Unija","article_published_time":"2020-09-25T09:42:01+00:00","article_modified_time":"2020-10-22T11:47:45+00:00","og_image":[{"width":720,"height":480,"url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png","type":"image\/png"}],"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\/context-transition-in-power-bi\/","url":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/","name":"Context Transition in Power BI - Bi Unija","isPartOf":{"@id":"https:\/\/bi.unija.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage"},"image":{"@id":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage"},"thumbnailUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png","datePublished":"2020-09-25T09:42:01+00:00","dateModified":"2020-10-22T11:47:45+00:00","author":{"@id":"https:\/\/bi.unija.com\/en\/#\/schema\/person\/3bed36623727c7162e421c4366a54e10"},"breadcrumb":{"@id":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#primaryimage","url":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png","contentUrl":"https:\/\/bi.unija.com\/en\/wp-content\/uploads\/sites\/2\/2020\/09\/26eng.png","width":720,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/bi.unija.com\/en\/context-transition-in-power-bi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bi.unija.com\/en\/"},{"@type":"ListItem","position":2,"name":"Context Transition in Power BI"}]},{"@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\/1775"}],"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=1775"}],"version-history":[{"count":5,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1775\/revisions"}],"predecessor-version":[{"id":1788,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/posts\/1775\/revisions\/1788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media\/1784"}],"wp:attachment":[{"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/media?parent=1775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/categories?post=1775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bi.unija.com\/en\/wp-json\/wp\/v2\/tags?post=1775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}