β Power BI DAX Basics ππ§
DAX (Data Analysis Expressions) is the formula language in Power BI. It's used to create custom calculations, measures, and calculated columns.
1οΈβ£ SUM()
Adds up values from a column
Example:
Total Sales = SUM(Sales[Amount])
2οΈβ£ AVERAGE()
Calculates the average of a column
Example:
Avg Salary = AVERAGE(Employee[Salary])
3οΈβ£ COUNT(), COUNTA(), COUNTROWS()
-
COUNT()β counts numeric values -
COUNTA()β counts non-blank values -
COUNTROWS()β counts rows in a table Examples:Total Orders = COUNT(Orders[OrderID])Total Customers = COUNTROWS(Customers)
4οΈβ£ CALCULATE()
Modifies the context of a calculation
Example:
Sales East = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "East")
5οΈβ£ FILTER()
Creates a filtered table for use inside CALCULATE
Example:
High Sales = CALCULATE(SUM(Sales[Amount]), FILTER(Sales, Sales[Amount] > 1000))
6οΈβ£ IF()
Adds logic to DAX
Example:
Sales Category = IF(Sales[Amount] > 500, "High", "Low")
7οΈβ£ SWITCH()
Simpler alternative to nested IFs
Example:
Rating = SWITCH(TRUE(),
[Score] >= 90, "A",
[Score] >= 75, "B",
[Score] >= 60, "C",
"Fail"
)
8οΈβ£ ALL()
Removes filters from a column or table
Example:
% of Total = DIVIDE(SUM(Sales[Amount]), CALCULATE(SUM(Sales[Amount]), ALL(Sales)))
9οΈβ£ DISTINCT()
Returns unique values in a column
Example:
Unique Products = DISTINCT(Sales[Product])
π Measures vs Calculated Columns
- Measure: Calculated based on report context (preferred for visuals)
- Calculated Column: Stored in the data model, row-by-row logic
π¬
Top comments (0)