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 Apps / Task Hierarchy in Powe...
Power Apps
Answered

Task Hierarchy in PowerApps

(0) ShareShare
ReportReport
Posted on by 76

I have a PowerApp that has Project, Task and Subtask Hierarchy.

The way I used to build my Hierarchy was in my OnStart, where I would make a collection and build a Hierarchy for My Projects to have when expanding and retracting.
Code looked like this:

ClearCollect(
 colTasks, 
 AddColumns(Project_Data, 
 "Show", ThisRecord.TaskLvl = 0,
 "Expanded", false, 
 "TaskHierarchy",If(ThisRecord.TaskLvl= 0, "0", If(ThisRecord.TaskLvl= 1, With({localOuterRecord: ThisRecord}, LookUp(Project_Data, Id=localOuterRecord.ParentId).TaskNo & "." & Text(localOuterRecord.TaskNo, "000")))),
 "ProjectCreationDate", If(ThisRecord.TaskLvl= 0, Oprettet, If(ThisRecord.TaskLvl= 1, With({localOuterRecord: ThisRecord}, LookUp(Project_Data, Id=localOuterRecord.ParentId).Created)))
 )
); 

// Then later in the OnStart I would have some more code
With(
 {localColTasks: colTasks}, 
 UpdateIf(
 colTasks As ThisTask, 
 ThisTask.TaskLvl=2,
 {
 TaskHierarchy: LookUp(localColTasks, Id=ThisTask.ParentId).TaskHierarchy & "." & Text(ThisTask.TaskNo, "000"),
 ProjectCreationDate: LookUp(localColTasks, Id=ThisTask.ParentId).ProjectCreationDate
 }
 ) 
); 


Later on in a Gallery on one of the app screens I would have a gallery that had an expand/retract icon

With({localItem: ThisItem},
UpdateIf(
 colTasks,
 // Show childTasks of current task
 !localItem.Expanded && ParentId = localItem.Id && TaskLvl <> 0,
 {Show: true},
 // Hide Hierarchy of current task
 localItem.Expanded && 
 (localItem.ProjectId = ThisRecord.ProjectId) && 
 !(ThisRecord.TaskLvl = 0) && 
 (localItem.TaskHierarchy in ThisRecord.TaskHierarchy) && 
 Id <> localItem.Id, 
 {Show: false, Expanded: false}, 
 // change Expanded field for this task
 Id = localItem.Id,
 {Expanded: !localItem.Expanded}));


This worked pretty well until I started having over 1000 items in my SharePoint list.
This started making the app slower and slower. I believe that it took on average 1,5-2 minutes to get in the app from the loading screen, and then it would take additional 20-30 seconds for all the data to get shown proper.
What I ended doing (to speed the app load mostly) is I moved the OnStart functionality to my Screen OnVisible with the same code.
I actually didn't know how to achieve this so I made a timer that runs once when the app is started. This timer then clicks a hidden button that executes the code.
Problem solved... Well kinda...


My app did start loading much, much faster and it only took like 10-30 seconds for everything to get shown inside the app. But the user was inside the app.

So now I am at a crossroad. I can either:

Try to somehow optimize this code so it runs faster where I can somehow incorporate the ClearCollect part with the With part and have it as a single block of code instead of one block running and then the second running.

Is this possible at all?

Something else I tried doing was instead of making an AddColumn where I create my TaskHierarchy I can "hardcode" the TaskHierarchy in my SharePoint list. This way I have no need for the ClearCollect at all. All the code still works fine. The only thing that now is ABSOLUTLY not working is the collapse part of my code: 

// Hide Hierarchy of current task
 localItem.Expanded && 
 (localItem.ProjectId = ThisRecord.ProjectId) && 
 !(ThisRecord.TaskLvl = 0) && 
 (localItem.TaskHierarchy in ThisRecord.TaskHierarchy) && 
 Id <> localItem.Id, 
 {Show: false, Expanded: false}, 
 // change Expanded field for this task
 Id = localItem.Id,
 {Expanded: !localItem.Expanded}));

Data gets loaded on average 10 ish seconds faster. I still see al the projects, I can still expand my project tasks and subtasks.
Where this approach fails is when I try collapsing my tasks and subtasks. Nothing happens!!

Is there somebody that can figure out what this last part of the code needs to start working??

Failing that is there a better way to build the Hierarchy with my first method (OnStart) or will this always be a problem down the line?







Categories:
I have the same question (0)
  • Verified answer
    VintagePush Profile Picture
    76 on at

    Ok, So i managed to figure it out.

    I made a new column in my SharePoint called TaskHierarchy

    So i was able to calculate values in my TaskLvl and TaskNo columns and write them into the TaskHierarchy.

    All my Top level tasks always start with 0 in TaskLvl and 0 in TaskNo

    this way easy. The hard part was figuring out the rest of it.

    My task level 1 and my task level 2 were tricky to figure out.


    So i started by making a text label and writing and figuring out what i had on a random task i was on.

    code looks like this:

    "Parent:" & 
    varParentItem.TaskLvl &
    "
    TaskLvl:" & 
    varParentItem.TaskLvl + 1 &
    "
    TaskNo: " & 
    If(VarMode = "EditMode", ThisItem.TaskNo, CountA(Filter(Projekt_Data, ProjectId=varParentItem.ProjectId, ParentId=ParentId_DataCard1.Default).Id)+1)
    
    


    Having this it made it a bit easier to write out the res of my Hierarchy.

    Code for that ended up being:

    If(varParentItem.TaskLvl + 1 = 0, "0",
     
     varParentItem.TaskLvl + 1 = 1, "0.00" & If(VarMode = "EditMode", ThisItem.TaskNo, 
     CountA(Filter(GanttChartProjektOversigt_Data, ProjectId=varParentItem.ProjectId, 
     ParentId=ParentId_DataCard1.Default).Id)+1),
    
     varParentItem.TaskLvl + 1 = 2, "0.0" & varParentItem.TaskLvl & ".0" & If(VarMode = "EditMode", 
     ThisItem.TaskNo, CountA(Filter(GanttChartProjektOversigt_Data, 
     ProjectId=varParentItem.ProjectId, ParentId=ParentId_DataCard1.Default).Id)+1)
    )



    This way my original expand and collapse code in the gallery worked just fine.

    This saved me around 50 seconds of load for the app.

    I went from having code in my app onStart in a collection to me building out the hierarchy by only looking in a SharePoint column. 




     


  • DevaangSoni Profile Picture
    11 on at

    Hi All,

    Is there any way to show direct and indirect reportees using office365 connection in power apps through gallery?

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard