The most common mistake when learning DAX is memorizing functions in isolation. The right way is to build the measures frequently needed in real business scenarios, example by example. In this article we'll cover 10 practical DAX examples.
01. Sales Total and the Total Measure
The most basic measure: Total Sales = SUM(Sales[Amount]). If you define this as a measure, it becomes filter-sensitive; if you add it as a column, it stays static.
02. Year-over-Year (YoY) Growth
YoY Growth % = DIVIDE([Total Sales] - CALCULATE([Total Sales], SAMEPERIODLASTYEAR(Date[Date])), CALCULATE([Total Sales], SAMEPERIODLASTYEAR(Date[Date]))). This measure gives the growth percentage versus last year.
03. Year-to-Date (YTD)
YTD Sales = CALCULATE([Total Sales], DATESYTD(Date[Date])). Total sales from the start of the year to today. Critical in monthly reports.
04. Moving Average (7-Day)
7d MA = AVERAGEX(DATESINPERIOD(Date[Date], LASTDATE(Date[Date]), -7, DAY), [Total Sales]). Ideal for smoothing short-term trends.
05. Top N Customers
Top 10 Customers = RANKX(ALL(Customer[Name]), [Total Sales]). If a filter constraint of <=10 is added, it returns the top 10 customers.
06. Contribution %
Contribution % = DIVIDE([Total Sales], CALCULATE([Total Sales], ALLSELECTED())). Gives the contribution share to the total within the selected filter.
07. Running Total
Running Total = CALCULATE([Total Sales], FILTER(ALLSELECTED(Date[Date]), Date[Date] <= MAX(Date[Date]))). For a cumulative-total chart.
08. What-If Parameters
New Target = SELECTEDVALUE(TargetParam[Value]) * [Base Value]. Lets the user change scenarios with a slider.
09. Today's Value
Today Sales = CALCULATE([Total Sales], Date[Date] = TODAY()). Needed for real-time indicators.
10. Blank Check
Safe Divide = DIVIDE([Numerator], [Denominator]). Doesn't throw a divide-by-zero error; returns blank instead. A small but life-saving function.
Explore our Power BI solution
You can book a free consultation call to get detailed information.