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 / connecting tables & gr...
Power Apps
Answered

connecting tables & grouping?

(0) ShareShare
ReportReport
Posted on by 482

Dear community,

 

I have the following tables in CDS:

 

Users

  • Default Users table from CDS (including all users in the tenant)

Projects

Assigned UsersLookUp to Users table
Project NameText
Start DateDate
End DateDate

 

Time Tracking

HoursFloating Point Number
ProjectLookup to Projects table
DateDate

 

Now each user can be assigned to n projects. I would assign those Users to a project in the Projects table. 

 

With above data structure, can I achieve something like the following table in Power Apps? If so, how would I go about this? I managed to create a calendar, but I wouldn't know how to connect the project & users like below.

 

example-table.png

 

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mrQ 

    Yes, you can use the Groupby function in your formulas to produce this.

    As a pure example, you can go this route:

    Groupby(Projects,
     "Assigned Users",
     "Projects"
    )

    However, what I am not seeing is the relationship of the Hours in the Time Tracking to the Project and the User.  If there is some relationship that defines the hours to the user, then you can add that into the formula using the AddColumns function.

     

    I hope this is helpful for you and gets you to the next step.  If not, then provide more details on the relationship of the Time Tracking and the User. 

  • mrQ Profile Picture
    482 on at

    Hi @RandyHayes 

    Thanks for your response.

     

    What I don't know is, how do I achieve connecting the dates and its reported hours per user with the projects? Like in the screenshot (Excel) attached. I managed to create a collection including the Users and their assigned projects, as well as a calendar (plain calendar), but how do I connect those? If even possible...

     

    The hours are reported in the Time Tracking table. It has a Date column as well as a Lookup to the Projects table. To report time, a user would simply add something like 0.5h for the 30th of December 2020 to the Time Tracking table. 

     

    Thank you.

  • mrQ Profile Picture
    482 on at

    @RandyHayes 

    Just wondering if you already had the chance to check? 

    One more thing to add: I wouldn't want to create each date as a new column... I don't think that's a good solution.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @mrQ 

    It appears that you have a classical many to many relationship.  The structure of your tables should look something like this.  I would develop the app around the tasks column with dropdowns for User and Project. For more information on how to structure a PowerApp around this design, check out my blog post https://powerusers.microsoft.com/t5/News-Announcements/Relational-Database-Principles-and-PowerApps-Step-3-Keys-and/ba-p/188640  In this example, the Tasks table is referred to a junction table and by adding fields to it, you can better describe what happened to a particular task on a particular day.  By employing this structure,  you will be able to see all tasks performed during a project by each user as well as all tasks performed by a user and assigned to a project._Many2Many.png

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mrQ 

    Sorry for the delay.  Yes, if you want to track the time like that, you are going to need to have something that connects the user time to the project.  Your time tracking table would, at the least need to associate the user to the entry.  This is done already with the created by column, but that would assume that the person recording will always be the one entering.  So, if you can at least have the User as part of that time tracking table, then you could start to get somewhere.

    Then, with that in place, you can group by the dates and the users to get the information you want in the way that you want it.  But, until then, you need to have some relationship of time to user to project.

  • mrQ Profile Picture
    482 on at

    Thanks both for your responses.

    @Drrickryp that was an interesting read!

    @RandyHayes I wanted to use the 'Created By' field at first, but I added a "User" field to the "Time Tracking" table now, which is a LookUp field to the "Users" table.

     

    Anyway, to make it simpler for this scenario, I think just listing the projects on the Y axis and the various days on the X axis is enough. Therefore, I would like to display all the projects just for a pre-selected user. So, the following graphic shows my endgoal:

    new-projects-days.png

    However, I'm still stuck on the logic part of combining those tables all together in one (or many) galleries to make it look like above image.

     

    Since I would like the Users to be able to switch between days, as well as adding Projects dynamically (...), I don't want to create the days or the specific projects as columns.

    I managed to create a calendar that is showing today's date +- 7 days and I can switch back and forth 7 days by clicking on the arrows. This should serve as the header-part. Unfortunately, I couldn't wrap my head around on how I would display/set up the rest... 😞

    projects-test.png

     

    Would I need to create several galleries to achieve my goal?

     

    Thanks and kind regards,

     

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mrQ 

    Yes, in general you will be working with a nested Gallery.

    So, in the formula that you have (and you don't need a collection for this, just set that formula minus the collection in the Items property of your Gallery), you are adding a column to your results called Projects and it has the entire table of projects.  What you would want to do is something similar to the following in your Items property of the Gallery:

    ForAll(
     Sequence(7),
     With({thisDate: Coalesce(glbFirstDayOfMonth, DateAdd(Today(), -Weekday(Today(), Monday), Days))},
    
     {GalleryDate: DateAdd(thisDate, Value, Days)
     Projects: ShowColumns(Filter('Time Tracking', dateColumn=thisDate), "projectLookupColumn")
     }
     )
    )

    (not doing this in a formula editor, so first replace with the appropriate names from your add, and then correct any typos I might have)

     

    Now, you will need to add a nested Gallery into the primary Gallery and then set its Items property to : ThisItem.Projects

    Now, you can place labels in the Gallery to display the Projects for that date.

     

    I believe you will get closer with this, but since I am not intimately familiar with your data or app flow, you might have additional questions or needs...so, try that and post back your progress.

     

     

     

  • mrQ Profile Picture
    482 on at

    Hi @RandyHayes 

    Thanks for your reply. 

    This is what I got... There is still a problem that the project names are not being displayed for some reason (I can look into that later), but you can see that at least the data is being loaded and the rows from the nested gallery are being "displayed".

    gallery-projects2.png

     

    However, I would like to list the projects only once on the left side, rather than for each gallery item and then have the dates (as it is now) at the top (all according to the Excel screenshot I've provided in my previous post). Is there a way to do that?

     

    Thanks for your effort so for. I highly appreciate it!! 

    Kind regards,

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @mrQ 

    I got the impression from your last post that you were going more with a "Week" list and then a list of projects under it.

    If you want to go the other way - a list of all projects (for the week) listed on the left and then summed values underneath dates, then that is another approach. 

    What's your poison?

     

  • mrQ Profile Picture
    482 on at

    Hi @RandyHayes 

    I'm so sorry for confusing you this way...  and again, thanks so much for your time so far. I really hope I can solve this soon. The end goal was like in the Excel screenshot I attached in one my previous posts.

     

    ...And with your help, I was finally able to set it up correctly. Thanks again!

    But then... Once everything was working, I continued improving on it and, what I didn't mention at the beginning of this post is, that every project has "project tasks". So I went ahead and wanted to implement them as well... that worked too! I could replicate all the relevant tables and values in a collection, but now I'm stuck because with an additional table - project tasks - I would need to get 3 levels of nested galleries and I just found out that it isn't possible with Power Apps :-/.

     

    This is what my collection looks like (and I have it in a collection because the user should be able to add more "projects" to this collection with a click of a button...):

    nested-galleries.gif

     

    This is my formula to create the collection. Note that I often get some records with First() - this is just for testing purposes. Later on, I'm planning to let the users choose their displayed projects manually (but that should be easy to adjust, once everything is working as it should).

     

     

    ClearCollect(
     colProjectTimeTrackingv3,
     With(
     {
     // adds the users time trackings to a temporary variable
     thisTimeEntry: ShowColumns(
     'Time Trackings',
     "crc06_billed",
     "crc06_comments",
     "crc06_date",
     "crc06_hours",
     "crc06_name",
     "crc06_Project",
     "crc06_User"
     )
     },
     {
     // creates the project column
     Projects: LookUp(
     Projects,
     Project = First(thisTimeEntry).crc06_Project.Project,
     Name
     ),
     // creates a new table for all the project tasks connected to the project in the 'Project Tasks' column
     
     'Project Tasks': AddColumns(
     ShowColumns(
     Filter(
     'Project Tasks',
     Project.Project = LookUp(
     Projects,
     Project = First(thisTimeEntry).crc06_Project.Project,
     Project
     )
     ),
     "crc06_billable",
     "crc06_name",
     "crc06_Project",
     "crc06_projecttaskid"
     ),
     // adds 7 days from the selected date (calendar) to each project task inside the column 'GalleryDate'
     "GalleryDate",
     ForAll(
     Sequence(7),
     With(
     {
     selectedDate: gblFirstDayOfMonth + Value - Weekday(gblFirstDayOfMonth, StartOfWeek.Monday) 
     },
     {
     Date: selectedDate,
     timeTracked: 
     ShowColumns(
     Filter(
     'Time Trackings' As tempTimeTracking, 
     Date(Year(tempTimeTracking.Date),Month(tempTimeTracking.Date),Day(tempTimeTracking.Date)) = selectedDate,
     tempTimeTracking.Project.Project = First(thisTimeEntry).crc06_Project.Project
     ),
     "crc06_billed","crc06_comments","crc06_date","crc06_hours","crc06_name","crc06_ProjectTask","crc06_Project"
     )
     }
     )
     )
     )
     }
     )
    )

     

     

     

    Thanks again and kind regards,

     

    *edit*

    On Google I just found a screenshot of what I roughly need. The guy who did this App didn't nest the project-tasks... without the nested tasks I would already have what I need. However, if somehow possible (...) I would really like to have the tasks nested below each project. Its just a user experience/personal thing... 🙂

    mockup.jpg

     

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

#2
11manish Profile Picture

11manish 193

#3
Valantis Profile Picture

Valantis 138

Last 30 days Overall leaderboard