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.
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.
- Below is the screenshot of the output sorted in ascending order.
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'))
- Below is the screenshot of the output showing the lowest value based on LikesCount.
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'))
- Below is the screenshot of the output sorted in descending order.
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'))
- Below is the screenshot of the output showing the highest value based on LikesCount.
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.
Top comments (0)