I am trying to get the last N items from an array.
For example in the below I want to get the last two items in the list. I know I can use take() to get the first N items however how would I get the last ones?
My data does not contain a reference which I can use to reorder the list correctly, unless I am missing some kind of reverse command which I could possibly use (then run a take function on that)
Appreciate any ideas! Thanks
[
{
...(Other records)
{
"Ref": "100",
"First Name": "Nathan",
},
{
"Ref": "1356",
"First Name": "Anne",
},
{
"Ref": "1345",
"First Name": "Ben",
},
{
"Ref": "75",
"First Name": "Carly",
}
]
Solved! Go to Solution.
Hi @CJRV ,
The expression in the post mentioned by @VictorIvanidze should do the job with a little modification:
skip(variables('varData'), sub(length(variables('varData')), variables('N')))
where varData is your JSON array
and N is your N value.
Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.
Thanks Victor, I think that would return the 2nd to last item, but not the last N items (by N this might be the last 10 items for a larger array for example)
Just test it yourself.
Hi, @CJRV! I think Victor is exactly right, and you can use the expression in that thread to base yours on. You'll just have to remove the first() part of the expression, which returns only the first element of the resulting array (whereas you want both of the last two elements.) Without the first() part, it should be spot on for you to retrieve the last two elements. (To spell it out, the formula will get the # of elements in the array, then skip all but the last two, which is exactly what you want.)
Hi @CJRV ,
The expression in the post mentioned by @VictorIvanidze should do the job with a little modification:
skip(variables('varData'), sub(length(variables('varData')), variables('N')))
where varData is your JSON array
and N is your N value.
Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.
Yes that did work indeed! Thanks everyone for clarifying this 😀
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Announcing a new way to share your feedback with the Power Automate Team.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
67 | |
22 | |
16 | |
16 | |
11 |
User | Count |
---|---|
133 | |
44 | |
32 | |
32 | |
28 |