1️⃣ What Is Conditional Aggregation?
Let’s break it into two simple parts:
🔹 Aggregation
Aggregation means summarizing numbers into one result.
Examples:
🔹 Conditional
Conditional means only include values that meet a condition.
So:
Conditional Aggregation = Summarizing data based on a condition.
Example:
2️⃣ Why Use IF for Conditional Aggregation?
The IF() function allows Excel to:
When combined with aggregation functions like:
SUM()AVERAGE()COUNT()It becomes powerful.
3️⃣ Basic Dataset Example
Assume this data:
| Employee | Sales | Region | |----------|-------|--------| | John | 5000 | East | | Mary | 7000 | West | | David | 3000 | East | | Anna | 9000 | West | | James | 4000 | East |
4️⃣ Example 1: Conditional SUM Using IF
Goal:
Find total sales only for East region
🔹 Step 1: Basic IF Logic
The IF formula structure:
=IF(condition, value_if_true, value_if_false)
🔹 Step 2: Use IF Inside SUM
=SUM(IF(C2:C6="East",B2:B6,0))
Explanation:
🔹 Result
East Sales:
5000 + 3000 + 4000 = 12000
| Condition | Result | |------------------|--------| | Total East Sales | 12000 |
⚠️ Important Note (Older Excel Versions)
In older Excel versions, you must press:
CTRL + SHIFT + ENTER
To make it an array formula.
In modern Excel, just press Enter.
5️⃣ Example 2: Conditional AVERAGE Using IF
Goal:
Average sales only for West region.
Formula:
=AVERAGE(IF(C2:C6="West",B2:B6))
Manual Calculation:
West Sales:
7000 + 9000 = 16000
16000 ÷ 2 = 8000
| Condition | Result | |---------------------|--------| | Average West Sales | 8000 |
6️⃣ Example 3: Conditional COUNT Using IF Goal:
Count employees with sales greater than 5000.
Formula:
=SUM(IF(B2:B6>5000,1,0))
Explanation:
Employees:
Mary (7000)
Anna (9000)
Total = 2
| Condition | Result | |-------------------------------|--------| | Employees with Sales > 5000 | 2 |
7️⃣ Multiple Conditions Using IF
Goal:
Total East region sales where Sales > 4000.
Formula:
=SUM(IF((C2:C6="East")*(B2:B6>4000),B2:B6,0))
Explanation:
Only:
John (5000)
Result = 5000
| Condition | Result | |-----------------------------------------|--------| | East Sales Above 4000 | 5000 |
8️⃣ Real Business Example
Imagine this dataset:
| Product | Category | Revenue | |---------|----------|---------| | A | Food | 1000 | | B | Drink | 2000 | | C | Food | 1500 | | D | Drink | 3000 | | E | Food | 2500 |
Goal:
Total revenue from Food category.
Formula:
=SUM(IF(B2:B6="Food",C2:C6,0))
Food revenue:
1000 + 1500 + 2500 = 5000
| Category | Total Revenue | |----------|---------------| | Food | 5000 |
9️⃣ Why Not Just Use SUMIF?
Excel has built-in functions like:
=SUMIF() =AVERAGEIF() =COUNTIF()
But learning conditional aggregation with IF helps you:
🔟 Key Concept Summary
| Concept | Meaning | |---------------------|--------------------------------| | IF | Tests a condition | | SUM + IF | Adds only matching values | | AVERAGE + IF | Averages only matching values | | SUM(IF(...,1,0)) | Counts matching records | | Multiple conditions | Use multiplication (*) for AND |