# Formula to Retrieve The MAX number in the List of Objects

May I know what is the Formula to Retrieve The MAX number [kWh] in the List of Objects?

Examples

Thanks The formula MAX is fine to look for the highest number, like e.g. kWh.
But you need to provide the input in the right format.
As you can see in the docs (https://docs.appgyver.com/reference/formula_functions/math/max) , the formula MAX requires a list of numbers: An example in the docs is MAX([100, 3, 20]) returns 100

My recomendation for you:

• first understand how the data looks like, that you use for the input. A nice way is to do it with ENCODE_JSON, e.g. ENCODE_JSON(data.kWhRecords) and display the result in a paragraph.
• second drill down the data until you have a list that is usable as input for the MAX() function. Most likely you will find functions like LOOKUP() and MAP() helpful.
1 Like

You can PLUCK the kWh values from `data.kWhRecords` to find the maximum value among them:

`MAX(PLUCK(data.kWhRecords, "kWh"))`

Hi Mari,
Currently has no error. But it still does not display anything at all. There’s data.
May I know where is the issue currently?
Thanks in advance Hi, there shouldn’t be any problem with the formula, for me the following works fine: Is it possible that you’re trying to pluck the maximum value already before the data has loaded completely → empty result?

Hi Mari,
How am I Supposed to check IF I plucking the maximum value already before the data has loaded completely?

As for I know on the same page there is a list of data being populated as well (using the same data) and it is working fine.

Hi @Yao_Cheng_Lim, you could create page variables to bind to the max and min value texts instead of displaying them directly with a formula, and then use the formulas in “Set page variable” nodes after the data variable has been initialized on the data variable’s logic canvas. Would that help?

Hi @Mari ,

I followed your instructions. But still unable to display.

This is my logic.

Not sure IF what I am doing is right.

When I try to change the value for “minKWH” it works.

Wait Why is my “kWh” from data is in String format. While I set Data Resource for “kWh” to be Number?

For the Max & Min Function, it works. But, I would like to know why is it automatically added as a String instead of as a number? Because this I unable to produce. Thanks in advance Hi, are the kWh records saved in number or string format in your database? Looks like they might be coming in in string format.

Did I understand correctly that you got the max and min values to work? If you’re still having some trouble, you can do:

`MAX(MAP(data.kWhRecords, NUMBER(item.kWh))`

Hi Mari,

It works already. Just that I am curious as to why kWh records save is in String format instead.

haha. Anyhow thanks alot.