web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / App using two SharePoi...
Power Apps
Answered

App using two SharePoint lists, with one item in one list connected to multiple items in the other

(0) ShareShare
ReportReport
Posted on by 151

Essentially, I believe I'm asking if I could replicate database behavior using lists. I know I should ideally use Dataverse tables, but they're expensive and I couldn't get the greenlight from management, so I'm stuck with doing my best using lists. So, here's my requirement.

 

I have a MainList, let's say with a Title and bunch of other columns that's of no interest for this topic. For each item in the MainList, I may have one or more Tasks associated, and the number of tasks per MainList item is not known until the time a user is trying to create an item. So, one MainList item may have 1 task, another one may have 5 tasks, and it could even go up to 30 or 40. So I was thinking of using two lists; the above mentioned MainList, and a second SubList.

 

MainList = ID, Title, {Other Stuff}

SubList = ID, Task, MainListID

 

When the user adds an item to the MainList, they should be able to press a button and add one or more items to the SubList. Is this achievable using PowerApps? If so, how would I go about doing this?

Categories:
I have the same question (0)
  • SebS Profile Picture
    4,616 Moderator on at

    @SachS  

     

    Yes, One-to-Many Relationship is achievable using Sharepoint Lists.

     

    It's done in a few ways using Lookup Column. I do not recommend this approach, but it's there for You if You want to try it.

     

    You can use a combination of Patch, collection and ForAll it's not easy for a beginner but really useful and You can build a nice UI for a user 🙂

     

    https://i.imgur.com/9tHetm1.gif

     

  • SachS Profile Picture
    151 on at

    @SebS  That looks like more or less what I want - is there any way you can attach the source for this sample you've shown, or maybe give me basics to get started?

  • SebS Profile Picture
    4,616 Moderator on at

    @SachS 

     

    No Problem I will make You the whole process of how I create this give me 10-20 min I'm a slow writer 🙂

  • Verified answer
    SebS Profile Picture
    4,616 Moderator on at

    How I create this example :

     

    SharePoint

    Two Lists :

     

    List1 Name - Staff

    columns - Title type Text availble on List creation recomended to not rename this column

     

    Add Sample Data like Names of Staff to Title column

     

    List2 Name - Task

    columns - Title same as above, TaskName type Single Text, Date type Date and Time

     

    Power Apps

     

    Connect both Lists to the App using Data buton on left navigation

     

    SebS_0-1688681453297.png

     

    Add

     

    Two Dropdowns to the Screen:

     

    Dropdown1 connect it to Staff and point it to Title column to see list of Sample names added

     

    SebS_1-1688681533747.png

     

    Dropdown2 add Sample tasks or You can create support lists similar to List1 and connect it to Dropdown2

     

     

     

    ["Dance","Clean","Walk","Sleep"]

     

     

     

    SebS_2-1688681703706.png

     

    Date Picker - just add a date picker from insert this one You do not need do anything alse

     

    Button Add Task

     

    This is where we will create a colection called colTasks this collection will populate our first Gallery what will show assigned tasks what You than will Patch to SP list.

     

    OnSelect property add below code:

     

     

     

    Collect(
     colTasks,
     {
     Title: Dropdown1.Selected.ID,
     Date: DatePicker1.SelectedDate,
     TaskName: Dropdown2.Selected.Value
     }
    )

     

     

     

    Title is a FK taken from Staff List what will build relationship between List Staff and List Tasks  in One To Many  type.

     

    First Gallery list of tasks

     

    SebS_3-1688682220938.png

     

    Add Blank Gallery. In items add colTasks

     

    SebS_4-1688682480750.png

     

    and to the template add two lables one for Date and secound for Task Name

    in Text property add:

     

     

     

    ThisItem.Date

     

     

    and

     

     

    ThisItem.TaskName

     

     

     

    Header is created from Ractangle and lable with Text lined up to position of lables in Gallery

     

    Button Submit Task List

     

    This button will add all tasks from collection colTasks to Tasks list

     

    OnSelect property add below code

     

    You can see i'm using ForAll to loop the collection and patch each item to SPlist I'm also creating an alias for the collection called c to make it easier for patch to understand what I'm asigning to each column from the collection

     

    at end I'm clearing collection to make sure Gallery is ready for new input.

     

     

     

    ForAll(
     colTasks As c,
     Patch(
     Tasks,
     Defaults(Tasks),
     {
     Title: c.Title,
     TaskName: c.TaskName,
     Date: c.Date
     }
     )
    );
    Clear(colTasks)

     

     

     

    Now the last two galleries

     

    Create a blank gallery again and in Item property add Staff

     

     

    SebS_5-1688682877242.png

     

    Than add lable

     

     

     

    ThisItem.Title

     

     

     

    Secound Gallery

     

    Copy Task Gallery and in Item property add this code

     

     

     

    Filter(Tasks,Title = Text(Gallery2.Selected.ID))

     

     

     

    Make sure Gallery2 reflecting name of gallery with Staff Names I wrap Gallery2.Selected.ID in Text() we will compare it to title column and that column is type Text so this need to match.

     

     

    Now Gallery Staff (Gallery2) we will add a counter for tasks but first you will need to add a lable to this gallery and in Text property  add

     

     

     

    Thisitem.ID

     

     

     

    call it lbl_StaffID

     

    Now add another lable call it lbl_TaskCounter and in Text property add below code

     

     

     

    Sum(ForAll(Filter(Tasks,Title = lbl_StaffID.Text),1),Value)

     

     

     

     

    all should look like this maybe not same designe 😛

     

    SebS_6-1688683365080.png

     

    Ok we move back to Gallery1 and we add Remove function just in case someon will make a mistake 🙂

     

    Add icon "Trash" to the Template inside of the gallery

     

    and in onselect Property of the Icon add below code

     

     

     

    Remove(colTasks,Thisitem)

     

     

     

    SebS_7-1688683502218.png

     

    Now hope all is working for You 🙂

  • SachS Profile Picture
    151 on at

    This is more or less what I wanted; I was able to use this and get it to work the way I wanted. Thank you!

  • SebS Profile Picture
    4,616 Moderator on at

    @SachS 

     

    You are more than welcome happy to help 🙂

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard