{"id":82927,"date":"2019-01-14T18:17:41","date_gmt":"2019-01-14T18:17:41","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=82927"},"modified":"2026-03-09T10:51:13","modified_gmt":"2026-03-09T10:51:13","slug":"using-the-dax-calculate-and-values-functions","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/using-the-dax-calculate-and-values-functions\/","title":{"rendered":"DAX CALCULATE &#038; VALUES Functions Explained"},"content":{"rendered":"\n<p>The CALCULATE function is the most important function in DAX &#8211; it evaluates an expression in a modified filter context, letting you compute values like percentage-of-total, year-over-year comparisons, and filtered aggregations that aren&#8217;t possible with basic measures. CALCULATE takes two arguments: the expression to evaluate and one or more filter modifications. Pair it with the VALUES function (which returns the distinct values in a column respecting the current filter context) and the ALL function (which removes filters) to build the majority of business intelligence calculations in Power BI, PowerPivot, or Analysis Services tabular models.<\/p>\n\n\n<p><strong>The series so far:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-calculated-columns-using-dax\/\">Creating Calculated Columns Using DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-measures-using-dax\/\">Creating Measures Using DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-the-dax-calculate-and-values-functions\/\">Using the DAX Calculate and Values Functions<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-the-filter-function-in-dax\/\">Using the FILTER Function in DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/cracking-dax-the-earlier-and-rankx-functions\/\">Cracking DAX\u00a0\u2013 the EARLIER and RANKX Functions<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">Using Calendars and Dates in Power BI<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-time-intelligence-functions-in-dax\/\"><span>Creating Time-Intelligence Functions in DAX<\/span><\/a><\/li>\n<\/ol>\n\n\n\n\n<p>If you should ever start reading a book on DAX, you will quickly reach a chapter on the <code>CALCULATE<\/code> function. The book will tell you that the <code>CALCULATE<\/code> function is at the heart of everything that you do in DAX and is the key to understanding the language. A delegate on one of my courses adopted the policy of starting every formula with <code>=CALCULATE<\/code>, and it\u2019s not such a bad approach! This article explains how to use the <code>CALCULATE<\/code> function and also how to use the (almost) equally important <code>VALUES<\/code> function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-example-database-for-this-article\">The Example Database for this Article<\/h2>\n\n\n\n<p>This article uses the same simple database as its two predecessors. This database shows sales of three toys for different cities around the world:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"903\" height=\"243\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-95.png\" alt=\"\" class=\"wp-image-82928\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>You can import this data into your own Power BI data model by first downloading <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/10\/Simple-Toys.xlsx\">this Excel workbook<\/a>, or by running <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/10\/Generate-simple-toy-database.sql\">this SQL script<\/a> in SQL Server Management Studio.<\/p>\n\n\n\n<p>As for the previous articles in this series, everything I describe below will work just as well in Power BI, PowerPivot or Analysis Services (Tabular Model), each of which <a href=\"https:\/\/www.wiseowl.co.uk\/power-bi\/exercises\/power-bi-desktop\/adv-data-models\/4431\/\">Wise Owl train<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-calculate-function\">The CALCULATE Function<\/h2>\n\n\n\n<p>To understand the <code>CALCULATE<\/code> function, you must understand filter context, so that\u2019s where I\u2019ll begin for this article.<\/p>\n\n\n\n<p><strong>Read also:<\/strong> <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/using-calendars-and-dates-in-power-bi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Calendar tables in Power BI<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-filter-context-explained-using-an-excel-pivot-table\">Filter Context Explained Using an Excel Pivot Table<\/h3>\n\n\n\n<p>Suppose you have the following pivot table in Excel, showing the number of sales for each country, city, and product in the database. The figure selected shows that there were three sales of Timmy Tortoise products in London (UK):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"319\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-96.png\" alt=\"\" class=\"wp-image-82929\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The filter context for the shaded cell containing the number 3 is therefore as follows:<\/p>\n\n\n\n<p>Country dimension: UK<\/p>\n\n\n\n<p>City dimension: London<\/p>\n\n\n\n<p>Product dimension: Timmy Tortoise<\/p>\n\n\n\n<p>If you were to double-click on this cell in Excel, you would see the underlying rows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1052\" height=\"123\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-97.png\" alt=\"\" class=\"wp-image-82930\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>These are the three sales which took place for this product in this country and city.<\/p>\n\n\n\n<p>Now suppose that you change your pivot table to show the number of sales as a percentage of the total for each column. This would give:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"311\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-98.png\" alt=\"\" class=\"wp-image-82931\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The figure for Timmy Tortoise for London is 75%, which is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales for London for Timmy Tortoise \/ \nTotal sales for London for all products<\/pre>\n\n\n\n<p>This gives 75% because this is the result you get when you divide 3 (the number of sales in London for Timmy Tortoise) by 4 (the number of sales in London for all products).<\/p>\n\n\n\n<p>Note that I\u2019ll often refer in this article to the numerator and denominator. In any fraction A \/ B, the numerator is A and the denominator is B (but you knew that from school maths, didn\u2019t you?).<\/p>\n\n\n\n<p><strong>Read also:<\/strong><br><a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/how-to-filter-dax-for-paginated-reports\/\" target=\"_blank\" rel=\"noreferrer noopener\">Filtering DAX for paginated reports<\/a><br><a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/temporary-tables-in-sql-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">Temporary tables in SQL Server<\/a><br><a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/t-sql-programming-sql-server\/using-a-subquery-in-a-select-statement\/\" target=\"_blank\" rel=\"noreferrer noopener\">Subqueries in SQL for comparison<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-removing-one-constraint-using-calculate-and-all\">Removing One Constraint Using CALCULATE and ALL<\/h3>\n\n\n\n<p>Now suppose that you want to recreate this pivot table using a matrix and slicer in Power BI:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"345\" height=\"344\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-99.png\" alt=\"\" class=\"wp-image-82932\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The figures are exactly the same, and for Timmy Tortoise for London you\u2019ll see 75% because this is the ratio between the number of sales for this product and city (3) against the number of sales for all products and this city (4).<\/p>\n\n\n\n<p>To solve this problem, you\u2019ll use the <code>CALCULATE<\/code> function which is the answer to most questions in DAX. The syntax of the function is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"562\" height=\"86\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-100.png\" alt=\"\" class=\"wp-image-82933\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The measure you should create (and show) is this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% of all products = DIVIDE(\n    \/\/ the numerator: number of sales for the current filter context\n    COUNT(Sales[SalesId]),\n    \/\/ the denominator: number of sales for the current filter\n    \/\/ context, but for ALL products\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        ALL('Product'[ProductName])\n    )\n)<\/pre>\n\n\n\n<p>I\u2019ve put my measure in a separate table \u2013 if you\u2019re not sure how to create this table or how to create measures, see the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-measures-using-dax\/\">previous article<\/a> in this series. What the measure does is to calculate the numerator (the number of sales for the current product and city) and divide this by the denominator (the number of sales for the current city only, with any product constraint removed). Here\u2019s what this calculates:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales for the current filter context \/ \nTotal sales for the current filter context, \nbut removing any product constraint<\/pre>\n\n\n\n<p>If you display row and column totals for this measure, you get this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"142\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-101.png\" alt=\"\" class=\"wp-image-82934\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The figures in the bottom row make sense: total sales for London for all products divided by total sales for London for all products will always give 100%!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-removing-multiple-constraints-using-all\">Removing Multiple Constraints Using ALL<\/h3>\n\n\n\n<p>Suppose that you now want to display the number of sales as a percentage of the total for all cities and for all products, to get this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"416\" height=\"385\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-102.png\" alt=\"\" class=\"wp-image-82935\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this case, the numerator is the total number of sales in the UK in London for Timmy Tortoise, and the denominator is the total number of sales in the UK; the other two constraints have been removed from the denominator. Here is a DAX measure to calculate these figures:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% of all products and cities = DIVIDE(\n    \/\/ divide the number of sales ...\n    COUNT(Sales[SalesId]),\n    \/\/ ... by the number of sales for all products and\n    \/\/ cities\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        ALL('Product'[ProductName]),\n        ALL(City[CityName])\n    )\n)<\/pre>\n\n\n\n<p>You can use the <code>ALL<\/code> function as many times as you like \u2013 each time it will remove one dimension from the filter context.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-allexcept-to-remove-all-but-one-constraint\">Using ALLEXCEPT to Remove All but One Constraint<\/h3>\n\n\n\n<p>An alternative solution to the above problem would be to calculate this ratio:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales for the current filter context \/ \nTotal sales for the current filter context, \nbut removing every constraint apart from the country one<\/pre>\n\n\n\n<p>Here\u2019s a quick comparison of the two approaches:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"484\" height=\"128\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-103.png\" alt=\"\" class=\"wp-image-82936\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Here\u2019s a measure which would show each product\/city\u2019s contribution to the grand total for each country:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% relaxing everything but country = DIVIDE(\n    \/\/ divide the number of sales ...\n    COUNT(Sales[SalesId]),\n    \/\/ ... by the number of sales, keeping only the \n    \/\/ country constraint\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        ALLEXCEPT(\n            Sales,\n            Country[CountryName]\n        )\n    )\n)<\/pre>\n\n\n\n<p>It\u2019s up to you whether you think it\u2019s more elegant to remove constraints from the filter context individually using <code>ALL<\/code>, or to remove all constraints apart from one using <code>ALLEXCEPT<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-replacing-filter-context-using-calculate\">Replacing Filter Context Using CALCULATE<\/h3>\n\n\n\n<p>The previous examples have all involved removing the filter context in whole or in part. What if you wanted to change it to show the ratio for each matrix cell between the number of sales for that cell and the number of sales for the same filter context, but for the product Timmy Tortoise? That is, you want to calculate:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales for the current filter context \/ \nTotal sales for the current filter context, but ignoring \nany product constraint and using the Timmy Tortoise product instead<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"382\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-104.png\" alt=\"\" class=\"wp-image-82937\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For this example, it\u2019s inevitable that the figures for Timmy Tortoise should be 100%, because for each cell in this row you\u2019re dividing a figure by itself. The matrix above shows that sales of Olly Owl were only a third of those for Timmy Tortoise in London but were twice those for Timmy Tortoise in Manchester.<\/p>\n\n\n\n<p>A formula that you could use might be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% of Timmy = DIVIDE(\n    \/\/ divide the number of sales for the filter context by ...\n    COUNT(Sales[SalesId]),\n    \/\/ ... the number of sales for the filter context, but\n    \/\/ removing any product constraint and replacing this \n    \/\/ with a constraint that the product should equal Timmy Tortoise\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        'Product'[ProductName] = \"Timmy tortoise\"\n    )\n)<\/pre>\n\n\n\n<p>What this does is to calculate the number of sales for a particular country, city and product, and divide this by the number of sales for the same country and city, but for <em>Timmy Tortoise<\/em>. The extra filter you add in the <code>CALCULATE<\/code> formula doesn\u2019t build on the filter context for the product, but instead replaces it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-allselected-function-as-opposed-to-all\">Using the ALLSELECTED Function as Opposed to ALL<\/h3>\n\n\n\n<p>Sometimes you\u2019ll want to reference just the selected items in a dimension, in a slicer, for example, rather than include all of the items in your formula. Here\u2019s an example of a matrix where you might want to do this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"399\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-105.png\" alt=\"\" class=\"wp-image-82938\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The measure shown initially is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% of all sales = DIVIDE(\n    \/\/ divide number of sales for filter context ...\n    COUNT(Sales[SalesId]),\n    \/\/ ... number of sales for all countries\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        ALL(Country[CountryName])\n    )\n)<\/pre>\n\n\n\n<p>The figures don\u2019t add up to 100% because for each country the statistic shown equals:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">the number of sales for that country \/ \nthe number of sales for all countries<\/pre>\n\n\n\n<p>In this example the USA is included in the denominator but not in the numerator. To get the statistic to work, you need to reference only the selected countries in the denominator:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">% of selected country sales = DIVIDE(\n    \/\/ take the number of sales for each country\n    COUNT(Sales[SalesId]),\n    \/\/ divide this by the number of sales for all \n    \/\/ currently selected countries\n    CALCULATE(\n        COUNT(Sales[SalesId]),\n        ALLSELECTED(Country[CountryName])\n    )\n)<\/pre>\n\n\n\n<p>This gives the required 100% total, regardless of the combination of countries you select in the slicer:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"391\" height=\"403\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-106.png\" alt=\"\" class=\"wp-image-82939\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-context-transition-using-the-calculate-function\">Context Transition Using the CALCULATE Function<\/h3>\n\n\n\n<p>Before moving on from the <code>CALCULATE<\/code> function, it has one more string to its bow. Consider the following two formulae:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales A = SUMX(Sales,[Price]*[Quantity])\nTotal sales B = CALCULATE(SUMX(Sales,[Price]*[Quantity]))<\/pre>\n\n\n\n<p>If you\u2019ve been following up to now, you\u2019ll realise that these two formulae must give the same result under all circumstances:<\/p>\n\n\n\n<p>The first formula gives the total sales value for the current filter context;<\/p>\n\n\n\n<p>The second formula gives the total sales value for the current filter context, with no extra modifications to it.<\/p>\n\n\n\n<p>However \u2026 what happens if there isn\u2019t a filter context to begin with? In this case the second formula will create a filter context, and hence return a different answer than the first. How can you not have a filter context? By creating a calculated column in a table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"157\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-107.png\" alt=\"\" class=\"wp-image-82940\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The first formula gives the same result for each row. Because calculated columns don\u2019t have a filter context by default, the formula sums sales over all of the rows in the sales table, giving the same answer (238.32) for each.<\/p>\n\n\n\n<p>Remember that the second formula is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Total sales B = CALCULATE(SUMX(Sales,[Price]*[Quantity]))<\/pre>\n\n\n\n<p>The <code>CALCULATE<\/code> function doesn\u2019t just allow you to change the filter context, it can create it, too. For each country, this creates a filter context, limiting the rows in the sales table to those for the country in question, and hence giving a different answer for each row of the above table. The process of changing row context into filter context in this way is called <em>context transition<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-values-function\">The VALUES Function<\/h2>\n\n\n\n<p>Learning the <code>CALCULATE<\/code> function is key to understanding how to create measures in DAX, but the <code>VALUES<\/code> function runs it a close second. The rest of this article shows what this function does, and how to use it to create a range of effects in your Power BI reports.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-the-values-function-returns\">What the VALUES function returns<\/h3>\n\n\n\n<p>The <code>VALUES<\/code> function returns the table of data for the current filter context. To explain what this sentence means, here\u2019s an example. Suppose you create this table in a Power BI report:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"231\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-108.png\" alt=\"\" class=\"wp-image-82941\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Note for this example that I\u2019ve used a filter (not shown here) on the report to avoid showing any blank countries). The <em>Number of cities<\/em> column shows the number of cities for each country, using the following measure:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Number of cities = COUNTROWS(VALUES(City[CityName]))<\/pre>\n\n\n\n<p>If you could look at the filter context, this is what you would see:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"514\" height=\"277\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-109.png\" alt=\"\" class=\"wp-image-82942\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The <code>VALUES<\/code> function allows you to return a table containing one or more of the columns in the current filter context\u2019s underlying table. For example, you could create this measure:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = VALUES(City[CityName])<\/pre>\n\n\n\n<p>If you display this measure in your Power BI report, you\u2019ll get this error message:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"485\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-110.png\" alt=\"\" class=\"wp-image-82943\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The problem is that you\u2019re trying to display a column of values in a single cell. This would work for Brazil and China, each of which only has one city, but wouldn\u2019t work for the other three countries.<\/p>\n\n\n\n<p>What you could do, however, is to test whether there is only one city for a country, and in this event show its name; otherwise, you could show a message saying that there are multiple cities. Here\u2019s a measure to do this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = IF(\n    \/\/ if there is  one city for the current \n    \/\/ filter context ...\n    COUNTROWS(VALUES(City[CityName])) = 1,\n    \/\/ ... shows the city's name\n    VALUES(City[CityName]),\n    \/\/ Otherwise, show a message\n    \"More than one city\"\n)<\/pre>\n\n\n\n<p>Displaying this measure in our report would give:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"432\" height=\"226\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-111.png\" alt=\"\" class=\"wp-image-82944\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For the total row there are lots of cities in the current filter context, so naturally you get the <em>More than one city<\/em> message.<\/p>\n\n\n\n<p>The above example shows two important features of the <code>VALUES<\/code> function. The first is that it returns a table of data. In the measure above, the <code>COUNTROWS<\/code> function expects to receive a table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"123\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-112.png\" alt=\"\" class=\"wp-image-82945\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Fortunately, that\u2019s what\u2019s supplied:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"368\" height=\"81\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-113.png\" alt=\"\" class=\"wp-image-82946\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The <code>VALUES<\/code> function in this case returns a single-column table which looks like this for each of the 5 countries:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"135\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-114.png\" alt=\"\" class=\"wp-image-82947\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The second important point to understand about the <code>VALUES<\/code> function is that you can\u2019t put a table into a cell without performing some sort of aggregation on it first, since a table can potentially contain multiple values. What this means is that the selected part of the measure below shouldn\u2019t work:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"374\" height=\"273\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-115.png\" alt=\"\" class=\"wp-image-82948\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This is because the <code>VALUES<\/code> function returns a column of data, and even though you know that there is only one row in this column, and hence only one value, you would normally still need to apply some aggregation function (e.g., <code>MAX<\/code>, <code>MIN<\/code>, <code>SUM<\/code>) to the data.<\/p>\n\n\n\n<p>Happily, there is one exception to this rule. If a call to the <code>VALUES<\/code> function returns a table with one column and one row, you can automatically treat this as a single scalar value without any additional work. This is why this measure works!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-hasonevalue-function-and-other-alternatives\">The HASONEVALUE Function and Other Alternatives<\/h3>\n\n\n\n<p>Checking whether the filter context only contains one value for a particular column is a common thing to do. It\u2019s so common, in fact, that DAX has a dedicated function called <code>HASONEVALUE<\/code> to do this.<\/p>\n\n\n\n<p>You could rewrite the measure like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = IF(\n    \/\/ if there is  one city for the current \n    \/\/ filter context ...\n    HASONEVALUE(City[CityName]),\n    \/\/ ... shows the city's name\n    VALUES(City[CityName]),\n    \/\/ Otherwise, show a message\n    \"More than one city\"\n)<\/pre>\n\n\n\n<p>Another solution would be to count how many distinct city names there are in the current filter context:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = IF(\n    \/\/ if there is  one city for the current \n    \/\/ filter context ...\n    DISTINCTCOUNT(City[CityName]) = 1,\n    \/\/ ... shows the city's name\n    VALUES(City[CityName]),\n    \/\/ Otherwise, show a message\n    \"More than one city\"\n)<\/pre>\n\n\n\n<p>These three methods, using <code>VALUES<\/code>, <code>HASONEVALUE<\/code> or <code>DISTINCTCOUNT<\/code>, are interchangeable, and I don\u2019t think there\u2019s any clear reason to favour one over another.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-concatenatex-to-list-out-multiple-values\">Using CONCATENATEX to List Out Multiple Values<\/h3>\n\n\n\n<p>For this example, you might want to list out the names of the cities for each country. You can do this using the <code>CONCATENATEX<\/code> function, which has this syntax:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"512\" height=\"104\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-116.png\" alt=\"\" class=\"wp-image-82949\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The arguments to this function are thus:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>The table containing the values you want to concatenate<\/li>\n\n\n\n<li>The column in this table containing the values to concatenate. You have to specify this even if the table only has one column, even though in this case it is blindingly obvious that this is the one you should choose!<\/li>\n\n\n\n<li>The text you want to use as glue to join the column values together<\/li>\n\n\n\n<li>Which column you want to order by. Again you need to specify this, even if you know you\u2019re working with a single-column table.<\/li>\n\n\n\n<li>The order-by direction, ascending or descending<\/li>\n<\/ul>\n<\/div>\n\n\n<p>For this example, you could modify the measure to read like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = IF(\n    \/\/ if there is one city for the current \n    \/\/ filter context ...\n    DISTINCTCOUNT(City[CityName]) = 1,\n    \/\/ ... shows the city's name\n    VALUES(City[CityName]),\n    \/\/ Otherwise, list all city names    \n    CONCATENATEX(\n        VALUES(City[CityName]),\n        City[CityName],\n        \",\",\n        City[CityName],\n        ASC\n    )\n)<\/pre>\n\n\n\n<p>This more or less works, since it gives this table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"244\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-117.png\" alt=\"\" class=\"wp-image-82950\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The only remaining problem is that the total row now looks odd. Technically it is correct, because, for this row, the filter context contains all of the cities for all countries. A better solution would be to check whether there is more than one country in the filter context:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Cities = IF(\n    \/\/ if there's only one country in the filter context ... \n    HASONEVALUE(Country[CountryName]),\n    \/\/ ... show the city name or names ...\n    IF(\n        \/\/ if there is  one city for the current \n        \/\/ filter context ...\n        DISTINCTCOUNT(City[CityName]) = 1,\n        \/\/ ... shows the city's name\n        VALUES(City[CityName]),\n        \/\/ Otherwise, list all city names    \n        CONCATENATEX(\n            VALUES(City[CityName]),\n            City[CityName],\n            \",\",\n            City[CityName],\n            ASC\n        )\n    ),\n    \/\/ ... or otherwise show nothing\n    BLANK()\n)<\/pre>\n\n\n\n<p>This is what you should now see when using this measure in the table:<\/p>\n\n\n\n<p>All of this illustrates an important point about DAX measures. You can create a measure which gives sensible results for one particular visual, but can you be sure that it will give sensible results in another? Or in a totals row? Or a totals column, or grand total? You\u2019ll often be faced with a trade-off in DAX between checking that a measure works under all possible circumstances and keeping things simple.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-modifying-the-filter-context-using-values\">Modifying the Filter Context Using VALUES<\/h3>\n\n\n\n<p>Suppose that you now want to display the total sales for each country apart from the UK. The obvious way to do this is to sum total sales, but using the <code>CALCULATE<\/code> function to amend the filter context to omit the UK:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Value of sales = CALCULATE(\n    \/\/ calculate total sales value\n    SUMX(\n        Sales,\n        [Price] * [Quantity]\n    ),\n    \/\/ country not UK\n    Country[CountryName] &lt;&gt; \"UK\"\n)<\/pre>\n\n\n\n<p>This suffers from one major problem \u2013 it doesn\u2019t work! Displaying this measure in a table would show the same value for every country:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"369\" height=\"197\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-119.png\" alt=\"\" class=\"wp-image-82952\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>To understand why this measure is showing 166.57 for every country, remember what I said earlier in this article: when you apply a filter, it replaces the current filter context for a dimension. For this example you\u2019re adding this filter to the <code>CALCULATE<\/code> function:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"254\" height=\"51\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-120.png\" alt=\"\" class=\"wp-image-82953\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>What this does is to lose any existing filter by the country dimension and replace it with one where the country is UK. Here\u2019s what\u2019s going on for each country:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"332\" height=\"154\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-121.png\" alt=\"\" class=\"wp-image-82954\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The total sales value for all of the countries apart from the UK is 166.57, so that\u2019s what gets displayed in every row. What you want to do is to keep the existing filter context constraints for the country dimension, but then add to them. One way to do this is to use the <code>VALUES<\/code> function, making the new measure read like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Value of sales = CALCULATE(\n    \/\/ calculate total sales value\n    SUMX(\n        Sales,\n        [Price] * [Quantity]\n    ),\n    \/\/ keep the country filter as it is\n    VALUES(Country[CountryName]),\n    \/\/ and add that the country should not be the UK\n    Country[CountryName] &lt;&gt; \"UK\"\n)<\/pre>\n\n\n\n<p>This would give the following results:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"198\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-122.png\" alt=\"\" class=\"wp-image-82955\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>If you\u2019re wondering why there is a discrepancy between the 166.57 shown in the first table and the 150.37 shown in the second, it\u2019s explained by the fact that I had filtered the table to remove any sales taking place with no assigned country. If you remove this filter you get:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"375\" height=\"224\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-123.png\" alt=\"\" class=\"wp-image-82956\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Add these 16.20 of sales in as above and you would get the required figure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-disconnected-slicers-to-make-reports-dynamic\">Using Disconnected Slicers to Make Reports Dynamic<\/h3>\n\n\n\n<p>This is a clever idea, which allows you to make reports dynamic. The idea is to create a slicer which allows you to choose which measure you want to show. In the example below, someone has chosen to show the average price of sales:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"269\" height=\"367\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-124.png\" alt=\"\" class=\"wp-image-82957\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>To make this work, first create a table to hold the statistics that you might want to report:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"275\" height=\"304\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-125.png\" alt=\"\" class=\"wp-image-82958\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>However, don\u2019t link this table to any other. That\u2019s why this technique is often called a \u201cdisconnected slicer\u201d. Now create a slicer based upon this table:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"291\" height=\"364\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-126.png\" alt=\"\" class=\"wp-image-82959\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The idea is that when you select a statistic in the slicer, the bottom table will show its value. All that you now need to do is to create and show a measure which will yield:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>The average price of sales if someone selects the first measure;<\/li>\n\n\n\n<li>The number of sales records if someone selects the second measure;<\/li>\n\n\n\n<li>The total value of sales if someone selects the third measure; or<\/li>\n\n\n\n<li>A blank if someone selects more than one statistic at a time or doesn\u2019t select one at all.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>Here\u2019s what this measure might look like!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Statistic = \n    \/\/ first find out what user wants to see (assume one thing chosen)\n    VAR Choice = SELECTEDVALUE('What to show'[Statistic])\n    \/\/ return different measure according to choice\n    RETURN\n        IF(\n            HASONEVALUE('What to show'[Statistic]),\n            SWITCH (\n                Choice,\n                \"Average price\", AVERAGE(Sales[Price]),\n                \"Number of sales\", COUNTROWS(Sales),\n                \"Total sales\",SUMX(Sales,[Price]*[Quantity])\n            ),\n            BLANK()\n        )<\/pre>\n\n\n\n<p>One final question: is it possible to display different statistics using different number formatting? I can\u2019t think of any way to do this except to use the <code>FORMAT<\/code> function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Statistic = \n    \/\/ first find out what user wants to see (assume one thing chosen)\n    VAR Choice = SELECTEDVALUE('What to show'[Statistic])\n    \/\/ return different measure according to choice\n    RETURN\n        IF(\n            HASONEVALUE('What to show'[Statistic]),\n            SWITCH (\n                Choice,\n                \"Average price\", FORMAT(AVERAGE(Sales[Price]),\"0.00\"),\n                \"Number of sales\", FORMAT(COUNTROWS(Sales),\"#,##0\"),\n                \"Total sales\",FORMAT(SUMX(Sales,[Price]*\n                                        [Quantity]),\"#,##0.00\")\n            ),\n            BLANK()\n        )<\/pre>\n\n\n\n<p>The problem with this is that the <code>FORMAT<\/code> function turns numbers into text, although because it does so only after the calculation is complete for each filter context, this shouldn\u2019t cause too much of a problem. Here\u2019s what you\u2019d see for the number of sales for the above measure, for example:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"280\" height=\"363\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-127.png\" alt=\"\" class=\"wp-image-82960\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>And just in case you\u2019re wondering, I can\u2019t think of any way to change the column title dynamically!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-dynamic-titles\">Dynamic Titles<\/h3>\n\n\n\n<p>There\u2019s one more thing to demonstrate with the creative use of the <code>VALUES<\/code> function: how to show the choices made in a slicer. For the report page below, you\u2019d like a card visual (shown selected) to display a measure listing the countries chosen:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"314\" height=\"473\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-128.png\" alt=\"\" class=\"wp-image-82961\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Here are some examples of what the card should display:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>For the choices shown above, it should read \u201cBrazil, China, India, UK\u201d<\/li>\n\n\n\n<li>If a user doesn\u2019t select a country, it should read \u201cAll countries\u201d<\/li>\n\n\n\n<li>If a user picks a single country, it should give the country\u2019s name<\/li>\n<\/ul>\n<\/div>\n\n\n<p>If you\u2019ve been following the article so far, there\u2019s nothing new with this \u2013 it just combines lots of the ideas you\u2019ve already seen. Here\u2019s a measure which would fit the bill:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Title = IF(\n    \/\/ if there are countries selected ...\n    ISFILTERED(Country[CountryName]),\n    \/\/ test to see if one, or more than one\n    IF(\n        HASONEVALUE(Country[CountryName]),\n        \/\/ there's one country selected; show it (but must use\n        \/\/ the VALUES function to convert the single column, \n        \/\/ single row table into a scalar\n        VALUES(Country[CountryName]),\n        \/\/ otherwise, join the country names together\n        CONCATENATEX(\n            Country,\n            Country[CountryName],\n            \",\",\n            Country[CountryName],\n            ASC\n        )\n    ),\n    \/\/ if we get here, then user didn't select\n    \/\/ any countries\n    \"All countries\"\n)<\/pre>\n\n\n\n<p>Here\u2019s what this would show if you have one country selected assuming that you attach the measure to your card:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"306\" height=\"385\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-129.png\" alt=\"\" class=\"wp-image-82962\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>If you have multiple countries selected, you\u2019ll see this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"316\" height=\"393\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-130.png\" alt=\"\" class=\"wp-image-82963\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>And finally, if you have no countries selected, you\u2019ll see this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"310\" height=\"464\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/01\/word-image-131.png\" alt=\"\" class=\"wp-image-82964\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>If you want to be even fancier you could use a quick measure to display only the first 3 countries in any list which I covered in the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-measures-using-dax\/\">previous article in this series<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>This article has shown how you can use two of the most important DAX functions: <code>CALCULATE<\/code> and <code>VALUES<\/code>. The article began by showing how you can use the <code>CALCULATE<\/code> function to amend the default filter context, mainly in order to create ratios. I then showed how you can use functions like <code>VALUES<\/code>, <code>HASONEVALUE<\/code> and <code>ISFILTERED<\/code> to produce a variety of clever effects in DAX. The next article in this series will look at the <code>FILTER<\/code> and <code>EARLIER<\/code> functions. You should make sure that you understand clearly how you can use the <code>CALCULATE<\/code> function to change filter context before progressing, since the DAX formulae won\u2019t get any easier!<\/p>\n\n\n\n<p><strong>Read also:<\/strong> <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/model-optimization-available-in-mdx-property-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Power BI model optimization<\/a><\/p>\n\n\n\n<section id=\"faq\" class=\"faq-block my-5xl\">\n    <h2>FAQs: How to use the DAX CALCULATE and VALUES functions<\/h2>\n\n                        <h3 class=\"mt-4xl\">1. What does the CALCULATE function do in DAX?<\/h3>\n            <div class=\"faq-answer\">\n                <p>CALCULATE evaluates a DAX expression (typically a measure or aggregation) in a modified filter context. You pass it the expression to evaluate and one or more filter arguments that add, replace, or remove filters from the current context. This is how you compute values like &#8220;total sales for all products&#8221; even when viewing a specific product in a visual.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">2. How do you calculate percentage of total in DAX?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Use CALCULATE with ALL to remove filters from the denominator. The pattern is: Pct of Total = DIVIDE([Sales], CALCULATE([Sales], ALL(Table))). The numerator respects the current filter context (showing sales for the current row&#8217;s product\/region), while the denominator uses ALL to calculate total sales across all values.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">3. What is filter context in DAX?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Filter context is the set of filters active on a calculation at any given point. In a visual, filter context comes from slicers, rows, columns, and page-level filters. CALCULATE lets you override this context &#8211; for example, removing a product filter to get a &#8220;total across all products&#8221; denominator while the numerator still shows the specific product&#8217;s value.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">4. What is the difference between CALCULATE and CALCULATETABLE in DAX?<\/h3>\n            <div class=\"faq-answer\">\n                <p>CALCULATE returns a single scalar value (a number, string, or date). CALCULATETABLE returns an entire table. Use CALCULATE for measures that produce a single result, and CALCULATETABLE when you need to generate a filtered table for use inside other DAX functions like SUMX or COUNTROWS.<\/p>\n            <\/div>\n            <\/section>\n","protected":false},"excerpt":{"rendered":"<p>Understand the DAX CALCULATE and VALUES functions with practical examples. Learn filter context, ALL function, and how to build percentage calculations in Power BI.&hellip;<\/p>\n","protected":false},"author":9783,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143528],"tags":[],"coauthors":[6782],"class_list":["post-82927","post","type-post","status-publish","format-standard","hentry","category-bi-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82927","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\/9783"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=82927"}],"version-history":[{"count":14,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82927\/revisions"}],"predecessor-version":[{"id":109026,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82927\/revisions\/109026"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=82927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=82927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=82927"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=82927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}