Foundations › Power BI › DAX: Calculate Smartly
DAX: Calculate SmartlyDAX from Zero: Your First Measures
DAX is the formula language of Power BI. You do not need to memorise it: the real skill is reading a formula as a logical sentence ("add up the Sales column"). We start simple, and every example here can be edited and run on the fictional Nile Retail data.
Your first measure: total sales
A measure is written as: name, an = sign, then the calculation. Afterwards you refer to it by name in square brackets, like [Total Sales].
Total Sales = SUM(FactSales[Sales])Press Run: this is the total of all 2024 and 2025 sales. Try changing Sales to Cost or Quantity and watch the number.
Four aggregations that cover 80% of your work
Total Sales = SUM(FactSales[Sales])
Orders = COUNTROWS(FactSales)
Customers = DISTINCTCOUNT(FactSales[CustomerID])
Avg Order Value = DIVIDE([Total Sales], [Orders])The same formulas returned different numbers for every category. That is your first hint of filter context, explained in the next lesson.
DIVIDE instead of the / sign
When the denominator is zero or blank, the / operator throws an error and can break the whole visual. DIVIDE returns BLANK or a fallback value you choose. Use DIVIDE for every ratio or margin.
Margin = [Profit] / [Total Sales] // risky: error if sales = 0
Margin % = DIVIDE([Profit], [Total Sales]) // safe: BLANK if sales = 0Use the second version.
Total Sales = SUM(FactSales[Sales])
Total Cost = SUM(FactSales[Cost])
Profit = [Total Sales] - [Total Cost]
Margin % = DIVIDE([Profit], [Total Sales])Each measure builds on the previous one. Notice that the Electronics margin in 2025 is clearly lower than the other categories: we come back to that in the time-intelligence lesson.
❓ A customer bought 4 times in 2025. How many times is that customer counted by DISTINCTCOUNT(FactSales[CustomerID])?
DISTINCTCOUNT counts different values only, so the customer is counted once however often they bought.
Exercise 1 — Write a measure named Answer that calculates the margin (profit ÷ sales) straight from the columns: (SUM of Sales − SUM of Cost) ÷ SUM of Sales.
Exercise 2 — Write a measure named Answer for the average order value: sales ÷ the number of different orders (OrderID).
Exercise 3 — Write a measure named Answer that counts how many different customers bought. Then see how it changes by category.
Try it in real Power BI Desktop
- A measure = name + = + calculation, referenced as [Name].
- SUM, COUNTROWS and DISTINCTCOUNT are the aggregation basics.
- Always use DIVIDE instead of / for ratios.
- Measures build on each other: Profit from Sales and Cost.
Need a real Power BI dashboard for your business?
I design a data model and an executive dashboard fitted to your business and your real data.