# Find max value in array of ints

**URL:** https://community.make.com/t/find-max-value-in-array-of-ints/44594
**Category:** Questions
**Tags:** arrays
**Created:** [July 4, 2024, 10:01am UTC](https://community.make.com/t/find-max-value-in-array-of-ints/44594 "2024-07-04T10:01:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tal](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tal](https://community.make.com/u/tal)
#### Post date: [July 4, 2024, 10:01am UTC](https://community.make.com/t/find-max-value-in-array-of-ints/44594/1 "2024-07-04T10:01:56Z")

</div>

I created the blueprint below to try and find the maximum value in an array of numbers, but I can’t figure out how to update a variable’s value.  
Specifically, in the 2nd iteration, the value of max is -1 instead of 3.  
How can I do so?

Thanks.

```auto
{
    "name": "test2",
    "flow": [
        {
            "id": 6,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max",
                "scope": "execution",
                "value": "-1"
            },
            "metadata": {
                "designer": {
                    "x": 296,
                    "y": 15
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One execution"
                        }
                    }
                },
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    },
                    {
                        "name": "scope",
                        "type": "select",
                        "label": "Variable lifetime",
                        "required": true,
                        "validate": {
                            "enum": [
                                "roundtrip",
                                "execution"
                            ]
                        }
                    },
                    {
                        "name": "value",
                        "type": "any",
                        "label": "Variable value"
                    }
                ],
                "interface": [
                    {
                        "name": "max",
                        "type": "any",
                        "label": "max"
                    }
                ],
                "advanced": true
            }
        },
        {
            "id": 7,
            "module": "builtin:BasicFeeder",
            "version": 1,
            "parameters": {},
            "mapper": {
                "array": [
                    "3",
                    "2"
                ]
            },
            "metadata": {
                "designer": {
                    "x": 687,
                    "y": 11
                },
                "restore": {
                    "expect": {
                        "array": {
                            "mode": "chose",
                            "items": [
                                null,
                                null
                            ]
                        }
                    }
                },
                "expect": [
                    {
                        "mode": "edit",
                        "name": "array",
                        "spec": [],
                        "type": "array",
                        "label": "Array"
                    }
                ]
            }
        },
        {
            "id": 8,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max",
                "scope": "execution",
                "value": "{{if(6.max <= 7.value; 7.value; 6.max)}}"
            },
            "metadata": {
                "designer": {
                    "x": 1056,
                    "y": 19
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One execution"
                        }
                    }
                },
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    },
                    {
                        "name": "scope",
                        "type": "select",
                        "label": "Variable lifetime",
                        "required": true,
                        "validate": {
                            "enum": [
                                "roundtrip",
                                "execution"
                            ]
                        }
                    },
                    {
                        "name": "value",
                        "type": "any",
                        "label": "Variable value"
                    }
                ],
                "interface": [
                    {
                        "name": "max",
                        "type": "any",
                        "label": "max"
                    }
                ],
                "advanced": true
            }
        },
        {
            "id": 9,
            "module": "builtin:BasicAggregator",
            "version": 1,
            "parameters": {
                "feeder": 7
            },
            "mapper": {},
            "metadata": {
                "designer": {
                    "x": 1428,
                    "y": 16
                },
                "restore": {
                    "extra": {
                        "feeder": {
                            "label": "Iterator [7]"
                        },
                        "target": {
                            "label": "Custom"
                        }
                    }
                }
            }
        },
        {
            "id": 10,
            "module": "util:GetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max"
            },
            "metadata": {
                "designer": {
                    "x": 1871,
                    "y": 13
                },
                "restore": {},
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    }
                ],
                "interface": [
                    {
                        "name": "max",
                        "type": "any",
                        "label": "max"
                    }
                ]
            }
        }
    ],
    "metadata": {
        "instant": false,
        "version": 1,
        "scenario": {
            "roundtrips": 1,
            "maxErrors": 3,
            "autoCommit": true,
            "autoCommitTriggerLast": true,
            "sequential": false,
            "slots": null,
            "confidential": false,
            "dataloss": false,
            "dlq": false,
            "freshVariables": false
        },
        "designer": {
            "orphans": []
        },
        "zone": "eu2.make.com"
    }
}

```

---

<div class="post-metadata">

### Author: ![ManishMandot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/manishmandot/32/25887_2.png) [@ManishMandot](https://community.make.com/u/ManishMandot)
#### Post date: [July 4, 2024, 2:51pm UTC](https://community.make.com/t/find-max-value-in-array-of-ints/44594/2 "2024-07-04T14:51:15Z")

</div>

Hey @tal  
welcome to the make community

You can use Numeric aggregator  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/a/0/a0ed29e99dec59c821e74213dc9f85d9cc1af361.png)

---

<div class="post-metadata">

### Author: ![samliew](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/samliew/32/13327_2.png) [@samliew](https://community.make.com/u/samliew)
#### Post date: [July 5, 2024, 3:48am UTC](https://community.make.com/t/find-max-value-in-array-of-ints/44594/3 "2024-07-05T03:48:27Z")

</div>

You do not need so many modules.

Here’s an additional screenshot to show output of the **Numeric Aggregator** , as suggested by Manish:

 ![Screenshot_2024-07-05_110750](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/5/4/544dde5b95b895f5cfcaea0a076f91a501c1b503.png)

You can also use the built-in function `max`

![Screenshot_2024-07-05_110752](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/d/b/dbcab29203e4ff7b760c84312056b6e0f5d1763f.png)

For more information, see the function documentation in the [Help Center](https://www.make.com/en/help).

[samliew](https://samliew.com/services) – [request private consultation](https://samliew.com/request-quote?ServiceType=Automation%20Consultation&Referrer=Make)

> Join the [Make Fans](https://samliew.com/make-discord-invite) Discord server to [chat](https://samliew.com/make-discord-invite) with other makers!

---

<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: [July 21, 2024, 7:04am UTC](https://community.make.com/t/find-max-value-in-array-of-ints/44594/4 "2024-07-21T07:04:05Z")

</div>


