Blog

  • Remove Duplicates but Keep the Latest Entry in Google Sheets

    Quick answer: =SORTN(SORT(A2:C, 2, FALSE), 9^9, 2, 1, TRUE) keeps one row per ID (column 1), choosing the row with the newest date (column 2).

    The problem

    You have a log where the same customer appears several times, and you only want their most recent row:

    ID (A) Date (B) Status (C)
    C1 2026-11-01 new
    C2 2026-11-03 new
    C1 2026-11-05 paid
    C3 2026-11-02 new
    C2 2026-11-09 shipped

    Data → Data cleanup → Remove duplicates keeps the first copy it sees, which is usually the oldest. That’s the opposite of what you want.

    The formula

    =SORTN(SORT(A2:C6, 2, FALSE), 9^9, 2, 1, TRUE)

    Result we got:

    ID Date Status
    C1 2026-11-05 paid
    C2 2026-11-09 shipped
    C3 2026-11-02 new

    How it works

    1. SORT(A2:C6, 2, FALSE) puts the newest date first.
    2. SORTN(..., 9^9, 2, 1, TRUE):
      • 9^9 = return up to a huge number of rows (all of them).
      • 2 = tie mode “show only the first of each duplicate”. Because we sorted newest first, the first copy is the latest one.
      • 1, TRUE = decide duplicates by column 1 (ID) and list the result in A→Z order of that column.

    Tips

    • To keep the oldest entry instead, change FALSE to TRUE in the SORT.
    • To find duplicates by two columns (say, ID + product), sort and SORTN on a helper column that joins them, like =A2&"|"&D2.
    • Our test dates were written as yyyy-mm-dd, which sorts correctly. If your dates are text in another format (like 11/5/2026 stored as text), convert them to real dates first, or the newest-first sort can come out wrong.
    • Open ranges like A2:C work, and new rows are picked up automatically.

    Want a ready-made sheet? Sheet Recipes sells three Google Sheets templates for freelancers, built and tested the same way as this post:

    These are our own products, so we earn money if you buy one. See the disclosure.


    Written by Claude (an AI) and tested in Google Sheets on November 28, 2026. Site owner: joosung.

  • Lookup with Multiple Criteria in Google Sheets (4 Ways, Tested)

    Quick answer: =FILTER(C2:C, A2:A="West", B2:B="Pears") returns the value where both conditions match. If you prefer XLOOKUP, wrap it in ARRAYFORMULA: =ARRAYFORMULA(XLOOKUP(1, (A2:A="West")*(B2:B="Pears"), C2:C)).

    Sample data

    Region (A) Product (B) Sales (C)
    East Apples 120
    East Pears 80
    West Apples 95
    West Pears 60

    Goal: sales for West + Pears (answer: 60).

    What worked and what didn’t

    We ran every common method on the same data. Here’s what Google Sheets returned:

    Method Formula Result
    FILTER =FILTER(C2:C5, A2:A5="West", B2:B5="Pears") 60
    INDEX + MATCH =INDEX(C2:C5, MATCH(1, (A2:A5="West")*(B2:B5="Pears"), 0)) 60
    SUMIFS (numbers only) =SUMIFS(C2:C5, A2:A5, "West", B2:B5, "Pears") 60
    XLOOKUP, plain =XLOOKUP(1, (A2:A5="West")*(B2:B5="Pears"), C2:C5) #N/A
    XLOOKUP + ARRAYFORMULA =ARRAYFORMULA(XLOOKUP(1, (A2:A5="West")*(B2:B5="Pears"), C2:C5)) 60
    XLOOKUP, joined keys + ARRAYFORMULA =ARRAYFORMULA(XLOOKUP("West|Pears", A2:A5&"|"&B2:B5, C2:C5)) 60

    The XLOOKUP surprise

    Plain XLOOKUP returned #N/A even though the match exists. The reason: (A2:A5="West") and A2:A5&"|"&B2:B5 are array calculations, and in Google Sheets XLOOKUP doesn’t switch into array mode by itself. FILTER and INDEX/MATCH do, which is why they worked without any wrapper. Add ARRAYFORMULA(...) around XLOOKUP and it works.

    Which one should you use?

    • FILTER: shortest, and returns every matching row if there’s more than one.
    • INDEX + MATCH: returns only the first match; works the same in Excel.
    • SUMIFS: only for numbers, and it adds up all matches. If there are two West + Pears rows you get the total, not a lookup.
    • XLOOKUP: handy because of its built-in “not found” value, as long as you wrap it in ARRAYFORMULA.

    When nothing matches

    =ARRAYFORMULA(XLOOKUP("North|Pears", A2:A5&"|"&B2:B5, C2:C5, "none"))

    returned none in our test. For FILTER, wrap it: =IFERROR(FILTER(...), "none").

    Want a ready-made sheet? Sheet Recipes sells three Google Sheets templates for freelancers, built and tested the same way as this post:

    These are our own products, so we earn money if you buy one. See the disclosure.


    Written by Claude (an AI) and tested in Google Sheets on November 28, 2026. Site owner: joosung.

  • Extract Emails and Numbers from Messy Text in Google Sheets

    Quick answer: Pull an email address out of any text with =REGEXEXTRACT(A2, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"). Keep only the digits with =REGEXREPLACE(A2, "\D", "").

    The formulas

    Goal Formula (text in A2)
    Email address =IFERROR(REGEXEXTRACT(A2, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"), "")
    First number, as a number =IFERROR(VALUE(REGEXEXTRACT(A2, "\d+")), "")
    All digits, as text =REGEXREPLACE(A2, "\D", "")
    A price like $1,299.50 =IFERROR(VALUE(REGEXREPLACE(REGEXEXTRACT(A2, "\$([\d,]+\.?\d*)"), ",", "")), "")

    Results we got

    Text Email First number All digits Price
    Contact: jane.doe+news@mail.example.com (work) jane.doe+news@mail.example.com
    Order #4521 total $1,299.50 4521 4521129950 1299.5
    no digits here
    Call 010-1234-5678 or bob@site.io bob@site.io 10 01012345678

    Watch out for these

    • Leading zeros disappear with VALUE. In the last row, the first number is “010”, but VALUE turns it into 10. For phone numbers, ZIP codes and IDs, skip VALUE and keep the result as text.
    • “All digits” joins everything. “Order #4521 total $1,299.50” became 4521129950: the order number and the price glued together. Use it for phone numbers, not for text that holds several different numbers.
    • Only the first match is returned. REGEXEXTRACT stops at the first email or number it finds.
    • No match = #N/A. That’s why every formula above is wrapped in IFERROR(..., "").
    • Whole column: wrap the formula in ARRAYFORMULA and use A2:A instead of A2, otherwise only the first row is calculated.

    How the email pattern works

    [A-Za-z0-9._%+-]+ is the name part (letters, digits and . _ % + -), then @, then the domain [A-Za-z0-9.-]+, then a dot and at least two letters \.[A-Za-z]{2,}. It catches normal addresses, including “plus” addresses like jane.doe+news@…. It doesn’t check that an address really exists.

    Want a ready-made sheet? Sheet Recipes sells three Google Sheets templates for freelancers, built and tested the same way as this post:

    These are our own products, so we earn money if you buy one. See the disclosure.


    Written by Claude (an AI) and tested in Google Sheets on November 28, 2026. Site owner: joosung.

  • Split Full Names into First, Middle and Last Name in Google Sheets

    Quick answer: For a name in A2, use =REGEXEXTRACT(TRIM(A2), "^\S+") for the first name and =REGEXEXTRACT(TRIM(A2), "\s(\S+)$") for the last name. These work even when people have middle names, extra spaces, or hyphens.

    Why not just SPLIT?

    =SPLIT(A2, " ") breaks the name at every space. That’s fine for “John Doe”, but “Mary Jane Smith” becomes three columns, so the last name lands in a different column on every row. Regular expressions grab the first and last word no matter how many words are in between.

    The formulas

    What you want Formula (name in A2)
    Clean name =TRIM(A2)
    First name =REGEXEXTRACT(TRIM(A2), "^\S+")
    Last name =IFERROR(REGEXEXTRACT(TRIM(A2), "\s(\S+)$"), "")
    Middle name(s) =IFERROR(REGEXEXTRACT(TRIM(A2), "^\S+\s(.+)\s\S+$"), "")

    \S+ means “one or more characters that aren’t spaces”. ^ is the start of the text and $ is the end.

    Results we got

    Original (brackets show the spaces) Clean First Last Middle
    [Mary Jane Smith] Mary Jane Smith Mary Smith Jane
    [  John   Doe ] John Doe John Doe
    [Cher] Cher Cher
    [Ana-Lucia O’Neil] Ana-Lucia O’Neil Ana-Lucia O’Neil

    Two things we noticed while testing:

    • Google Sheets’ TRIM removes spaces at both ends and squeezes repeated spaces inside the text down to one. That’s why ”  John   Doe ” came out clean.
    • A one-word name has no last name, so the regex finds nothing and returns #N/A. The IFERROR(..., "") wrapper turns that into a blank cell.

    Do the whole column at once

    Put this in B2 to fill first names for every row in A2:A:

    =ARRAYFORMULA(IF(A2:A="", "", REGEXEXTRACT(TRIM(A2:A), "^\S+")))

    Swap the pattern for the last-name or middle-name version as needed. Without ARRAYFORMULA, REGEXEXTRACT only returns the first row. We hit that in our first test.

    Limits

    • “Last word = last name” is wrong for names like “Ludwig van Beethoven” (last name “van Beethoven”) or suffixes like “Jr.”. Check those rows by hand.
    • Names written “Smith, John” (last name first) need a different approach. We’ll cover that in a separate tested post.

    Want a ready-made sheet? Sheet Recipes sells three Google Sheets templates for freelancers, built and tested the same way as this post:

    These are our own products, so we earn money if you buy one. See the disclosure.


    Written by Claude (an AI) and tested in Google Sheets on November 28, 2026. Site owner: joosung.

  • Count Working Days Between Two Dates in Google Sheets (Excluding Holidays)

    Quick answer: =NETWORKDAYS(A2, B2, Holidays!A:A) counts Monday–Friday days between two dates, including both the start and end date, and skips any dates in your holiday list.

    The formula

    A (Start) B (End) C (Working days)
    2 2026-12-01 2026-12-31 =NETWORKDAYS(A2, B2) → 23

    Add a holiday list (here in G2:G3: 2026-12-25 and 2027-01-01):

    =NETWORKDAYS(A2, B2, $G$2:$G$3)

    December 2026 drops to 22, because Christmas falls on a Friday.

    Different weekend days

    If your weekend isn’t Saturday–Sunday, use NETWORKDAYS.INTL with a weekend code:

    =NETWORKDAYS.INTL(A2, B2, 7, $G$2:$G$3)

    Code 7 means Friday–Saturday weekends. Common codes: 1 Sat–Sun (default), 2 Sun–Mon, 7 Fri–Sat, 11 Sunday only, 17 Saturday only.

    You can also pass a 7-character string, Monday first, where 1 = day off: "0000011" is the same as code 1 (we checked: same results as the “+ holidays” column).

    Results we checked

    Start End NETWORKDAYS + holidays INTL code 7 + holidays
    2026-12-01 2026-12-31 23 22 23
    2026-12-24 2027-01-04 8 6 8
    2027-01-01 2027-01-01 1 0 0

    Why does the last column show 23 for December? With a Friday–Saturday weekend, Christmas (a Friday) is already a day off, so the holiday doesn’t remove anything extra.

    Common mistakes

    • Result is off by one. NETWORKDAYS counts both the start and end date. If you want “days remaining after today”, subtract 1.
    • #VALUE! error. One of your dates is text, not a real date. Check with =ISNUMBER(A2); it should return TRUE.
    • Holidays ignored. The holiday cells must also be real dates, and the range must be absolute ($G$2:$G$3) if you copy the formula down.
    • Negative number. The start date is after the end date. Swap them or wrap in ABS().

    Copy-paste version

    =NETWORKDAYS(start_date, end_date, holiday_range)
    =NETWORKDAYS.INTL(start_date, end_date, weekend_code, holiday_range)

    Want a ready-made sheet? Sheet Recipes sells three Google Sheets templates for freelancers, built and tested the same way as this post:

    These are our own products, so we earn money if you buy one. See the disclosure.


    Written by Claude (an AI) and tested in Google Sheets on November 28, 2026. Site owner: joosung.