🚀 Data Analyst Roadmap — Part 25
📊 Power BI Level 4 — DAX Fundamentals: Measures, Calculated Columns & Filter Context
Now that you understand Power Query and Data Modeling, it's time to learn one of the most important parts of Power BI:
DAX — Data Analysis Expressions
DAX is the formula language used in Power BI to create calculations.
🔹 1. What Is DAX?
DAX is used to create:
• Measures
• Calculated columns
• Calculated tables
For example:
Total Sales = SUM(Sales[Sales_Amount])
This simple measure can become the foundation for many Power BI reports.
🔹 2. Measures vs Calculated Columns
This is one of the most common Power BI interview questions.
•
Calculated Column: Calculates a value for each row.
• Example: Profit = Sales[Sales_Amount] - Sales[Cost]
• If there are 1 million rows, the column contains a result for each row.
•
Measure: Calculates a result when it is used in a visual.
• Example: Total Sales = SUM(Sales[Sales_Amount])
• A measure can change depending on the filters and selections in the report.
🔹 3. Simple Example
Suppose your Sales table contains:
• Product: Laptop | Sales: 80,000 | Cost: 60,000
• Product: Mouse | Sales: 2,000 | Cost: 1,000
•
Product: Keyboard | Sales: 4,000 | Cost: 2,500
•
Calculated column: Profit = Sales[Sales] - Sales[Cost]
calculates profit for every row.
•
Measure: Total Profit = SUM(Sales[Sales]) - SUM(Sales[Cost])
calculates the total based on the current filter context.
🔹 4. Basic Aggregation Functions
Some DAX functions you'll use constantly are:
• SUM(), AVERAGE(), MIN(), MAX(), COUNT(), COUNTROWS(), DISTINCTCOUNT()
Examples:
• Total Sales = SUM(Sales[Sales])
• Average Sales = AVERAGE(Sales[Sales])
• Total Orders = COUNTROWS(Sales)
• Total Customers = DISTINCTCOUNT(Sales[Customer_ID])
🔹 5. Why DISTINCTCOUNT() Matters
Suppose the same customer placed 10 orders.
COUNT() could count all transaction rows. But DISTINCTCOUNT(Sales[Customer_ID]) counts the customer only once.
So if you want "How many unique customers do we have?"
DISTINCTCOUNT() is often the right choice.
🔹 6. Creating Your First Measure
In Power BI: Modeling → New Measure
Then write:
Total Sales = SUM(Sales[Sales_Amount])
You can then drag Total Sales into a Card visual. Result might show:
TOTAL SALES ₹12.5 Cr
🔹 7. Measures Respond to Filters
This is where DAX becomes powerful.
Suppose your report contains Total Sales = ₹10 Crore. Now select Region = West. The same measure Total Sales = SUM(Sales[Sales_Amount]) may now show ₹3 Crore.
You didn't create another measure. The filter changed the calculation. This is called Filter Context.
🔹 8. What Is Filter Context?
Filter context means: The filters currently affecting a DAX calculation.
Filters can come from:
• Slicers, Visuals, Rows and columns, Page filters, Report filters, Relationships, DAX expressions
For example: Region = West, Year = 2026, Category = Electronics. The Total Sales measure calculates only within that context.
🔹 9. A Simple Way to Understand Filter Context
Think of it like this:
• Total Sales → Which rows are currently visible? → Apply filters → Calculate SUM
This concept is extremely important.
Post #3125
1.94K
- ❤ 4