{"id":12441,"date":"2025-07-06T11:05:55","date_gmt":"2025-07-06T05:20:55","guid":{"rendered":"https:\/\/nestnepal.com\/blog\/?p=12441"},"modified":"2025-08-11T13:36:22","modified_gmt":"2025-08-11T07:51:22","slug":"dax-in-power-bi-with-14-understandable-examples","status":"publish","type":"post","link":"https:\/\/nestnepal.com\/blog\/dax-in-power-bi-with-14-understandable-examples\/","title":{"rendered":"Understanding DAX (Data Analysis Expressions) with Simple Examples"},"content":{"rendered":"\n<p>Let&#8217;s be honest\u2014DAX scares the crap out of most people when they first see it. You&#8217;re cruising along in <a href=\"https:\/\/nestnepal.com\/microsoft-power-bi-in-nepal\/\">Power BI<\/a>, dragging and dropping fields like a pro, and then suddenly you need to write some formula that looks like alien code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"669\" height=\"372\" data-src=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/07\/DAX.jpeg\" alt=\"DAX\" class=\"wp-image-12442 lazyload\" data-srcset=\"https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/07\/DAX.jpeg 669w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/07\/DAX-300x167.jpeg 300w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/07\/DAX-380x211.jpeg 380w, https:\/\/nestnepal.com\/blog\/wp-content\/uploads\/2025\/07\/DAX-550x306.jpeg 550w\" data-sizes=\"(max-width: 669px) 100vw, 669px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 669px; --smush-placeholder-aspect-ratio: 669\/372;\" \/><\/figure>\n\n\n\n<p>But here&#8217;s the thing: <a href=\"https:\/\/learn.microsoft.com\/en-us\/dax\/\" target=\"_blank\" rel=\"noopener\">DAX<\/a> isn&#8217;t actually that hard once you understand the basics. It&#8217;s just different from Excel formulas, and that&#8217;s where people get tripped up. Let me walk you through it with examples that actually make sense.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What the Hell is DAX Anyway?<\/strong><\/h2>\n\n\n\n<p>DAX stands for Data Analysis Expressions. It&#8217;s the formula language that Power BI (and Excel Power Pivot and Analysis Services) uses to create calculated columns, measures, and calculated tables.<\/p>\n\n\n\n<p>Think of it like this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Excel formulas<\/strong> work on individual cells<\/li>\n\n\n\n<li><strong>DAX formulas<\/strong> work on entire columns and tables<\/li>\n<\/ul>\n\n\n\n<p>That&#8217;s the fundamental shift you need to wrap your head around.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>DAX vs Excel: The Mental Shift<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Excel Thinking<\/strong><\/td><td><strong>DAX Thinking<\/strong><\/td><\/tr><tr><td>=A1*B1<\/td><td>= Sales[Quantity] * Sales[Price]<\/td><\/tr><tr><td>Works on single cells<\/td><td>Works on entire columns<\/td><\/tr><tr><td>SUM(A1:A100)<\/td><td>SUM(Sales[Amount])<\/td><\/tr><tr><td>References ranges<\/td><td>References tables and columns<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Two Main Types of DAX Formulas<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Calculated Columns<\/strong><\/h3>\n\n\n\n<p>These create new columns in your tables. They&#8217;re calculated row by row, like Excel formulas.<\/p>\n\n\n\n<p><strong>When to use<\/strong>: When you need a value for each row that you can filter or group by.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Measures<\/strong><\/h3>\n\n\n\n<p>These are dynamic calculations that change based on context (filters, slicers, etc.).<\/p>\n\n\n\n<p><strong>When to use<\/strong>: When you need aggregated values that respond to user interactions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Let&#8217;s Start with Simple Calculated Columns<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 1: Basic Math<\/strong><\/h3>\n\n\n\n<p>Say you have a Sales table with Quantity and Unit Price columns, and you want the Total Amount:<\/p>\n\n\n\n<p>Total Amount = Sales[Quantity] * Sales[UnitPrice]<\/p>\n\n\n\n<p>This multiplies the quantity by the unit price for each row. Simple enough, right?<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 2: Text Manipulation<\/strong><\/h3>\n\n\n\n<p>Want to combine first and last names?<\/p>\n\n\n\n<p>Full Name = Customers[FirstName] &amp; &#8221; &#8221; &amp; Customers[LastName]<\/p>\n\n\n\n<p>The &amp; operator concatenates text in DAX (like Excel).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 3: Conditional Logic<\/strong><\/h3>\n\n\n\n<p>Let&#8217;s categorize sales amounts:<\/p>\n\n\n\n<p>Sales Category =<\/p>\n\n\n\n<p>IF(<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0\u00a0Sales [Amount] > 1000,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&#8220;High Value&#8221;,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;IF(<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Sales [Amount] > 500,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;Medium Value&#8221;,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;Low Value&#8221;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;)<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>This creates a nested IF statement. Each row gets categorized based on its sales amount.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Now Let&#8217;s Talk Measures (The Real Power)<\/strong><\/h2>\n\n\n\n<p>Measures are where DAX gets interesting. They&#8217;re dynamic and change based on what&#8217;s selected in your report.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 4: Basic Aggregation<\/strong><\/h3>\n\n\n\n<p>Total Sales = SUM (Sales[Amount])<\/p>\n\n\n\n<p>This looks simple, but here&#8217;s the magic: this measure will show different values depending on what&#8217;s filtered. If a user selects &#8220;January&#8221; in a date slicer, it shows January sales. If they select &#8220;Product A&#8221;, it shows Product A sales.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 5: Counting Things<\/strong><\/h3>\n\n\n\n<p>Number of Customers = DISTINCTCOUNT(Sales[CustomerID])<\/p>\n\n\n\n<p>DISTINCTCOUNT counts unique values. This measure tells you how many different customers made purchases (based on current filters).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 6: Averages That Make Sense<\/strong><\/h3>\n\n\n\n<p>Average Order Value = DIVIDE(SUM(Sales[Amount]), DISTINCTCOUNT(Sales[OrderID]))<\/p>\n\n\n\n<p>This calculates average order value properly\u2014total sales divided by the number of unique orders. The DIVIDE function handles division by zero gracefully.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Time Intelligence: The DAX Superpower<\/strong><\/h2>\n\n\n\n<p>DAX has built-in functions for time-based calculations that would be a nightmare in Excel.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 7: Year-to-Date<\/strong><\/h3>\n\n\n\n<p>YTD Sales = TOTALYTD(SUM(Sales[Amount]), Calendar[Date])<\/p>\n\n\n\n<p>This automatically calculates year-to-date sales based on the current filter context. Select any date, and it shows YTD through that date.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 8: Previous Month<\/strong><\/h3>\n\n\n\n<p>Previous Month Sales = CALCULATE(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;SUM(Sales[Amount]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;PREVIOUSMONTH(Calendar[Date])<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>CALCULATE is probably the most important DAX function. It changes the filter context. Here, it&#8217;s saying, &#8220;Calculate sales but for the previous month instead of the current selection.&#8221;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 9: Month-over-Month Growth<\/strong><\/h3>\n\n\n\n<p>MoM Growth % =<\/p>\n\n\n\n<p>VAR CurrentMonth = SUM(Sales[Amount])<\/p>\n\n\n\n<p>VAR PreviousMonth = CALCULATE(SUM(Sales[Amount]), PREVIOUSMONTH(Calendar[Date]))<\/p>\n\n\n\n<p>RETURN<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;DIVIDE(CurrentMonth &#8211; PreviousMonth, PreviousMonth) * 100<\/p>\n\n\n\n<p>This introduces VAR (variables)\u2014a way to store intermediate calculations and make your formulas readable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Filter Context: The Thing That Confuses Everyone<\/strong><\/h2>\n\n\n\n<p>Filter context is what makes measures dynamic. It&#8217;s the combination of:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What row you&#8217;re looking at (row context)<\/li>\n\n\n\n<li>What filters are applied (filter context)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 10: Understanding Context<\/strong><\/h3>\n\n\n\n<p>Sales for Product A = CALCULATE(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;SUM(Sales[Amount]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;Products[ProductName] = &#8220;Product A&#8221;<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>This measure always shows sales for Product A, regardless of what&#8217;s selected. The CALCULATE function overrides the current filter context.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 11: Multiple Filters<\/strong><\/h3>\n\n\n\n<p>High Value Sales This Year = CALCULATE(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;SUM(Sales[Amount]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;Sales[Amount] &gt; 1000,<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;YEAR(Sales[Date]) = YEAR(TODAY())<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>You can stack multiple filter conditions in CALCULATE. This shows sales over $1000 for the current year only.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Practical Examples You&#8217;ll Actually Use<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 12: Running Total<\/strong><\/h3>\n\n\n\n<p>Running Total =&nbsp;<\/p>\n\n\n\n<p>CALCULATE(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;SUM(Sales[Amount]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;FILTER(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL(Sales[Date]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sales[Date] &lt;= MAX(Sales[Date])<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;)<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>This creates a running total that accumulates as you move through dates. ALL removes filters, then FILTER applies a new condition.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 13: Ranking<\/strong><\/h3>\n\n\n\n<p>Customer Rank = RANKX(ALL(Customers), [Total Sales],, DESC)<\/p>\n\n\n\n<p>RANKX ranks customers by their total sales. ALL(Customers) ensures ranking is done across all customers, not just the visible ones.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 14: Percentage of Total<\/strong><\/h3>\n\n\n\n<p>% of Total Sales =&nbsp;<\/p>\n\n\n\n<p>DIVIDE(<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;SUM(Sales[Amount]),<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;CALCULATE(SUM(Sales[Amount]), ALL(Sales))<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>This shows what percentage each item represents of the grand total.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common DAX Functions You Should Know<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Function<\/strong><\/td><td><strong>What It Does<\/strong><\/td><td><strong>Example Use<\/strong><\/td><\/tr><tr><td>SUM()<\/td><td>Adds up values<\/td><td>SUM(Sales[Amount])<\/td><\/tr><tr><td>COUNT()<\/td><td>Counts non-blank values<\/td><td>COUNT(Sales[OrderID])<\/td><\/tr><tr><td>DISTINCTCOUNT()<\/td><td>Counts unique values<\/td><td>DISTINCTCOUNT(Sales[CustomerID])<\/td><\/tr><tr><td>AVERAGE()<\/td><td>Calculates average<\/td><td>AVERAGE(Sales[Amount])<\/td><\/tr><tr><td>CALCULATE()<\/td><td>Changes filter context<\/td><td>CALCULATE(SUM(Sales[Amount]), Sales[Region] = &#8220;East&#8221;)<\/td><\/tr><tr><td>IF()<\/td><td>Conditional logic<\/td><td>IF(Sales[Amount] &gt; 1000, &#8220;High&#8221;, &#8220;Low&#8221;)<\/td><\/tr><tr><td>DIVIDE()<\/td><td>Safe division<\/td><td>DIVIDE(Sales[Profit], Sales[Amount])<\/td><\/tr><tr><td>RELATED()<\/td><td>Gets value from related table<\/td><td>RELATED(Products[Category])<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>DAX Best Practices That Matter<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Use Variables for Readability<\/strong><\/h3>\n\n\n\n<p><strong>Bad:<\/strong><\/p>\n\n\n\n<p>Profit Margin = DIVIDE(SUM(Sales[Amount]) &#8211; SUM(Sales[Cost]), SUM(Sales[Amount]))<\/p>\n\n\n\n<p><strong>Good:<\/strong><\/p>\n\n\n\n<p>Profit Margin =&nbsp;<\/p>\n\n\n\n<p>VAR Revenue = SUM(Sales[Amount])<\/p>\n\n\n\n<p>VAR Cost = SUM(Sales[Cost])<\/p>\n\n\n\n<p>RETURN<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;DIVIDE(Revenue &#8211; Cost, Revenue)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Use DIVIDE Instead of Division Operator<\/strong><\/h3>\n\n\n\n<p><strong>Bad:<\/strong> = Sales[Profit] \/ Sales[Revenue] (crashes on zero) <strong>Good:<\/strong> = DIVIDE(Sales[Profit], Sales[Revenue]) (returns blank on zero)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Be Explicit with Table Names<\/strong><\/h3>\n\n\n\n<p><strong>Bad:<\/strong> = SUM(Amount) <strong>Good:<\/strong> = SUM(Sales[Amount])<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Use Measures, Not Calculated Columns for Aggregations<\/strong><\/h3>\n\n\n\n<p>If you&#8217;re summing, counting, or averaging, use a measure. Calculated columns are for row-level calculations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Debugging DAX (When Things Go Wrong)<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Common Error Messages and Fixes<\/strong><\/h3>\n\n\n\n<p><strong>&#8220;Circular dependency detected&#8221;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You&#8217;re referencing a column\/measure that references itself<\/li>\n\n\n\n<li>Check your formula for self-references<\/li>\n<\/ul>\n\n\n\n<p><strong>&#8220;A table of multiple values was supplied where a single value was expected&#8221;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Usually happens when you use a function expecting a single value but get multiple<\/li>\n\n\n\n<li>Wrap in an aggregation function like SUM() or use VALUES()<\/li>\n<\/ul>\n\n\n\n<p><strong>&#8220;Cannot find table\/column&#8221;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Typo in table or column name<\/li>\n\n\n\n<li>Table\/column was renamed or deleted<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Quick Debugging Tips<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use VAR to break down complex formulas<\/li>\n\n\n\n<li>Create simple versions first, then add complexity<\/li>\n\n\n\n<li>Use the DAX Studio tool for advanced debugging<\/li>\n\n\n\n<li>Test with simple data first<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Learning Path: What to Master Next<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Start here<\/strong>: Basic aggregations (SUM, COUNT, AVERAGE)<\/li>\n\n\n\n<li><strong>Then learn<\/strong>: CALCULATE and filter context<\/li>\n\n\n\n<li><strong>Add<\/strong>: Time intelligence functions<\/li>\n\n\n\n<li><strong>Master<\/strong>: FILTER, ALL, ALLEXCEPT<\/li>\n\n\n\n<li><strong>Advanced<\/strong>: Table functions and complex relationships<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Reality Check<\/strong><\/h2>\n\n\n\n<p>DAX can get incredibly complex, but you don&#8217;t need to master everything at once. Focus on solving real problems with simple formulas first. As you get comfortable, you&#8217;ll naturally start combining functions and building more sophisticated calculations.<\/p>\n\n\n\n<p>Most of the DAX you&#8217;ll write in real life is actually pretty straightforward &#8211; basic aggregations with some time intelligence thrown in. The complex stuff comes later when you&#8217;re building advanced analytics.<\/p>\n\n\n\n<p>Start simple, test everything, and don&#8217;t be afraid to break things. That&#8217;s how you learn DAX for real.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s be honest\u2014DAX scares the crap out of most people when they first see it. You&#8217;re cruising along in Power&#8230;<\/p>\n","protected":false},"author":15,"featured_media":12949,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[422],"tags":[446,445],"class_list":["post-12441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft","tag-microsoft","tag-power-bi"],"_links":{"self":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/12441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/comments?post=12441"}],"version-history":[{"count":1,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/12441\/revisions"}],"predecessor-version":[{"id":12443,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/posts\/12441\/revisions\/12443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media\/12949"}],"wp:attachment":[{"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/media?parent=12441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/categories?post=12441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestnepal.com\/blog\/wp-json\/wp\/v2\/tags?post=12441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}