DAX Formulas I Can’t Live Without in Power BI (Data Analyst Edition)

As a data analyst working with Power BI, I quickly realized that DAX (Data Analysis Expressions) is the secret sauce behind powerful calculations. While the UI lets you drag and drop visuals, mastering DAX unlocks next-level insights.
In this post, I’ll share the most essential DAX formulas I use daily—from basic aggregations to advanced time intelligence—with real-world examples.
1. CALCULATE()
– The Swiss Army Knife of DAX
When to use: Modifying filter context dynamically (e.g., filtering a measure on the fly).
- Example: Calculate total sales only for the ‘Technology' category:daxCopyTech_Sales = CALCULATE(SUM(Sales[Amount]), Sales[Category] = “Technology”)
- Why it’s a game-changer: It’s the backbone of 90% of advanced DAX.
2. FILTER()
– Supercharged Row-by-Row Logic
When to use: When you need fine-grained control over filtering.
- Example: Find customers who spent more than $1,000:daxCopyHigh_Value_Customers = CALCULATE( COUNTROWS(Customers), FILTER(Sales, Sales[Amount] > 1000) )
- Pro Tip: Often paired with
CALCULATE()
for dynamic measures.
3. SUMX()
/ AVERAGEX()
– Row-by-Row Aggregations
When to use: When you need to iterate over rows before aggregating.
- Example: Calculate profit margin per product (where each row has a unique margin):daxCopyTotal_Profit_Margin = SUMX(Products, Products[Revenue] * Products[Margin])
- Why not just
SUM()
? BecauseSUMX()
lets you apply logic before summing.
4. RELATED()
& RELATEDTABLE()
– Bridging Table Relationships
When to use: Pulling data from related tables (like SQL joins).
- Example: Fetch a product’s category name in a sales table:daxCopySales_With_Category = RELATED(Products[Category])
- Watch out: Requires a proper data model relationship.
5. DATEDIFF()
& DATEADD()
– Time Intelligence Basics
When to use: Calculating durations, growth over time, or rolling periods.
- Example: YoY (Year-over-Year) Sales Growth:daxCopyYoY_Growth = VAR CurrentYearSales = SUM(Sales[Amount]) VAR PriorYearSales = CALCULATE(SUM(Sales[Amount]), DATEADD(Sales[Date], -1, YEAR)) RETURN (CurrentYearSales – PriorYearSales) / PriorYearSales
- Pro Move: Combine with
SAMEPERIODLASTYEAR()
.
6. RANKX()
– Ranking Metrics Dynamically
When to use: Leaderboards, top N analysis, or percentile rankings.
- Example: Rank salespeople by revenue:daxCopySales_Rank = RANKX(ALL(Sales[Salesperson]), [Total_Sales], , DESC)
- Gotcha: Use
ALL()
to remove filters if needed.
7. SWITCH()
– Cleaner Than Nested IFs
When to use: Categorizing data or conditional logic.
- Example: Assign a tier based on sales amount:daxCopyCustomer_Tier = SWITCH( TRUE(), [Total_Sales] > 5000, “Gold”, [Total_Sales] > 1000, “Silver”, “Bronze” )
- Why it’s better: More readable than
IF(IF(IF()))
.
8. COALESCE()
– Handling Blanks Gracefully
When to use: Replacing BLANK()
with a default value.
- Example: Display “N/A” instead of blanks:daxCopyClean_Profit = COALESCE([Profit], “N/A”)
- Alternative:
IF(ISBLANK([Profit]), "N/A", [Profit])
(butCOALESCE
is cleaner).
9. TREATAS()
– Applying Virtual Relationships
When to use: Filtering across disconnected tables.
- Example: Apply a slicer from an unrelated table:daxCopyFiltered_Sales = CALCULATE(SUM(Sales[Amount]), TREATAS(VALUES(UnrelatedTable[Category]), Sales[Category]))
- Power BI Pro Tip: Great for dynamic segmentation.
10. SELECTEDVALUE()
– Simplifying Slicer Logic
When to use: Capturing slicer selections in measures.
- Example: Show sales for the selected region only:daxCopySelected_Region_Sales = IF( HASONEVALUE(Regions[Region]), CALCULATE(SUM(Sales[Amount]), Sales[Region] = SELECTEDVALUE(Regions[Region])), SUM(Sales[Amount]) )
- Why it’s clutch: Makes reports interactive without complex DAX.
Final Thoughts
DAX is Power BI’s superpower—but it takes practice. Start with CALCULATE()
, SUMX()
, and time intelligence, then level up to advanced patterns.
What’s your most-used DAX function? Let me know in the comments!