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.

excelformulaspreadsheettutorial
12 min read • Last updated: 7/2/2025

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:

  1. Faster analysis—no need for repetitive filters and manual totals.
  2. Reduced error rates compared with copy-pasting subtotals.
  3. 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 SUMIFS syntax, 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 SUMPRODUCT or 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 SUMIFS components, or by expanding the array constant in dynamic Excel.
  • Mix numeric and text conditions: "East" together with ">=01-Jul-2023", provided each has its own criteria_range.
    Data preparation guidelines:
  • Ensure no hidden leading/trailing spaces in text fields; use TRIM or CLEAN if needed.
  • Convert ranges to Excel Tables for automatic range expansion and readable structured references.
    Edge cases:
  • Blank cells in sum_range are ignored by SUMIFS but treated as zero by SUMPRODUCT; plan accordingly.
  • Duplicate criteria columns (e.g., X and Y overlap) can lead to double-counting unless using SUMPRODUCT or distinct criteria ranges.

Step-by-Step Examples

Example 1: Basic Scenario

Suppose you keep a simple sales log in [A1:C11]:

ABC
DateProductQty
04-Jan-23Apple15
05-Jan-23Banana18
05-Jan-23Orange12
06-Jan-23Apple20
07-Jan-23Pear14
08-Jan-23Banana10
09-Jan-23Apple22
10-Jan-23Orange17
11-Jan-23Banana19

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—SUMIFS is not case-sensitive. More likely extra spaces; wrap list in TRIM.

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:

DateCostCenterAmount
03-Jan-23Travel1 250
04-Jan-23Supplies400
10-Feb-23Training1 100
15-Feb-23Travel950
18-Mar-23Training720
29-Mar-23IT2 300
04-Apr-23Travel1 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:

  1. Each SUMIFS simultaneously filters by date range and one cost center.
  2. Because Travel and Training expenses cannot be in the same row, no overlap exists, so adding results is safe.
  3. 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:

CampaignIDRegionsBudget
C-101East12 000
C-102West9 500
C-103EastWest
C-104North11 200
C-105WestSouth

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. ISNUMBER converts 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.
  • SUMPRODUCT multiplies 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

  1. Turn your data into an Excel Table (Ctrl + T). Formulas automatically adjust and become more readable via structured references.
  2. Isolate criteria in dedicated cells (e.g., Config sheet). Dynamic formulas referencing those cells are easier to audit and modify.
  3. Use named ranges like rngSales and rngProduct to reduce typos and improve clarity, especially with long SUMIFS chains.
  4. For multiple “OR” conditions, consider the dynamic array syntax SUM(SUMIFS(..., criteria_range, ["A","B","C"])) in Excel 365; it scales with fewer edits.
  5. Document your formulas by adding cell comments or a Notes column, explaining rationale and edge cases—future you (or a colleague) will thank you.
  6. Keep SUMPRODUCT as your Swiss-army knife for tricky text matches or overlap elimination, but profile performance on datasets exceeding 100 000 rows.

Common Mistakes to Avoid

  1. Range length mismatch – If sum_range and criteria_range are not identical in size, SUMIFS returns zero or unpredictable results. Always verify with F2 and dotted borders.
  2. Hard-coding dates – Typing \"1/1/2023\" can lead to regional date ambiguity. Use DATE(year,month,day) or cell references.
  3. Forgetting overlap – When rows can satisfy both X and Y, dual-SUMIFS double-counts. Switch to SUMPRODUCT or UNIQUE-based solutions.
  4. Extra spaces in text – “Travel ” (with trailing space) is invisible to the eye but breaks exact matches. Remedy with TRIM in data load or use wildcard "Travel*" when appropriate.
  5. 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

MethodFormula ExampleProsConsBest For
Dual SUMIFS plus SUM=SUM(SUMIFS(...X),SUMIFS(...Y))Simple, fast, works in all modern Excel versionsPotential double-countMutually exclusive X and Y
Dynamic array SUMIFS=SUM(SUMIFS(sum, crit, ["X","Y"]))One formula, scalable to many criteriaRequires Microsoft 365Users with latest Excel, many OR conditions
SUMPRODUCT OR logic=SUMPRODUCT(((crit="X")+(crit="Y"))*sum)No double-count, flexible comparisonsSlower on big data, complex syntaxOverlaps, text pattern matches
PivotTable with filterBuild Pivot, select X and YNo formulas, user-friendlyManual refresh or VBA to automateAd-hoc analysis, non-formula users
Power Query aggregationGroup By with conditional columnHandles millions of rows, repeatable ETLExtra load step, learning curveLarge 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.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.