# HSTACK formula generator

> Describe what you need and get a HSTACK formula for Excel and Google Sheets, run on real data before you copy it. Plus 8 tested HSTACK examples.

Source: https://spreadsheetpractice.com/tools/formula-generator/hstack · Updated October 29, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

HSTACK places ranges side by side to build one table, so you can pick columns that aren't next to each other, put them in a new order, or add a calculated column, all in one formula that updates with the source.

Describe the task at [HSTACK formula generator](https://spreadsheetpractice.com/tools/formula-generator/hstack) and get a HSTACK formula for Excel and Google Sheets, tested on real data.

## Tested HSTACK examples

### Return non-adjacent columns with XLOOKUP

`=XLOOKUP(J1,A2:A8,CHOOSECOLS(A2:G8,2,6,7))`

Excel. Result on the sample sheet: 1 row (J2:L2). [See it and try it](https://spreadsheetpractice.com/formulas/xlookup-non-adjacent-columns)

### Find the highest value for each category

`=HSTACK(UNIQUE(A2:A13),MAXIFS(C2:C13,A2:A13,UNIQUE(A2:A13)))`

Excel. Result on the sample sheet: 3 rows (E2:F4). [See it and try it](https://spreadsheetpractice.com/formulas/highest-value-for-each-category)

### Make a ranked leaderboard with a formula

`=SORT(HSTACK(RANK.EQ(B2:B9,B2:B9),A2:B9),1)`

Excel. Result on the sample sheet: 8 rows (D2:F9). [See it and try it](https://spreadsheetpractice.com/formulas/make-a-ranked-leaderboard)

### Merge two tables by a common ID

`=HSTACK(A2:B7,XLOOKUP(A2:A7,D2:D6,E2:E6,"Missing"))`

Excel. Result on the sample sheet: 6 rows (G2:I7). [See it and try it](https://spreadsheetpractice.com/formulas/merge-two-tables-by-id)

### Count how many times each value appears

`=HSTACK(UNIQUE(A2:A12),COUNTIF(A2:A12,UNIQUE(A2:A12)))`

Excel. Result on the sample sheet: 4 rows (D2:E5). [See it and try it](https://spreadsheetpractice.com/formulas/count-how-many-times-each-value-appears)

### Total each category with one formula

`=HSTACK(UNIQUE(B2:B9),SUMIF(B2:B9,UNIQUE(B2:B9),C2:C9))`

Excel. Result on the sample sheet: 4 rows (E2:F5). [See it and try it](https://spreadsheetpractice.com/formulas/total-each-category-with-one-formula)

### Sum by category with one formula

`=HSTACK(UNIQUE(A2:A13),SUMIFS(C2:C13,A2:A13,UNIQUE(A2:A13)))`

Excel. Result on the sample sheet: 4 rows (E2:F5). [See it and try it](https://spreadsheetpractice.com/formulas/sum-by-category-with-one-formula)

### Compare two price lists and find changed prices

`=LET(old,XLOOKUP(D2:D8,A2:A7,B2:B7,"New"),FILTER(HSTACK(D2:D8,old,E2:E8),old<>E2:E8))`

Excel. Result on the sample sheet: 4 rows (G2:I5). [See it and try it](https://spreadsheetpractice.com/formulas/compare-two-price-lists)

## Questions

### What does the HSTACK formula generator do?

You describe the task in plain English, and it writes the formula, using HSTACK where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.

### What does HSTACK do?

HSTACK places ranges side by side to build one table, so you can pick columns that aren't next to each other, put them in a new order, or add a calculated column, all in one formula that updates with the source.

### Can I learn to write HSTACK formulas myself?

Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the HSTACK function page has a practice exercise.

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
