Excel formulas cheat sheet

The 37 formulas business people use most, what each one does, and the SQL that does the same job, for the day your data outgrows the spreadsheet.

Excel formulas cheat sheet: SUM, COUNTIF, SUMIFS, IF, IFS, VLOOKUP, XLOOKUP, INDEX MATCH, LEFT, TEXT, DATEDIF, UNIQUE, FILTER and more, with what each does and the SQL equivalent
Save or print the whole cheat sheet. Download · Save to Pinterest

Totals

Excel formulaWhat it doesIn SQL
=SUM(D2:D100)Adds up numbersSUM(quantity)
=AVERAGE(D2:D100)Average of numbersAVG(quantity)
=COUNT(D2:D100)Counts cells with numbersCOUNT(quantity)
=COUNTA(A2:A100)Counts cells that are not emptyCOUNT(col) -- or COUNT(*) for every row
=MIN(D2:D100) / =MAX(D2:D100)Smallest / largest valueMIN(quantity) / MAX(quantity)
=ROUND(A2, 2)Rounds to 2 decimalsROUND(price, 2)
=SUMPRODUCT(C2:C100, D2:D100)Multiplies pairs, then adds themSUM(price * quantity)

Conditional totals

Excel formulaWhat it doesIn SQL
=COUNTIF(B:B, "Europe")Counts rows that matchCOUNT(*) ... WHERE region = 'Europe'
=COUNTIFS(B:B, "Europe", D:D, ">5")Counts rows matching several rulesWHERE region = 'Europe' AND quantity > 5
=SUMIF(B:B, "Europe", D:D)Adds up rows that matchSUM(quantity) ... WHERE region = 'Europe'
=SUMIFS(D:D, B:B, "Europe", C:C, ">5")Adds up rows matching several rulesSUM(quantity) ... WHERE region = 'Europe' AND price > 5
=AVERAGEIF(B:B, "Europe", D:D)Average of rows that matchAVG(quantity) ... WHERE region = 'Europe'

Logic

Excel formulaWhat it doesIn SQL
=IF(D2>=5, "bulk", "single")One test, two outcomesCASE WHEN quantity >= 5 THEN 'bulk' ELSE 'single' END
=IFS(A2>90, "A", A2>80, "B", TRUE, "C")Several tests in orderCASE WHEN score > 90 THEN 'A' WHEN score > 80 THEN 'B' ELSE 'C' END
=AND(A2>5, B2<3) / =OR(...)Combine testsa > 5 AND b < 3 / a > 5 OR b < 3
=IFERROR(A2/B2, 0)Fallback when a formula errorsCOALESCE(a / NULLIF(b, 0), 0)

Lookups

Excel formulaWhat it doesIn SQL
=VLOOKUP(A2, Products!A:C, 3, FALSE)Find a value in another sheetJOIN products p ON p.id = o.product_id
=XLOOKUP(A2, Products!A:A, Products!C:C)Modern VLOOKUP, any directionLEFT JOIN products p ON p.id = o.product_id
=INDEX(C:C, MATCH(A2, A:A, 0))The classic VLOOKUP alternativeJOIN ... ON ... (same idea)

Text

Excel formulaWhat it doesIn SQL
=LEFT(A2, 3) / =RIGHT(A2, 3)First / last charactersSUBSTRING(name, 1, 3) / SUBSTRING(name, -3)
=MID(A2, 2, 5)Characters from the middleSUBSTRING(name, 2, 5)
=LEN(A2)Number of charactersLENGTH(name)
=TRIM(A2)Removes extra spacesTRIM(name)
=UPPER(A2) / =LOWER(A2)Change caseUPPER(name) / LOWER(name)
=A2 & " " & B2 / =CONCAT(A2, B2)Join textfirst || ' ' || last / CONCAT(first, last)
=TEXTJOIN(", ", TRUE, A2:A10)Join a list with a separatorGROUP_CONCAT(name, ', ') -- STRING_AGG in Postgres
=SUBSTITUTE(A2, "old", "new")Replace textREPLACE(name, 'old', 'new')

Dates

Excel formulaWhat it doesIn SQL
=TODAY()Today's dateDATE('now') -- CURRENT_DATE elsewhere
=TEXT(A2, "yyyy-mm")Date as year-monthstrftime('%Y-%m', order_date)
=DATEDIF(A2, B2, "d")Days between two datesjulianday(b) - julianday(a) -- DATEDIFF elsewhere
=EDATE(A2, 1)Same date, one month laterDATE(d, '+1 month') -- DATEADD elsewhere
=EOMONTH(A2, 0)Last day of the monthDATE(d, 'start of month', '+1 month', '-1 day')

Lists

Excel formulaWhat it doesIn SQL
=UNIQUE(A2:A100)Each value onceSELECT DISTINCT region
=FILTER(A2:D100, B2:B100="Europe")Only matching rowsWHERE region = 'Europe'
=SORT(A2:D100, 4, -1)Sort by a column, largest firstORDER BY quantity DESC
=RANK.EQ(D2, D:D)Rank a value in a listRANK() OVER (ORDER BY quantity DESC)
PivotTableTotals per categoryGROUP BY region

Want the reverse, starting from SQL? See the Excel to SQL cheat sheet, or start lesson 1.