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 / How do i get the max d...
Power Automate
Answered

How do i get the max date from Select output?

(0) ShareShare
ReportReport
Posted on by 28
Hi all, i need to get the max date from an array. I'm trying to not use a variable as i want to run the apply to each this is within as max concurrency.  
 
{
    "body": [
        "2022-06-01",
        "2022-06-01",
        "2022-06-01",
        "2022-06-30",
        "2022-06-01",
        "2022-06-01",
        "2022-06-10",
        "2022-07-13"
    ]
}
 
Tried 'Max(body('Select'))' and get an error
 
 'The template language function 'Max' expects all of its parameters to be either integer or decimal numbers. Found invalid parameter types: 'String'.'.
 
Any ideas?
Categories:
I have the same question (0)
  • Verified answer
    David_MA Profile Picture
    14,078 Super User 2026 Season 1 on at

    You will need to get rid of the hyphens in the dates and format them as an integer. You can then use a compose action with an expression to return the max value. Your flow will look like this:

    David_MA_0-1667485702410.png

    The expression in the select statement to format the Created date is, which you will need to switch to map mode to enter:

     

    int(formatDateTime(item()?['Created'],'yyyyMMdd'))

     

    And the formula in Compose is:

     

    max(body('Select'))

     

     

  • cheekyv Profile Picture
    28 on at

    Ah, ok... so i end up with 20220713 as the result. How do i convert that back to a date?

  • David_MA Profile Picture
    14,078 Super User 2026 Season 1 on at

    I suppose you could just add another action to generate what you were originally doing for your date format and use the above just to get your max date value.

  • cheekyv Profile Picture
    28 on at

    Hi, i ended up adding a second compose 🙂 

     

    concat(substring(outputs('Pick_MaxDate'),0,4),'-',substring(outputs('Pick_MaxDate'),4,2),'-',substring(outputs('Pick_MaxDate'),6,2))
  • Matthy79 Profile Picture
    4,188 Super User 2024 Season 1 on at

    Hello,

     

    I know it is been solved and the last post has been a while but I would suggest to do it like this:

     

    last(sort(outputs('Compose_sample_output')['body']))

     

    Of course instead of "outputs('Compose_sample_output')" you have to put in the action you are getting this object from the first post.

  • CU06081659-0 Profile Picture
    134 on at

    Hi,

     

    I have to create a Flow based on the below 2 conditions. The file names are always in 'XYZ_ddMMyy.xlsx' format.

     

    Condition 1: If the file is not more than 14 days from today then it should be kept as it is
    Condition 2: If the file belongs to the last day of every month or it is the last file of that month whether it is on last day or not then it should be kept as it is

    I have been able to identify the 1st condition fully and also the 2nd condition partially i.e. whether the file belongs to the last day of the month or not. The portion which I am not been able to create is if the file doesn't belong to the last day of the month but it was the last file that we had received for that month. E.g. if we may have received a file on 24th and it was the last file that we had received for that month then this too should be considered. I mean I need the file with the MAX date for a month. This should be done for each of the months.

    I am attaching the screenshots of the Flow and would appreciate if anyone can help me.

    1st Compose Action: FilenameWithExtension
    2nd Compose Action: substring(outputs('Compose_-_File_Name_with_Extension'), 25, 6)

    3rd Compose Action: formatDateTime(concat('20', substring(outputs('Compose_-_Extracted_Date'), 4, 2), '-', substring(outputs('Compose_-_Extracted_Date'), 2, 2), '-', substring(outputs('Compose_-_Extracted_Date'), 0, 2)), 'yyyy-MM-dd')

    4th Compose Action: formatDateTime(addDays(startOfMonth(addDays(outputs('Compose_-_Formatted_Date'), 1)), -1), 'yyyy-MM-dd')

     

    Thank you.

     

    Shubhabrata_0-1716556422661.png

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 557

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 264 Super User 2026 Season 1

Last 30 days Overall leaderboard