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

How to get the second last element of an array

I am using a template "Email me a weekly summary of Office 365 service health notices" to get service health notifications. An array with 2  string parameters in it is used. The second one is the Published time that gives me the time service health update was published.  As the number of updates with respect to particular service is not fixed, the length of array is dynamic and the reason i am unable to pick the second last element.

 

Can i get an help asap.

6 REPLIES 6
Dual Super User III
Dual Super User III

Try the following formula. It gets the last two items in the array and then returns the first one.

first(skip(variables('ArrayName'),sub(length(variables('ArrayName')),2)))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Community Support
Community Support

Hi @Anonymous ,

 

If you want to get the PublishedTime contained in Message, please try the following Expression:

7.PNG

 

Best Regards,

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

@Pstork1 Thanks for the quick response.

Just to confirm, as you said ""the exporession gets the last two items in the array and then returns the first one "" . It means it will return the second last item right ??

 

I tried but it is popping up as Expression is invalid.

 

Please help


@Pstork1 wrote:

Try the following formula. It gets the last two items in the array and then returns the first one.

first(skip(variables('ArrayName'),sub(length(variables('ArrayName')),2)))

 

Anonymous
Not applicable

Hi @v-bacao-msft ,

Thanks for the response.

 

However, i am getting the published time. The problem here is as there are multiple updates for a service degradation before it gets restored, everytime the updated Published time goes into an array. The final one is the last element of array and hence i am looking for the second last element of array for comparing with the last element.

 

Please help.


@v-bacao-msft wrote:

Hi @Anonymous ,

 

If you want to get the PublishedTime contained in Message, please try the following Expression:

7.PNG

 

Best Regards,


 

Hi @Anonymous ,

 

You could use the expression provided by @Pstork1 :

first(skip(body('Filter_array'),sub(length(body('Filter_array')),2)))

Image reference:

9.PNG

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Dual Super User III
Dual Super User III

Yes, it will return the next to last item in the array.  Make sure you change the Arrayname to whatever variable you are storing the array in.  Otherwise the code should work.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (61,889)