Convert an Excel formula to SQL
Moving a spreadsheet calculation into a database means translating formula thinking into set thinking. SUMIFS becomes a WHERE clause with an aggregate, VLOOKUP becomes a JOIN, and COUNTIFS becomes COUNT with the same filters. The Formula Translator gives you the SQL version next to the explanation.
The output uses standard syntax with PostgreSQL-style date literals. Check function names if you use MySQL or SQL Server.
Worked example: SUMIFS to SQL
Orders sheet: column B is Region, column C is Order date, column D is Revenue.
=SUMIFS(D2:D5000,B2:B5000,"West",C2:C5000,">="&DATE(2026,1,1))SELECT COALESCE(SUM(revenue), 0) AS west_revenue
FROM orders
WHERE region = 'West'
AND order_date >= DATE '2026-01-01';Each SUMIFS criteria pair becomes an AND condition. COALESCE matters: SUMIFS returns 0 when nothing matches, but SQL SUM returns NULL. Also note that Excel compares text without regard to case, while most databases do not. For COUNTIFS use COUNT(*) with the same WHERE conditions, and for a per-region total add GROUP BY region instead of a fixed filter.
How it works
- 01Paste the Excel or Sheets formula into the Formula Translator.
- 02Open the SQL tab and copy the query.
- 03Replace the table and column names with your own.
- 04Run it on a small sample and compare the result with the sheet.
Common questions
- How does VLOOKUP convert to SQL?
- As a LEFT JOIN on the lookup column. VLOOKUP returns the first match only, so deduplicate the lookup table first or the join will repeat order rows.
- Why do my SQL results differ from Excel?
- The usual causes are text case, trailing spaces, NULL versus empty cells, and dates stored as text.
- Does it support MySQL and SQL Server?
- The generated SQL is standard and often needs small changes for dialect-specific functions such as date arithmetic.
Try it on your own formula
The Formula Translator is free for 5 formulas a day, with no account.