web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Compare date property ...
Power Automate
Answered

Compare date property in an array

(0) ShareShare
ReportReport
Posted on by 19

I have an HTTP action which returns values as follows;

 

 

{



"value": [

{

"deviceName" : "Testmachine1",

"LastContacted" : "01/10/2021" // DD/MM//YYYY

}

{

"deviceName" : "Testmachine2",

"LastContacted" : "01/11/2021" // DD/MM//YYYY

}

{

"deviceName" : "Testmachine3",

"LastContacted" : "01/12/2021" // DD/MM//YYYY

}

}

 

 

By looking at the above json values, it is clearly visible that the third record with a device name "Testmachine3" date property "LastContacted" is greater (recent) than the other two records (Testmachine1 & Testmachine2) and how can I achieve this scenario using power automate flow. scope here is, I would to choose from the list of values which value's date property is greater. 

Categories:
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    I'm hoping it doesn't return the JSON exactly the same as what you have above as it's not valid 😉

     

    Assuming you have the following data, and that the date format is always going to be dd/MM/yyyy

     

    {
     "value": [
     {
     "deviceName": "Testmachine1",
     "LastContacted": "01/10/2021"
     },
     {
     "deviceName": "Testmachine2",
     "LastContacted": "01/11/2021"
     },
     {
     "deviceName": "Testmachine3",
     "LastContacted": "01/12/2021"
     }
     ]
    }

     

    grantjenkins_0-1666697718540.png

     

    To clean up the output so we are accessing the value array directly I'd use a Select. I'd also reformat the date so it's in the format yyyy-MM-dd so we can easily sort on it. After it's all sorted you can reformat the dates however you want.

     

    For the From I've got the following expression to just get the array.

     

    outputs('Compose_Data')?['value']

     

    For deviceName I have:

     

    item()?['deviceName']

     

    For LastContacted I have the following which extracts out the day, month and year and reorders/splits into yyyy-MM-dd format.

     

    concat(substring(item()?['LastContacted'], 6,4),'-',substring(item()?['LastContacted'], 3,2),'-',substring(item()?['LastContacted'], 0,2))

     

    grantjenkins_1-1666697757979.png

    I then use the sort expression to sort on LastContacted, then wrap that into a reverse to have it sorted by LastContacted in descending order.

     

    reverse(sort(body('Select_Data'), 'LastContacted'))

     

    grantjenkins_2-1666697981656.png

     

    If you then wanted to reformat the dates back into dd/MM/yyyy then you could do the following.

     

    For deviceName I have the same as before:

     

    item()?['deviceName']

     

    For LastContacted I have:

     

    formatDateTime(item()?['LastContacted'], 'dd/MM/yyyy')

     

    grantjenkins_3-1666698484190.png

     

    The final output would be:

    grantjenkins_4-1666698618498.png

     

     

    NOTE: After posting my reply I read your initial question again and realized that you were actually just trying to get the latest object based on the date. Not all is lost as now that we have our sorted array of objects, we can just use another Compose to get the first item in the array which is what you are after 🙂

     

    body('Select_Date_Format')[0]

     

    grantjenkins_5-1666699073259.png

     

    Final output would be:

    grantjenkins_6-1666699141938.png

     

  • Verified answer
    SWO-Sujithkumar Profile Picture
    19 on at

     

     

    Thanks a lot for your help! it worked well.

     

    Yes, you are right that return JSON is not valid as I just added for reference.

     

     

     

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 389

#2
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard