Google Sheets Formula Category Tricks
In this article
Google Sheets doesn't have a single "category" formula, but you can categorise data with a handful of reliable functions: IF, IFS, SWITCH, VLOOKUP, XLOOKUP, or a combination of TEXT and FIND. The trick is to pick the one that matches how many categories you have and whether your rules are simple or need pattern matching. This guide shows you exactly how to set each one up, plus the mistakes that make them fail.
What You'll Need
- A Google account and access to Google Sheets (desktop browser recommended for formula entry; the mobile app works but is fiddlier).
- A spreadsheet with a column of values you want to categorise (e.g., amounts, product names, dates, or text labels).
- A clear list of your category rules written down first — for example, "under 50 = Low, 50–100 = Medium, over 100 = High."
Step-by-Step
- Set up your data. Put your raw values in one column (say A2:A100) and leave the next column (B) for the category formula. Add a header row so you can label the new column "Category."
- Choose your formula type. Use IF for two categories, IFS for three to five simple conditions, SWITCH for exact-match categories (like product codes), and VLOOKUP or XLOOKUP when you have a separate reference table. TEXT and FIND help when the category is hidden inside a longer string.
- Write a basic IF formula. In B2, type
=IF(A2<50,"Low",IF(A2<=100,"Medium","High")). This nests two IFs to create three bands. Press Enter and drag the fill handle down. The order matters: Sheets stops at the first TRUE, so always test the smallest or most specific condition first. - Use IFS for cleaner multi-condition logic. In B2, type
=IFS(A2<50,"Low",A2<=100,"Medium",A2>100,"High"). IFS reads left to right and returns the first matching pair. It is easier to edit than nested IFs and avoids deep bracket counting. - Use SWITCH for exact matches. If your categories come from fixed codes, type
=SWITCH(A2,"A1","Electronics","B2","Clothing","C3","Food","Other"). SWITCH compares the value to each case and returns the matching result; the final value is the fallback. - Use VLOOKUP with a reference table. Create a small table elsewhere (say columns E and F) listing each threshold or code and its category. Then in B2 type
=VLOOKUP(A2,$E$2:$F$10,2,TRUE)for approximate numeric bands (the table must be sorted ascending) orFALSEfor exact matches. Lock the range with dollar signs so it doesn't shift when you copy down. - Use XLOOKUP if your version supports it. XLOOKUP is available in Google Sheets and handles exact or approximate matches without sorting. In B2 type
=XLOOKUP(A2,$E$2:$E$10,$F$2:$F$10,"Not found",0)for exact matches, or change the last argument to1or-1for approximate matches. Check that your sheet actually offers XLOOKUP before relying on it — older shared sheets may not. - Categorise text with FIND or SEARCH. If a cell contains "Invoice-2024-ACME," you can extract the client with
=IF(ISNUMBER(FIND("ACME",A2)),"ACME","Other"). FIND is case-sensitive; SEARCH is not. Wrap it in IFERROR to avoid #VALUE! errors when the text is missing. - Convert numbers to categories with TEXT. For date-based categories,
=TEXT(A2,"mmmm")returns the month name, or=TEXT(A2,"yyyy")returns the year. This is useful when you want to group transactions by month without a lookup table. - Copy the formula down and check a sample. Drag the fill handle or double-click it to fill the column. Spot-check the first, middle, and last rows against your rules. If a row returns an unexpected category, trace which condition fired first.
- Lock the formula ranges if you plan to sort. Use absolute references ($A$2:$A$100) for lookup tables and relative references for the row being evaluated. Mixing them up is the most common cause of wrong categories after sorting.
Common Mistakes
- Wrong condition order. In nested IFs, putting the broadest condition first (e.g., A2>0 before A2>100) makes every value fall into the first bucket. Always test the narrowest range first.
- Forgetting the fallback. IF and IFS return #N/A or an error when no condition matches. Add a final "Other" or "Uncategorised" value so blanks and outliers don't break the column.
- Unsorted VLOOKUP tables. Approximate VLOOKUP (TRUE) requires the first column sorted ascending. If it isn't, you get wrong or missing categories with no error message.
- Relative references in lookup ranges. Copying a formula down without $ signs shifts the lookup table row by row, so later rows look at the wrong reference cells.
- Mixing text and numbers. A value stored as text (often imported from CSV) won't match a numeric threshold. Use VALUE() to convert, or check with ISNUMBER.
- Case sensitivity surprises. FIND and exact-match comparisons are case-sensitive; SEARCH and most lookups are not. Pick deliberately.
Tips
- Keep your category rules in a separate reference table rather than hard-coding them inside formulas. When a threshold changes, you edit one cell instead of every row.
- Use named ranges (Data > Named ranges) for lookup tables so formulas read like
=VLOOKUP(A2,CategoryTable,2,FALSE). - Wrap fragile formulas in IFERROR to show a clean label instead of an error code:
=IFERROR(VLOOKUP(...),"Uncategorised"). - Add a helper column that flags rows where the category is "Other" so you can review edge cases quickly.
- For large sheets, prefer XLOOKUP or a reference table over deeply nested IFs — they are faster to edit and less error-prone.
Troubleshooting
If every row returns the same category, check the condition order and whether you used absolute references where needed. If you see #N/A, your lookup value isn't in the reference table — check for trailing spaces with TRIM or mismatched data types. If you see #VALUE!, a text value is being compared to a number; convert it with VALUE or change the comparison to text. If categories are correct at the top but wrong further down, your lookup range shifted — add dollar signs. If the formula works in one sheet but not another, confirm XLOOKUP or IFS is supported there; older shared files may lack newer functions. Finally, if sorting the sheet scrambles categories, your formulas are using relative references to the lookup table — lock them and re-copy.
Frequently Asked Questions
Can I categorise text values, not just numbers?
Yes. Use SWITCH for exact text matches, or IF with FIND/SEARCH for partial matches inside a longer string.
What's the difference between IFS and nested IF?
They do the same job. IFS is flatter and easier to read; nested IF works in every version of Sheets and is sometimes required in older shared files.
Why does my VLOOKUP return the wrong category?
Most often the reference table isn't sorted ascending when using approximate match (TRUE), or the range isn't locked with dollar signs.
Can I use XLOOKUP in Google Sheets?
XLOOKUP is available in Google Sheets, but support can vary in older shared files. If it returns an error, fall back to VLOOKUP or INDEX/MATCH.
How do I handle blank cells in a category formula?
Add a first condition like =IF(A2="","", ...) so blank rows stay blank instead of being categorised.