Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Collect only Part of Nested Array

(1) ShareShare
ReportReport
Posted on by

I have an array that I ClearCollect into a collection of Items, then a nested table for "Days", and then a nested table for "activities." 

 

In the 2nd nested array of "Days", I need to only keep the first item in the array. 

 

So for example, in the first item of days, under day #2, I want to keep only the 1st item category 837. 

 

Before: 

 

[
 {
 "OriginDate": "2024-07-08", 
 "Identifier": 21523, 
 "days": [
 {
 "dayNumber": 1, 
 "activities": [
 {
 "category": 123,
 "sport": true
 }, 
 {
 "category": 435,
 "sport": false
 }
 ]
 }, 
 {
 "dayNumber": 2, 
 "activities": [
 {
 "category": 837,
 "sport": false
 }, 
 {
 "category": 827,
 "sport": true
 }
 ]
 }
 ]
 }, 
 {
 "OriginDate": "2024-07-09", 
 "Identifier": 21523, 
 "days": [
 {
 "dayNumber": 1, 
 "activities": [
 {
 "category": 123,
 "sport": true
 }, 
 {
 "category": 435,
 "sport": false
 }
 ]
 }, 
 {
 "dayNumber": 2, 
 "activities": [
 {
 "category": 837,
 "sport": false
 }, 
 {
 "category": 827,
 "sport": true
 }
 ]
 }
 ]
 }
 ]

Desired After: 

[
 {
 "OriginDate": "2024-07-08", 
 "Identifier": 21523, 
 "days": [
 {
 "dayNumber": 1, 
 "activities": [
 {
 "category": 123,
 "sport": true
 }, 
 {
 "category": 435,
 "sport": false
 }
 ]
 }, 
 {
 "dayNumber": 2, 
 "activities": [
 {
 "category": 837,
 "sport": false
 }
 ]
 }
 ]
 }, 
 {
 "OriginDate": "2024-07-09", 
 "Identifier": 21523, 
 "days": [
 {
 "dayNumber": 1, 
 "activities": [
 {
 "category": 123,
 "sport": true
 }, 
 {
 "category": 435,
 "sport": false
 }
 ]
 }, 
 {
 "dayNumber": 2, 
 "activities": [
 {
 "category": 837,
 "sport": false
 }
 ]
 }
 ]
 }
 ]

 

Any idea how I can do this? 

Categories:
  • Rex2025 Profile Picture
    on at
    Re: Collect only Part of Nested Array

    I wanted to throw in an actual sample of my data to help. 

     

    In the dutyPeriodNumber 2, I want to only keep the first item under "legs" while retaining the array format. 

     

    [
     {
     "sequenceOriginDate": "2024-07-16",
     "sequenceNumber": 28441,
     "sequenceStartDateTime": {
     "localTime": "2024-07-16T04:10:00",
     "gmt": "2024-07-16T09:10:00"
     },
     "sequenceEndDateTime": {
     "localTime": "2024-07-18T16:28:00",
     "gmt": "2024-07-18T21:28:00"
     },
     "dutyPeriods": [
     {
     "dutyPeriodNumber": 1,
     "odMinutes": 577,
     "numberOfLegs": 2,
     "legs": [
     {
     "legNumber": 361,
     "legIndex": 1,
     "blockTime": 215,
     "groundTime": 120
     },
     {
     "legNumber": 1622,
     "legIndex": 2,
     "blockTime": 167,
     "groundTime": 0
     }
     ]
     },
     {
     "dutyPeriodNumber": 2,
     "odMinutes": 376,
     "numberOfLegs": 2,
     "legs": [
     {
     "legNumber": 2827,
     "legIndex": 3,
     "blockTime": 97,
     "groundTime": 80
     
     },
     {
     "legNumber": 2043,
     "legIndex": 4,
     "blockTime": 124,
     "groundTime": 0
     }
     ]
     }
     ]
     }
    ]

     

  • Rex2025 Profile Picture
    on at
    Re: Collect only Part of Nested Array

    Hey! No worries & no rush. I appreciate any and all help I can get! 

  • Michael E. Gernaey Profile Picture
    40,272 Super User 2025 Season 1 on at
    Re: Collect only Part of Nested Array

    Hi @Rex2025 

     

    I promise I will give you a solution later today, its 130 am and going to bed. But yes can easily give you that when i get back.

     


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • Rex2025 Profile Picture
    on at
    Re: Collect only Part of Nested Array

    My power automate flow that I built is only returning Days 1 & 2, so that is what I will always get.

     

    But where I’ve struggled in the flow is limiting Day 2 to just 1 item. 

    If you have a solution in power automate, my current strategy has been a Select function, then

     

    take(item()?[‘day’], 2)


    That still returns all items though in Day 2. 

     

  • Michael E. Gernaey Profile Picture
    40,272 Super User 2025 Season 1 on at
    Re: Collect only Part of Nested Array

    Hi @Rex2025 

     

    Nice share thank you.

     

    So you'll have Many Items, all with Day 1 and Day 2. Ok just curious, are there other patterns like this. where Day3 or Day4-7 matter? I just want to either give you the fastest without caring because it won't change, or a strategy to do different patterns before I start.

     

    Thanks!


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • Rex2025 Profile Picture
    on at
    Re: Collect only Part of Nested Array

    So the array goes (indents for nests)

    • Item
      • First level
        • Second level item
        • second level item 
        • Possibly more… a “n” number 
      • first level
        • Second level item
        • possibly more
    • item #2

    It repeats that JSON format. 

    At the first level I want all the items from the first second level, but only the first item from Index, 2 of the second level. 

    So, if it is: 

    • Item 1
      • Day 1
        • Cat
        • dog
        • sheep
      • Day 2
        • Lizard
        • Horse
        • lion

     

    I want everything from Day 1, but only Lizard from Day 2. 

  • Michael E. Gernaey Profile Picture
    40,272 Super User 2025 Season 1 on at
    Re: Collect only Part of Nested Array

    Hi @Rex2025 

     

    How do you determine which things you want to keep? In your example, you kept both in day 1?

     


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard