# Can you sort by two columns?

**URL:** <https://community.glideapps.com/t/can-you-sort-by-two-columns/25469>\
**Category:** Ask for Help\
**Created:** [April 12, 2021, 2:06pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469 "2021-04-12T14:06:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 12, 2021, 2:06pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/1 "2021-04-12T14:06:09Z")

</div>

I want to sort a table by two levels, column A and column B. I can only see that you can sort by one column. Am I missing anything or are there any tricks?

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 12, 2021, 2:21pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/2 "2021-04-12T14:21:57Z")

</div>

You can create a template column that joins two columns together. Then sort by that template column. Just do some thorough testing to make sure it’s sorting correctly if your first column has varying lengths. For something like this, I like to separate both values in the template with a ‘-’ or ‘|’, so hopefully it sorts properly alphabetically.

---

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 16, 2021, 4:05am UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/3 "2021-04-16T04:05:39Z")

</div>

thanks!

---

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 22, 2021, 3:52am UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/4 "2021-04-22T03:52:55Z")

</div>

I tried this method and it works but I ended up having to zero fill my numbers as it was sorting incorrectly. For example 100 would be sorted before 20 and 3. I used the following function in Google Sheets =ARRAYFORMULA(if(ISBLANK(D2),"",TEXT(D2,“0000000000”))). The challenge is that it the formula doesnt copy down when Glide creates a new row. Is there a way to put this formula in Glide Apps?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 22, 2021, 5:37am UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/5 "2021-04-22T05:37:51Z")

</div>

Try using D2:D instead of D2, I believe it will work.

However if you do not really need that data inside the Sheet, you can try Jeff’s method, which would work inside Glide.

---

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 23, 2021, 2:23pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/6 "2021-04-23T14:23:29Z")

</div>

I have tried D2:D but the issue is that i get a #REF! Error.

 ![Screen Shot 2021-04-23 at 10.24.39 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/0/505eceebf72090aac8ee0a72a2c13d4f437b33c8.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 23, 2021, 2:29pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/7 "2021-04-23T14:29:00Z")

</div>

As the error says, you have data in the rest of the column, so the arrayformula can’t fill the rest of the column. Delete the data in the column below the row that contains the formula.

---

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 23, 2021, 11:50pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/8 "2021-04-23T23:50:47Z")

</div>

That is perfect, I thought you had to copy the array formula down. I didn’t realize that you only have the formula at the top and the values automatically copy all the way down. This is AMAZING!

Thank you so much!

---

<div class="post-metadata">

**Author:** ![laureljt](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/laureljt/32/24763_2.png) [@laureljt](https://community.glideapps.com/u/laureljt)\
**Post date:** [April 23, 2021, 11:57pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/9 "2021-04-23T23:57:24Z")

</div>

One other thing I found out that I am others know but wanted to contribute. The CONCATENATE formula does not work the way I expected with the ARRAYFORMULA. Instead I used the CONCAT command and that did the trick. The only limitation is that CONCAT only combines two inputs.

=ARRAYFORMULA(CONCAT(B2:B,if(ISBLANK(X2:X),"",CONCAT(" → ",X2:X))))

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 23, 2021, 11:57pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/10 "2021-04-23T23:57:31Z")

</div>

You can read more about it here.

> [@Tutorial: Arrayformula in Google Sheets, good practices & how to overcome Arrayformula restrictions with scripts](https://community.glideapps.com/t/tutorial-arrayformula-in-google-sheets-good-practices-how-to-overcome-arrayformula-restrictions-with-scripts/9727):
>
> Hi, Today I will show you the script that can make copying formulas down work, when it does not work with arrayformula. But first, let’s have some introductions about arrayformula, for those who has not used this before in Google Sheets, some equivalents in Glide and some good practices while using it. I hope it can help you in building your Glide apps as well as applying it in your normal day job. 
> 
> > **1/ Definition**
> >
> > Arrayformula is defined as “a range, mathematical expression using one cell range …

Hope it helps.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 23, 2021, 11:58pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/11 "2021-04-23T23:58:32Z")

</div>

I would use a template column inside Glide for this, again, if you don’t need to see that formula in Sheets.

---

<div class="post-metadata">

**Author:** ![NoCodeAndy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nocodeandy/32/62530_2.png) [@NoCodeAndy](https://community.glideapps.com/u/NoCodeAndy)\
**Post date:** [January 17, 2024, 4:52pm UTC](https://community.glideapps.com/t/can-you-sort-by-two-columns/25469/12 "2024-01-17T16:52:31Z")

</div>


