DEV Community

Ruthramugesh
Ruthramugesh

Posted on

How to get the lowest and highest values from an array of objects using Power Automate?

Introduction:
In this article, we will explore how to retrieve the lowest and highest values from an array of objects using Power Automate expressions. By leveraging built-in functions, we can efficiently sort and extract the required values. This step-by-step guide, along with screenshots, will walk you through the process to achieve this seamlessly.

1. Store the array of objects in the Compose action.

Image description

2. Use the sort() expression in the Compose action to arrange the data in ascending order.

  • Expression for ascending: sort(outputs('Compose_-_Store_Array_of_Object'), 'LikesCount')
  • In the above expression, specify the property to sort in ascending order.

Image description

  • Below is the screenshot of the output sorted in ascending order.

Image description

3. Use the first() expression in the Compose action to get the lowest value from the array of objects.

  • Expression for first(): first(outputs('Compose_-_Sorted_in_Ascending_Order'))

Image description

  • Below is the screenshot of the output showing the lowest value based on LikesCount.

Image description

4. Use the reverse() expression in the Compose action to sort the array in descending order after sorting it in ascending order.

  • Expression for reverse(): reverse(outputs('Compose_-_Sorted_in_Ascending_Order'))

Image description

  • Below is the screenshot of the output sorted in descending order.

Image description

5. Use the first() expression in the Compose action to get the highest value from the array of objects.

  • Expression for first(): first(outputs('Compose_-_Sorted_in_Descending_Order'))

Image description

  • Below is the screenshot of the output showing the highest value based on LikesCount.

Image description

Conclusion:
By using the sort() expression, we can easily get the lowest value by sorting in ascending order. Similarly, by using the reverse() expression, we can sort in descending order to get the highest value. Finally, the first() expression helps retrieve either the lowest or highest value efficiently.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

šŸ‘‹ Kindness is contagious

Please leave a ā¤ļø or a friendly comment on this post if you found it helpful!

Okay