# Conditional iteration to Google Sheets

**URL:** <https://community.make.com/t/conditional-iteration-to-google-sheets/6867>\
**Category:** Questions\
**Tags:** google-sheets\
**Created:** [January 18, 2023, 7:57am UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867 "2023-01-18T07:57:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crumbs](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Crumbs](https://community.make.com/u/Crumbs)\
**Post date:** [January 18, 2023, 7:57am UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/1 "2023-01-18T07:57:33Z")

</div>

I have an iterator which iterates over an array of objects that look like this:

```auto
[
   {"field_id": "name", "value": "John"}, 
   {"field_id": "phone", "value": "0502221321"}, 
   {"field_id": "email_address", "value": "a@a.com"}
] 

```

For each such object, I want to first check if it’s a relevant `field_id` (let’s say only “name” and “phone” are relevant, and I don’t need “email\_address”). Then for relevant objects, I want to populate a Google Sheet row so that “John” (i.e. `value` field of object where `"field_id"="name"`) and “0502221321” (i.e. `value` field of object where `"field_id"="phone"`) go into the appropriate columns (let’s say column A and B).

I’m stuck at the part between the iterator and how to conditionally select objects to go into the Google Sheets row.  
If I simply choose “Add row” after the iterator - it will add a new row for each field (new row for “John”, new row for “0502221321”, etc.).

How can I select the correct value for each column in the Google Sheets?

In pseudo-code it would look like this:

```auto
for item in array:
    if item["field_id"] = "name":
        insert item["value"] into row A
    if item["field_id"] = "phone":
        insert item["value"] into row B

```

---

<div class="post-metadata">

**Author:** ![Florian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/florian/32/11118_2.png) [@Florian](https://community.make.com/u/Florian)\
**Post date:** [January 18, 2023, 9:16am UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/2 "2023-01-18T09:16:31Z")

</div>

Don’t iterate and use this formula instead : `get(map(array; "value"; "field_id"; "name"); 1)`  
I upload you an example with the blueprint, import it in a new scenario to look at it.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/make/original/2X/1/1c0f43d25dedfaf5f3a655e6430f91438564c944.png)  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/make/original/2X/6/61f69f236c6880788b32776e02680e04d1b0e3fe.png)

[extract object.json](https://community.make.com/uploads/short-url/sugCuSG1b1AOZa8dyQNWOnNhTpO.json) (20.8 KB)

[M@gic Integration](https://magic-integration.com)

---

<div class="post-metadata">

**Author:** ![Crumbs](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Crumbs](https://community.make.com/u/Crumbs)\
**Post date:** [January 18, 2023, 9:32am UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/3 "2023-01-18T09:32:33Z")

</div>

Wow… so much I need to learn… much simpler and cleaner. Thanks so much!

---

<div class="post-metadata">

**Author:** ![Florian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/florian/32/11118_2.png) [@Florian](https://community.make.com/u/Florian)\
**Post date:** [January 18, 2023, 9:35am UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/4 "2023-01-18T09:35:12Z")

</div>

If you need, private message me , I can train you or give support. meanwhile enjoy the solution and analyse the formula.

---

<div class="post-metadata">

**Author:** ![alex.newpath](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/alex.newpath/32/84_2.png) [@alex.newpath](https://community.make.com/u/alex.newpath)\
**Post date:** [January 18, 2023, 5:04pm UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/5 "2023-01-18T17:04:34Z")

</div>

An iterator uses an array, and in your example you had just 1 element in the array, albeit with 3 collections. So the iterator would iterate just once over the elements rather than iterating through each collection.

The [get/map technique](https://community.make.com/t/extract-an-item-from-array-get-and-map-function-make-beginners-guide/2134) is very useful when looking through collections/objects for a specific item. the `get(<expression>;1)` can also be replaced with` first(map(<expression>))` where first just chooses the first element of the returned array from map().

---

<div class="post-metadata">

**Author:** ![Make\_Bot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/make_bot/32/14661_2.png) [@Make\_Bot](https://community.make.com/u/Make_Bot)\
**Post date:** [September 7, 2023, 3:23pm UTC](https://community.make.com/t/conditional-iteration-to-google-sheets/6867/6 "2023-09-07T15:23:17Z")

</div>


