# How to shorten code for an Airtable filter

**URL:** https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263
**Category:** Questions about Thunkable X
**Tags:** beginner, help
**Created:** [February 11, 2021, 5:57am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263 "2021-02-11T05:57:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aarav-work](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/aarav-work/32/95738_2.png) [@aarav-work](https://community.thunkable.com/u/aarav-work)
#### Post date: [February 11, 2021, 5:57am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/1 "2021-02-11T05:57:43Z")

</div>

Hello again Thunkers

Today I read a amazing Post

> [@\[Solved\] How to Filter data from Airtable](https://community.thunkable.com/t/solved-how-to-filter-data-from-airtable/537129):
>
> I was able to get the search functionality to work in my home screen to search on specific titles. I am now trying to do similar functionality on a profile screen that would display only the current user’s posts (so the ones with the user’s email in the email field). I’m using the same idea of generating lists for the Key, email and title column. And then filtering through the email list to only use the ones that have the user’s email. I don’t have error handling to it freezes. I know it’s retr…

So I thought This is a amazing idea

Is there anyway where the code could be shorter, or you could give me the final code?

@domhnallohanlon pls can you try to give the answer.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [February 11, 2021, 7:56am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/2 "2021-02-11T07:56:18Z")

</div>

Check this  
[https://x.thunkable.com/projectPage/5fb9fb1dbfeb240011084d78](https://x.thunkable.com/projectPage/5fb9fb1dbfeb240011084d78)

When you select a category, the code will filter the table and show the filtered results in the second list.

---

<div class="post-metadata">

### Author: ![aarav-work](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/aarav-work/32/95738_2.png) [@aarav-work](https://community.thunkable.com/u/aarav-work)
#### Post date: [February 11, 2021, 9:22am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/3 "2021-02-11T09:22:52Z")

</div>

Thanks @muneer

I did not understand the part below, where is SelectedCat:

![Screen Shot 2021-02-11 at 2.50.50 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/8/98a23d9e5f0855f5deb87b8099c2274240007c29.png)

this block was inside the Data viewer list clicked event.

 ![Screen Shot 2021-02-11 at 2.51.02 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/2/c2192e55b3c0e46301ac6f4712364e022b042e63.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [February 11, 2021, 10:18am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/4 "2021-02-11T10:18:20Z")

</div>

Basically the DVL (Data Viewer List) lacks a filter criteria and therefore it will always display all the records in the table so as a workaround you will connect the DVL with a temporary table that you will clear all data in this table and fill it with the required data according to the user selection. This is the reason behind deleting all rows in that table.

---

<div class="post-metadata">

### Author: ![aarav-work](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/aarav-work/32/95738_2.png) [@aarav-work](https://community.thunkable.com/u/aarav-work)
#### Post date: [February 11, 2021, 10:19am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/5 "2021-02-11T10:19:46Z")

</div>

thanks again @muneer

I went ahead and I came tot his block, can you explain it?

![Screen Shot 2021-02-11 at 3.52.31 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/8/48a916f307b9be7c2a607cde0d46cfcfbd291324.png)

and how it becomes a row id?

![Screen Shot 2021-02-11 at 4.02.20 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/1/e1fdcc0deedf44c527fe3f7fd36c5febed9a8a19.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [February 11, 2021, 11:57am UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/6 "2021-02-11T11:57:30Z")

</div>

Once you have cleared your temporary table successfully, you know want to populate it with the selected rows from your main table.

First retrieve the column from the main table that contains the row IDs for all rows. This column is created automatically by Airtable.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/a/2a33ebac1ef604b10f1cdd30a240c75aa1b7335d.png)

This gives us a list of all unique IDs for the main table.

Now you need to loop through the records of the main table and check if the row meets your criteria.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/0/506c5c849a80e6b171cbead55fcd16ef81df49ee.png)  
Here we created a loop to take each rowID from the list and assign it to variable `j` then retrieve the information in that row using the `get block` and check if this row satisfies the condition with the `if condition` if it satisfies then we go ahead and append this row to the temporary table (`SelectedCat` in this case).

In the end of the loop you will get your temporary table containing **only** the required rows from the main table.

Hope this makes it clear.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [February 11, 2021, 12:02pm UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/7 "2021-02-11T12:02:05Z")

</div>

This is another example using free text search

[https://x.thunkable.com/projectPage/600c35d2f153060012143dc8](https://x.thunkable.com/projectPage/600c35d2f153060012143dc8)

---

<div class="post-metadata">

### Author: ![aarav-work](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/aarav-work/32/95738_2.png) [@aarav-work](https://community.thunkable.com/u/aarav-work)
#### Post date: [February 11, 2021, 12:54pm UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/8 "2021-02-11T12:54:57Z")

</div>

thanks

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:29pm UTC](https://community.thunkable.com/t/how-to-shorten-code-for-an-airtable-filter/1092263/9 "2024-11-08T13:29:29Z")

</div>


