# \[Solved\] How can I use Google Sheets data in a ForEach loop?

**URL:** <https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107>\
**Category:** Questions about Thunkable X\
**Created:** [May 18, 2022, 11:25am UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107 "2022-05-18T11:25:42Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [May 18, 2022, 11:25am UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/1 "2022-05-18T11:25:42Z")

</div>

Hi Community,  
I am trying to load data from Google Sheet to Firebase , i have more than 250 rows but after loading 20 rows it completed. What could be possible cause.

Does cloud variable has limit of storing data ?? or there could be issue in the table ( I tried removing last lines but it could load only specific amount of data)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/d/5d2880a0c247cfcb9647b6fa6b22adab9d481ce0.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:** [May 18, 2022, 11:48am UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/2 "2022-05-18T11:48:12Z")

</div>

You are doing it in a very complicated an slow method.

All what I can see from this code is that you want **3** columns to be written to Firebase so first get each column in a separate `list` variable using the `list of values block` but once for **food** then for **calories** and last for **serve**.

Now that you have the 3 lists start with a count loop from 1 to length of list.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/8/c8619726eebcb50d6eec529696a04744fdcfbd8f.png)  
read the lists with the count variable **i** and save the values to cloud variable as you are doing it now.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [May 18, 2022, 11:58am UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/3 "2022-05-18T11:58:11Z")

</div>

I’d love to learn more about the move from Sheets to Firebase? What prompted this move?

For a best experience with getting your data into the cloud variable, you should load your data first and then try to push it all via looping.

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [May 18, 2022, 12:13pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/4 "2022-05-18T12:13:25Z")

</div>

Thanks Muneer, I wanted Food should be created as nested Object.  
For faster retrieval from Food ITem ( Search)  
FoodCalorieMeter  
|  
FoodITem  
|\_Calories  
|\_Serving

---

<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:** [May 18, 2022, 12:15pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/5 "2022-05-18T12:15:38Z")

</div>

> [@r0han](#):
>
> I wanted Food should be created as nested Object.

This is exactly what I proposed.

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [May 18, 2022, 12:20pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/6 "2022-05-18T12:20:04Z")

</div>

Hi Jared, i was not able to load data directly to firebase , it has 250 rows.  
It was easy to load in google sheet and then to firebase, hence tried this method.

also, i found sheets quickly loads to the screen, without much retrieval efforts.

My current objective is to load data into firebase, once user selects item from list viewer, it fetches data from firebase, because sheets is slow.

I may be doing it wrong… trying all ways for faster retrieval.

---

<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:** [May 18, 2022, 12:25pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/7 "2022-05-18T12:25:57Z")

</div>

Check this

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/3/f3d52b48407bcb7bbb92985cfb593740c942d416.png)

This is based on the Assumption that the **Food** column in your table is **unique**

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [May 18, 2022, 12:33pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/8 "2022-05-18T12:33:43Z")

</div>

Thanks for this @muneer , Much Appreciated… i will try this as well.

However, from below, Why does it stops after loading 20 rows, is my concern.

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/b/4b257870672db1d66c5e6f2c23d2b90fc91e2c0d.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:** [May 18, 2022, 12:36pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/9 "2022-05-18T12:36:48Z")

</div>

The `get value` blocks are asynchronous and would cause a timing mismatch for the loop. The `cloud variables` in the other hand are synchronous and will force the loop to wait until the operation is completed.

In my code, I’m getting all the values from the Google sheet first then start the loop without having to worry about the timing inside the loop.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [May 18, 2022, 1:02pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/10 "2022-05-18T13:02:49Z")

</div>

Probably because of the google sheets imposed api rate limit…

I’m encouraging all to check out xano for these types of uses! Is super fast and easy to get started with!!

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/0/50d087280a6fb60deb103081c25ef2d8c3f10737.jpeg)

Each loop you call the same sheet three times. 3 per loop \* 20 loops equals 60 calls within a minute and then your blocked until the next minute.

One more solid example of why google sheets is not the best choice for a backend Database. 🙂

---

<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:** [May 18, 2022, 1:44pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/11 "2022-05-18T13:44:32Z")

</div>

If this is the case then my locks will surely work because it takes only 4 API calls.

However, I understand that Thunkable uses GraphQL so the **project limit** should apply not the user limit, isn’t it?

Is there a Google project being created at our end when we connect to a Google sheet from Thunkable? That will be a big security hole!!!

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [May 18, 2022, 3:29pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/12 "2022-05-18T15:29:49Z")

</div>

Your code is working… Thank You very much …

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [May 18, 2022, 3:31pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/13 "2022-05-18T15:31:40Z")

</div>

> [@muneer](#):
>
> However, I understand that Thunkable uses GraphQL so the **project limit** should apply not the user limit, isn’t it?

I’d have to check with our engineers, but from the look of it, it seems to be following the user limit. It’s getting 60 pings from the same ip address at least before quitting. That’s my guess for now.

> [@muneer](#):
>
> Is there a Google project being created at our end when we connect to a Google sheet from Thunkable? That will be a big security hole!!!

not sure what you’re asking here. as far as I can tell, we aren’t creating anything in google when just connecting to a sheet.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [August 16, 2022, 3:32pm UTC](https://community.thunkable.com/t/solved-how-can-i-use-google-sheets-data-in-a-foreach-loop/1882107/14 "2022-08-16T15:32:13Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
