How to Sum If X Or Y in Excel
Learn multiple Excel methods to sum if x or y with step-by-step examples and practical applications.
How to Sum If X Or Y in Excel
Why This Task Matters in Excel
Business data rarely fits neatly into one category. A sales manager might ask, “What is our total revenue for Product A or Product B?” A finance analyst may need to know how much was spent in either the “Travel” or “Training” cost centers. An HR professional could track salaries for employees located in City X or City Y. Each of these questions falls under the umbrella of conditional aggregation with an OR logic—commonly referred to as “Sum If X Or Y.”
Working professionals meet this requirement daily:
- Retail: Summing sales where the store is London or Manchester for regional reporting.
- Manufacturing: Calculating material usage where the part class is Metal or Composite.
- Education: Adding up student scores where the subject is Math or Science for STEM metrics.
Excel is a perfect tool for this task because it combines a powerful calculation engine with flexibility in handling lists that grow or shrink over time. Correctly using “sum if X or Y” enables:
- Faster analysis—no need for repetitive filters and manual totals.
- Reduced error rates compared with copy-pasting subtotals.
- Reusable dashboards that update automatically when new records arrive.
Failing to master this approach often results in bloated workbooks containing multiple helper columns, hidden filter states, or even incorrect results caused by overlooking overlapping criteria. Moreover, “sum if X or Y” acts as a gateway skill to more advanced concepts such as nested logic, dynamic arrays, and data modeling with Power Query. Once you understand it, branching into sum if X and Y or sum if X, Y, or Z becomes intuitive. In short, this technique eliminates busywork, improves data integrity, and sets the stage for scalable reporting workflows.
Best Excel Approach
The most robust way to sum when either of two (or more) conditions is met is to wrap multiple SUMIFS calls inside a single SUM function. Each SUMIFS evaluates one condition, and SUM adds the subtotals together. This keeps formulas readable, leverages the optimized SUMIFS calculation engine, and works across all modern Excel versions.
Syntax skeleton:
=SUM(
SUMIFS(sum_range, criteria_range, condition_X),
SUMIFS(sum_range, criteria_range, condition_Y)
)
Why this is the preferred default:
- Uses familiar
SUMIFSsyntax, so anyone comfortable with “Sum If X and Y” can adapt quickly. - Handles numeric and text criteria, wildcards, and comparison operators equally well.
- Avoids double-counting if X and Y cannot overlap (the most common real-world situation).
- Remains fully compatible with Excel 2010 onward, including Microsoft 365.
When might you choose an alternative?
- If you must guard against double-counting because some records qualify for both X and Y, use the
SUMPRODUCTor dynamic-array solution shown later. - If you regularly tackle many “OR” conditions (five or more), encapsulating all criteria in an array with the Excel 365 formula
SUM(FILTER(...))can be more concise.
Recommended formula example:
=SUM(
SUMIFS([Revenue], [Product], "Product A"),
SUMIFS([Revenue], [Product], "Product B")
)
Alternative without possible overlap issues (Excel 365 dynamic arrays):
=SUM(SUMIFS([Revenue], [Product], {"Product A","Product B"}))
Or classic SUMPRODUCT to eliminate overlap risk in any version:
=SUMPRODUCT(([Product]="Product A")+([Product]="Product B"), [Revenue])
Parameters and Inputs
- sum_range – The numeric range you want to total, e.g., [D2:D101]. Must contain numbers or blanks.
- criteria_range – The range containing X or Y labels, e.g., [B2:B101]. Length must match sum_range.
- condition_X / condition_Y – Literal text such as \"Product A\", numbers such as 2023, or comparison strings like \">100\". Wildcards
*and?are allowed.
Optional adjustments: - Add more conditions by inserting extra
SUMIFScomponents, or by expanding the array constant in dynamic Excel. - Mix numeric and text conditions:
"East"together with">=01-Jul-2023", provided each has its owncriteria_range.
Data preparation guidelines: - Ensure no hidden leading/trailing spaces in text fields; use
TRIMorCLEANif needed. - Convert ranges to Excel Tables for automatic range expansion and readable structured references.
Edge cases: - Blank cells in sum_range are ignored by
SUMIFSbut treated as zero bySUMPRODUCT; plan accordingly. - Duplicate criteria columns (e.g., X and Y overlap) can lead to double-counting unless using
SUMPRODUCTor distinct criteria ranges.
Step-by-Step Examples
Example 1: Basic Scenario
Suppose you keep a simple sales log in [A1:C11]:
| A | B | C |
|---|---|---|
| Date | Product | Qty |
| 04-Jan-23 | Apple | 15 |
| 05-Jan-23 | Banana | 18 |
| 05-Jan-23 | Orange | 12 |
| 06-Jan-23 | Apple | 20 |
| 07-Jan-23 | Pear | 14 |
| 08-Jan-23 | Banana | 10 |
| 09-Jan-23 | Apple | 22 |
| 10-Jan-23 | Orange | 17 |
| 11-Jan-23 | Banana | 19 |
Goal: Total quantity for Apple or Banana.
Step 1 – Confirm your ranges: sum_range is [C2:C11] (Qty). criteria_range is [B2:B11] (Product).
Step 2 – Enter the dual-SUMIFS formula in any empty cell, e.g., E2:
=SUM(
SUMIFS(C2:C11, B2:B11, "Apple"),
SUMIFS(C2:C11, B2:B11, "Banana")
)
Step 3 – Press Enter. Result should be 104 (15 + 20 + 22 + 18 + 10 + 19).
Why it works: SUMIFS calculates a subtotal where Product equals \"Apple\" (57) and another where Product equals \"Banana\" (47). SUM adds them.
Common variations:
- Replace hard-coded criteria with cell references such as $G$1 and $H$1 for dynamic dashboards.
- Use wildcards:
"Ban*"will include both \"Banana\" and any future \"Banana-Organic\" entries.
Troubleshooting tips:
- #VALUE! errors usually indicate mismatched range lengths.
- Unexpected zero means criteria text does not match due to case? No—
SUMIFSis not case-sensitive. More likely extra spaces; wrap list inTRIM.
Example 2: Real-World Application
Scenario: A midsize company tracks travel expenses in a table called tblExpenses with columns Date, CostCenter, Amount. Management requests: “How much did we spend on the Travel or Training cost centers in Quarter 1?”
Data snapshot:
| Date | CostCenter | Amount |
|---|---|---|
| 03-Jan-23 | Travel | 1 250 |
| 04-Jan-23 | Supplies | 400 |
| 10-Feb-23 | Training | 1 100 |
| 15-Feb-23 | Travel | 950 |
| 18-Mar-23 | Training | 720 |
| 29-Mar-23 | IT | 2 300 |
| 04-Apr-23 | Travel | 1 400 |
We also need to restrict to Q1 (Jan–Mar). Introduce a helper SUMIFS date condition while preserving OR logic on CostCenter.
Formula:
=SUM(
SUMIFS(tblExpenses[Amount],
tblExpenses[CostCenter],"Travel",
tblExpenses[Date],">="&DATE(2023,1,1),
tblExpenses[Date],"<="&DATE(2023,3,31)),
SUMIFS(tblExpenses[Amount],
tblExpenses[CostCenter],"Training",
tblExpenses[Date],">="&DATE(2023,1,1),
tblExpenses[Date],"<="&DATE(2023,3,31))
)
Walkthrough:
- Each
SUMIFSsimultaneously filters by date range and one cost center. - Because Travel and Training expenses cannot be in the same row, no overlap exists, so adding results is safe.
- Output equals 5 020 (1 250 + 950 + 1 100 + 720).
Business impact: Finance updates the workbook monthly. Since the formula relies on the table name tblExpenses, it auto-expands when new records arrive, eliminating manual maintenance.
Integration: This total feeds a PivotChart via a linked cell, providing real-time visuals.
Performance: With 50 000+ rows, SUMIFS remains fast because it uses Excel’s multithreaded engine, whereas SUMPRODUCT might become slow.
Example 3: Advanced Technique
Edge case: Overlapping criteria. Imagine a marketing table where each campaign can target multiple regions stored in a pipe-delimited string such as \"East|West\". You need the total budget for any campaign that includes “East” or “West”, avoiding double-counting rows that mention both. This requires evaluating two possibilities on the same text field and ensuring each qualifying campaign contributes its budget exactly once.
Data excerpt:
| CampaignID | Regions | Budget |
|---|---|---|
| C-101 | East | 12 000 |
| C-102 | West | 9 500 |
| C-103 | East | West |
| C-104 | North | 11 200 |
| C-105 | West | South |
Classic dual-SUMIFS approach produces incorrect double-count because row C-103 meets both tests (East, West). Solution: Use a single-pass SUMPRODUCT with OR logic:
=SUMPRODUCT(
(--(ISNUMBER(SEARCH("East", tblCampaigns[Regions])) +
ISNUMBER(SEARCH("West", tblCampaigns[Regions])) > 0)),
tblCampaigns[Budget]
)
Explanation:
SEARCH("East", Regions)returns the position of “East,” or #VALUE! if absent.ISNUMBERconverts that to TRUE (1) or FALSE (0). Same for “West.”- Sum the two 1/0 results. If total greater than 0, the row contains East or West.
- Double unary
--coerces TRUE/FALSE to 1/0. SUMPRODUCTmultiplies the logical array by Budget, summing only qualifying rows exactly once.
Outcome: 12 000 + 9 500 + 18 000 + 14 700 = 54 200, with no double-count.
Performance optimization: Restrict SEARCH to smaller datasets or wrap in IFERROR(,…0) only when necessary, because error trapping inside arrays can degrade speed.
Professional tip: Convert pipe-delimited text to a proper relational model if possible; but when refactoring is impossible, pattern-based SUMPRODUCT offers a reliable stopgap.
Tips and Best Practices
- Turn your data into an Excel Table (Ctrl + T). Formulas automatically adjust and become more readable via structured references.
- Isolate criteria in dedicated cells (e.g., Config sheet). Dynamic formulas referencing those cells are easier to audit and modify.
- Use named ranges like
rngSalesandrngProductto reduce typos and improve clarity, especially with longSUMIFSchains. - For multiple “OR” conditions, consider the dynamic array syntax
SUM(SUMIFS(..., criteria_range, ["A","B","C"]))in Excel 365; it scales with fewer edits. - Document your formulas by adding cell comments or a Notes column, explaining rationale and edge cases—future you (or a colleague) will thank you.
- Keep
SUMPRODUCTas your Swiss-army knife for tricky text matches or overlap elimination, but profile performance on datasets exceeding 100 000 rows.
Common Mistakes to Avoid
- Range length mismatch – If
sum_rangeandcriteria_rangeare not identical in size,SUMIFSreturns zero or unpredictable results. Always verify with F2 and dotted borders. - Hard-coding dates – Typing \"1/1/2023\" can lead to regional date ambiguity. Use
DATE(year,month,day)or cell references. - Forgetting overlap – When rows can satisfy both X and Y, dual-
SUMIFSdouble-counts. Switch toSUMPRODUCTorUNIQUE-based solutions. - Extra spaces in text – “Travel ” (with trailing space) is invisible to the eye but breaks exact matches. Remedy with
TRIMin data load or use wildcard"Travel*"when appropriate. - Wildcards in numeric fields – Wildcards work only on text. If you place account numbers stored as numbers in the criteria_range,
"*123"will fail. Convert numbers to text or use numeric comparisons instead.
Alternative Methods
| Method | Formula Example | Pros | Cons | Best For |
|---|---|---|---|---|
Dual SUMIFS plus SUM | =SUM(SUMIFS(...X),SUMIFS(...Y)) | Simple, fast, works in all modern Excel versions | Potential double-count | Mutually exclusive X and Y |
Dynamic array SUMIFS | =SUM(SUMIFS(sum, crit, ["X","Y"])) | One formula, scalable to many criteria | Requires Microsoft 365 | Users with latest Excel, many OR conditions |
SUMPRODUCT OR logic | =SUMPRODUCT(((crit="X")+(crit="Y"))*sum) | No double-count, flexible comparisons | Slower on big data, complex syntax | Overlaps, text pattern matches |
| PivotTable with filter | Build Pivot, select X and Y | No formulas, user-friendly | Manual refresh or VBA to automate | Ad-hoc analysis, non-formula users |
| Power Query aggregation | Group By with conditional column | Handles millions of rows, repeatable ETL | Extra load step, learning curve | Large datasets, data warehouses |
Choose based on dataset size, overlap risk, version compatibility, and maintenance preferences. You can migrate between methods by encapsulating each in named formulas and switching the definition as requirements evolve.
FAQ
When should I use this approach?
Use the dual-SUMIFS plus SUM method when your X and Y are mutually exclusive or you are certain no record meets both criteria. It is fastest and easiest to audit.
Can this work across multiple sheets?
Yes. You can reference external ranges:
=SUM(
SUMIFS(Sheet2!D:D, Sheet2!B:B, "X"),
SUMIFS(Sheet3!D:D, Sheet3!B:B, "Y")
)
Keep range sizes identical and consider naming them for clarity. If both criteria exist in the same sheet, convert it to a Table and use structured references like Sheet2!tblSales[Amount].
What are the limitations?
SUMIFS allows up to 127 range/criteria pairs, but each additional SUMIFS call counts toward the workbook’s formula complexity. Large arrays can slow recalculation. Also, wildcards do not work on numbers, and case sensitivity is unavailable unless you add helper columns with EXACT.
How do I handle errors?
Wrap your entire expression in IFERROR if blank output is preferred:
=IFERROR(
SUM(SUMIFS(...),SUMIFS(...)),
0
)
For SUMPRODUCT, use N() or IFERROR inside the array to convert errors to zero without disrupting totals.
Does this work in older Excel versions?
Dual-SUMIFS (introduced in Excel 2007) works in all versions from 2007 onward. Dynamic array syntax requires Microsoft 365, while SUMPRODUCT is backward compatible to Excel 2003. If you are stuck on Excel 2003, replace SUMIFS with SUMPRODUCT containing AND conditions.
What about performance with large datasets?
SUMIFS is multithreaded and optimized; it handles hundreds of thousands of rows well. SUMPRODUCT is single-threaded and scans every cell, so limit its use or convert data to an Excel Table and filter first. Alternatively, offload heavy aggregations to Power Pivot or Power Query, which can manage millions of rows more efficiently.
Conclusion
Mastering the “Sum If X Or Y” pattern equips you with a versatile tool to answer everyday business questions quickly and accurately. Whether you choose dual-SUMIFS, dynamic arrays, or SUMPRODUCT, you gain the ability to produce real-time insights while minimizing manual effort. This skill integrates seamlessly with PivotTables, dashboards, and automation workflows, forming a cornerstone of advanced Excel proficiency. Continue experimenting with additional conditions, nested logic, and combined AND + OR scenarios to deepen your analytical toolkit—and watch your productivity soar.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.