cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to retreive or calculate minimum and maximum values from data after parse JSON

I am bulding a flow which retrieves a .json. (http action GET)
This .json contains 24 items. 
One of the values in these 24 items is the temperature data from a wheaterstation.
With the Parse Json I am able to convert the data to html, csv or use select from the Data Operations actions.
As an example the result from the select action in my flow:


json to select.png

 

From the 24 temperature values I want to determine the minimum and maximum temperature (and write them to a Sharepoint list). I have tried several suggested solutions to retrieve the minimum and maximum value, however did not succeed in finding a working solution. Perhaps I am looking for the wrong solutions, search terms etc.

 
What have i tried :

https://powerusers.microsoft.com/t5/Building-Flows/Convert-array-to-string/td-p/79125

 

https://powerusers.microsoft.com/t5/Building-Flows/How-to-get-value-of-array-from-a-JSON-Object-usin...

 

https://powerusers.microsoft.com/t5/Building-Flows/How-to-access-JSON-Array-items/td-p/83265

 

Resulting in errors as non supported types (float or string) etc. 

 

Maybe one of you could point me in the right direction?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to retreive or calculate minimum and maximum values from data after parse JSON

Hi @Anonymous,

 

Could you please share a full screenshot of your flow's configuration?

 

I agree with @Pieter_Veenstra's thought almost, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use Flow Button trigger.
  • Add a Compose action, Inputs set to following json data that you mentioned:
[
  {
    "time": "2018-04-04T00:00:00",
    "temperature": 8.7,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-05T00:00:00",
    "temperature": 8.8,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-06T00:00:00",
    "temperature": 12,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-07T00:00:00",
    "temperature": 10,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-08T00:00:00",
    "temperature": 6.1,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  }
]
  • Add a "Select" action, From set to output of "Compose" action. Within Map entry, type one entry. Name set to Temp and Value set to following formula:
item()?['temperature']
  • Add a Variables-> "Initialize variable" action, Name set to MaximunValue, Type set to Float and Value set to following formula:
first(body('Select'))?['Temp']
  • Add a Variables-> "Initialize variable" action, Name set to MinimumValue, Type set to Float and Value set to following formula:
first(body('Select'))?['Temp']
  • Add a parallel branch action, within left branch, add a "Apply to each" action, Input parameter set to output of "Select" action. Wihtin "Apply to each" action, add a Condition, Click "Edit in advanced mode", type the following formula:
@greater(item()?['Temp'], variables('MaximunValue'))

Within "If/yes" branch of Condition, add a "Set variable" action, Name set to MaximunValue, Value set to following formula:

item()?['Temp']

Within right branch, add a "Apply to each 2" action, Input parameter set to output of "Select" action. Wihtin "Apply to each" action, add a Condition, Click "Edit in advanced mode", type the following formula:

@less(item()?['Temp'], variables('MinimumValue'))

Within "If/yes" branch of Condition, add a "Set variable" action, Name set to MinimumValue, Value set to following formula:

item()?['Temp']
  • Under the Parallel branch action, add a Compose action, Inputs set to MaximunValue variable and MinimumValue variable.

 

Image reference:

15.JPG16.JPG17.JPG18.JPG19.JPG

The flow works successfullly as below:20.JPG

 

 

More details about using expression in flow actions, please check the following article:

Using expression in flow actions

 

More details about Parallel Branch action in Microsoft Flow, please check the following article:

https://flow.microsoft.com/en-us/blog/parallel-actions/

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Super User
Super User

Re: How to retreive or calculate minimum and maximum values from data after parse JSON

The easiest way is probably just to use actions that set variables within an Apply to Each step.

 

So within the Apply to each use a condition to thet the loweest value, the highest value to keep the total and keep a counter.

 

Then after the Apply to each calculate the average.

Community Support Team
Community Support Team

Re: How to retreive or calculate minimum and maximum values from data after parse JSON

Hi @Anonymous,

 

Could you please share a full screenshot of your flow's configuration?

 

I agree with @Pieter_Veenstra's thought almost, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use Flow Button trigger.
  • Add a Compose action, Inputs set to following json data that you mentioned:
[
  {
    "time": "2018-04-04T00:00:00",
    "temperature": 8.7,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-05T00:00:00",
    "temperature": 8.8,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-06T00:00:00",
    "temperature": 12,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-07T00:00:00",
    "temperature": 10,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  },
  {
    "time": "2018-04-08T00:00:00",
    "temperature": 6.1,
    "relativeHumidity": 98,
    "rainPastHour": 5.3
  }
]
  • Add a "Select" action, From set to output of "Compose" action. Within Map entry, type one entry. Name set to Temp and Value set to following formula:
item()?['temperature']
  • Add a Variables-> "Initialize variable" action, Name set to MaximunValue, Type set to Float and Value set to following formula:
first(body('Select'))?['Temp']
  • Add a Variables-> "Initialize variable" action, Name set to MinimumValue, Type set to Float and Value set to following formula:
first(body('Select'))?['Temp']
  • Add a parallel branch action, within left branch, add a "Apply to each" action, Input parameter set to output of "Select" action. Wihtin "Apply to each" action, add a Condition, Click "Edit in advanced mode", type the following formula:
@greater(item()?['Temp'], variables('MaximunValue'))

Within "If/yes" branch of Condition, add a "Set variable" action, Name set to MaximunValue, Value set to following formula:

item()?['Temp']

Within right branch, add a "Apply to each 2" action, Input parameter set to output of "Select" action. Wihtin "Apply to each" action, add a Condition, Click "Edit in advanced mode", type the following formula:

@less(item()?['Temp'], variables('MinimumValue'))

Within "If/yes" branch of Condition, add a "Set variable" action, Name set to MinimumValue, Value set to following formula:

item()?['Temp']
  • Under the Parallel branch action, add a Compose action, Inputs set to MaximunValue variable and MinimumValue variable.

 

Image reference:

15.JPG16.JPG17.JPG18.JPG19.JPG

The flow works successfullly as below:20.JPG

 

 

More details about using expression in flow actions, please check the following article:

Using expression in flow actions

 

More details about Parallel Branch action in Microsoft Flow, please check the following article:

https://flow.microsoft.com/en-us/blog/parallel-actions/

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Meneghino
Level 10

Re: How to retreive or calculate minimum and maximum values from data after parse JSON

Hi all, I find it difficult to believe that the max() expression cannot be used in this case.

Could @v-micsh-msft or @yoshihirok or anyone else confirm that max() cannot be used and that a loop with for each has to be used?

I have exactly the same situation/question as @Anonymous 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (3,638)