๐Ÿ”— https://techtown.in/power-bi/dax/
(Topic: DAX in Power BI โ€“ Measures, Calculated Columns, and Best Practices)


๐Ÿงฎ Mastering DAX in Power BI โ€“ The Brain Behind Your Data

DAX (Data Analysis Expressions) is the formula language of Power BI. Itโ€™s what turns raw data into actionable insights.

Whether you’re calculating revenue, year-over-year growth, or running complex filtering logic โ€” DAX is the engine behind it all.


๐Ÿ“Œ What is DAX?

DAX is a powerful, Excel-like formula language used to create:

  • Measures: For aggregations (like total sales, average profit)
  • Calculated Columns: For row-level calculations (like full name = first + last)
  • Calculated Tables: For creating new tables using DAX expressions
  • Custom Filters: Using functions like FILTER() and CALCULATE()

๐Ÿ” DAX vs Excel Formulas

FeatureDAXExcel
Context AwareYes (Row & Filter Context)No
Works on ModelsYes (tables, relationships)Works only on cells
Optimized for BIYesGeneral-purpose

DAX isnโ€™t just about math โ€” itโ€™s about context.


๐Ÿ› ๏ธ Most Useful DAX Functions (With Examples)

๐Ÿงฎ Aggregation

Total Sales = SUM(Sales[TotalAmount])
Average Profit = AVERAGE(Sales[Profit])

๐Ÿ“… Time Intelligence

Sales YTD = TOTALYTD([Total Sales], 'Date'[Date])
Sales LY = CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))

๐Ÿ” Filtering

High Value Sales = CALCULATE([Total Sales], Sales[Amount] > 50000)

๐Ÿ’ก Logical

Is High Value = IF(Sales[Amount] > 50000, "Yes", "No")

๐Ÿ”„ Context in DAX: The Secret Sauce

DAX calculations depend on two types of context:

Context TypeMeaningExample
Row ContextCurrent row of the tableUsed in Calculated Columns
Filter ContextFiltered view during visuals/measuresUsed in Visuals and Measures

๐Ÿ”‘ CALCULATE() is used to change filter context and is the most important DAX function.


๐Ÿง  Measures vs Calculated Columns

FeatureMeasureCalculated Column
Computed AtVisual levelRow level (once per row)
Stored in Model?No (computed on demand)Yes (increases model size)
UsageKPIs, visual aggregationsGrouping, filtering, keys
PerformanceFaster and lightweightSlower, increases size

โœ” Use Measures whenever possible.


๐Ÿ“˜ Example Use Cases

Use CaseDAX Solution
Year-over-Year SalesCALCULATE([Sales], SAMEPERIODLASTYEAR(...))
Top 5 ProductsUse RANKX with filters
Profit Margin %DIVIDE([Profit], [Revenue])
Sales Target ComparisonIF([Sales] > [Target], "Achieved", "Missed")

โš ๏ธ Common DAX Mistakes

๐Ÿšซ Using SUM() on text columns
๐Ÿšซ Creating too many calculated columns instead of measures
๐Ÿšซ Ignoring context when using CALCULATE()
๐Ÿšซ Not using a proper Date Table for time intelligence
๐Ÿšซ Forgetting to use DIVIDE() (safe division with 0 handling)


๐Ÿ’ก Performance Tips for DAX

โœ… Always prefer measures over calculated columns
โœ… Use VAR to store intermediate results for cleaner logic
โœ… Use FILTER() sparingly โ€” it can slow things down
โœ… Avoid iterators (SUMX, COUNTX) unless needed
โœ… Use relationships instead of LOOKUPVALUE when possible


๐Ÿงช Advanced DAX Patterns

  • Dynamic Titles: "Sales Report for " & SELECTEDVALUE('Region'[RegionName])
  • Custom Ranking: RANKX(ALL('Product'), [Total Sales])
  • Moving Average: AVERAGEX(DATESINPERIOD(...), [Measure])
  • Cumulative Totals with Filters: Use CALCULATE() + FILTER() + ALLSELECTED()

๐Ÿ“Š Summary

DAX is the beating heart of Power BI. With it, you can:

  • Build custom KPIs
  • Apply business logic
  • Analyze trends over time
  • Create smarter, interactive reports

Start with simple functions like SUM(), IF(), and CALCULATE() โ€” and work your way up to advanced logic.

The more you master DAX, the more powerful and dynamic your Power BI dashboards become.