Power Apps Collections Introduction

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in powerapps collections are a special type of variable right we call them a table variable so powerapps collections what they do is they let you capture rows and Columns of data whereas if you think about a traditional variable where you're just capturing one piece of information right dog color equals white that is a you know like using set or update context collections we use collect or clear collect the idea is it's rows and columns so it is you know name uh buddy color white weight 60 pounds name chewy color tan weight 110 pounds right that's what a collection is so in powerapps we use collections a lot of times for two real reasons right one is to grab the data ahead of time so we can grab it and right Bunch it all up before we save it off to our data source especially like in offline apps where we want to like you know grab a bunch of things and hold it in memory and then when we're done we'll save it to the data source so that's one way we use collections the other way that we use collections is to Cache information so if we don't want to keep going back to a data source we can put the data into a collection and then reference that because it's a table just like the data source is so this video is a remake of one that I made about five years ago that has 300 000 views I thought it's probably time to update it so what we're going to do is we're gonna walk through all the pieces of what a collection is and Empower you to start using them in your power apps now keep in mind if you look in the description below there is jumping off points so if you want to jump to certain sections because you just want to see how to use one port function great jump ahead but if you're trying to understand the whole picture this is your video so let's just switch over to my desktop and take a look okay so over on the desktop I've started with a blank app I've done nothing to it so we can all learn about this together and so the first thing I always start with when I'm explaining collections is how do you create one so we can then explain what you're creating right so we're gonna throw a button on the screen and we're going to use the on Select Property and we're going to do something like this we're going to say collect and then call whatever you want to call it I'm gonna call it cool stuff my usual and so then here you're going to need to put in a record right so a record is a row and a list and so a record is always done like this in powerapps as well curly braces and we close it so that would put a blank row we don't want a blank rope that would do that so we're gonna do is we're gonna say all right I want a name and I want that to be Lori right I had a call with Lori this morning hi Lori and so um right that will create a column name of called name and then it'll have the value of worry and then say we want to have her phone number P in for phone number and her phone number is 12. yeah she has a very short phone number it's weird but so that right there is a record that has two columns and so if we press this button once so we'll just hold down the ALT key so we can press the button now if I come up here and highlight cool stuff look cool stuff data type table and then we hit the drop down and you can see that we have a name column with Lori and PN for 12. now the way the collect works is that if you press this button again it is going to add a row right because collect says hey if the collection doesn't exist create it and then add the row if it already exists which it does now then just add the row so if we press this button two three four five times now now we're going to see in our collection we have five Lori 12s right which I realize the data is done right why would I want to do this I know but we gotta we gotta get turn baby steps right so that is how you would put that in there if you wanted collect to put in two records at once you could literally just go here do a comma do curly braces again and then you could do name and then you would do Tom and then PN and then we would do 33 and now what's going to happen is we just have a collection with Lori and Tom when you edit the collect it wiped out what was cached in there so but now if we press this button again so let's press it two three times now we should see that we've got six people in here all right so Lori Tom Lori Tom Lori Tom six now if you're taking a chance a tough way to visualize this I agree remember that collections are tables insert a gallery right what do galleries want for their items property they just want a table so there's nothing from stopping up here and typing in cool stuff and there they are kind of pull this over and we can change this to be you know title and subtitle and then just change this from name to PN and so now we see the data great right so let's say your button and let's just name this button collect because it creates a simple collection for us now what if I want to wipe out all that data no big deal insert a button and so with this button we're going to do is we're going to use a different function called clear clear takes a collection like cool stuff and it will clear it it will wipe everything out so we'll rename this text button to clear and then if we press the button as you can probably guess we have nothing we press this we get two four six eight ten who do you appreciate now we won't do cheers and then we can clear those out again so that's very simple one more thing we gotta learn before we get a little more complex there's another function that you probably care about so let's insert this button and so this button what we're going to do is we're going to change this and we're going to say we want to clear collect clearcollect takes a collection and says hey if there's stuff in there clear it first and then add what I have here so if we do queer collect cool stuff and then we do our little curly brackets here and then we said name equals um buddy and then we said his phone number is I don't know what buddies number is one sure so now if we press let's rename the button so we don't forget all right we'll set that to clear collect and so now if we press this button so hit play so if we press this button it is going to put buddy in there let's clear if we had done this and if we hit clear collect what's going to happen it's going to clear the collection and then put buddy in there right now what's important to understand though is if right now right if I keep hitting clear collect we just keep deleting the row recreating right like it's not doing much but what we can now do is we can clear collect right we got buddy now we collect look there's Lori and Tom there's more Lori and Tom right because remember when he collected it was different than quitter collect collect said hey if there's something already in the collection then let me just add to the collections that's why it's adding rows so I see a lot of beginners struggle with this right when do I use Clear collection when I want use collect well you have to ask yourself do I want what was already in there or do I want to start blank and so that's kind of how you think about these two and of course Claire just wipes it all out again okay so there is art collections now you're probably thinking well all right Shane that was great and all but I don't want a bunch of buddies lorries and toms who doesn't want buddy Laurie and Tom that's rude no so what we're going to do is we're going to make ourselves a simple little interface real quick to collect what we want right so let's throw a label and pull this over here we'll set this label to be name then let's insert ourselves a text input now with the text input we're gonna do a couple quick things right we'll get rid of the default text I also want you over here to the left and rename this because we're going to use it in a formula in a minute and it's easier to reference it if you've got it renamed right so input name and I just double clicked on to rename it if you've ever done it or you can hit the Ellipsis and say rename here so then now we can insert a text label here and then we're going to say um phone number right and what we type here in the labels doesn't matter we could have just typed in Bob it doesn't matter and we'll do another text input we'll throw this one over here we'll get rid of default and then we're going to rename this one inp for input and then PN for phone number so then now what we're going to do is we're going to take our collect button so we're going to say copy we're going to paste it import over here right this is less typing for me so now we only want to do one at a time so we'll get rid of Tom bye Tom and then for name worry equals this right so we don't want name Lori we want name to be input name Dot text there it is and then for phone number now notice before I change this right phone numbers data type is number right when we do input of PN what are we gonna get we're gonna get text so what we need to do here we're going to delete the 12 is we're going to use the value function and inside there we're going to put input p n dot text that will convert the text that comes out of PN so the text 1 and text two to the number 12. Doesn't Remind You is click on a little input here we'll just change its format from number so I can only put in numbers but now watch so we'll clear this out and so now if we went here and we said chain n is number one duh we'll say collect there it is and now if we change this to Nicola and G is number two and collect and so now we're collecting the information from the text inputs we could still click this and throw Lori and Tom in there if we click this what would happen uh oh we lost Nicola and Shane right and there is no undo so they would just have to go back in here and re-enter the data again that's how collect works right you you design a collection and then once you've got the collection you know you've got your format your columns here then it just Wants What It Wants right name wants text it doesn't care if that text comes from hard coded like we did over here it doesn't care if it comes from a text input here it can come from a flow it could come from a variable it doesn't matter it just wants text in this spot right here where we're at so that's what it wants the same for this PN wants phone number wants a number doesn't care right I can change this to the number to be you know 12 plus 12 right that what is that it's 24. so then if I press collect now what happens we'll have a Shane and a 24. right don't overthink these things they just want what they want give them what they want and they will be happy you might be thinking can you show me an example of where you would use something like this so I'll show you maybe two one maybe two we'll see so one is if you've ever seen this app before and I'll put a link to the video series it's a multi-part series to build this thing out but down here if we go here and say new expense and so if we go here to um you know expense description right so this is demo that matter type of expense is training but so over here on the left this is a collection right and so this is how I am actually uh saying expense item is Taco expense cost is 12 20 whatever 22. when I hit save it saves that this is not the save button is not saving it off to the data source it's not getting saved to my data source right now it is just getting saved in a collection because I want to be able to come in here and then add you know pizza and then five dollars for pizza expensive pizza expensive tacos expensive everything but oh you know what tacos were actually two dollars oh that makes more sense right and so we can hit save so the idea of a collection this is a great use of a collection I want my user to be able to grab pull in data edit manipulate it right if you're new to collections this is too advanced for you right now but go watch the series or remember if you sign up at training.powerapps911.com to our YouTube Library you can download this working yeah but really this is look at that it's a gallery with its collection right this is the same type of stuff that you've already you just learned how to do just uh on steroids okay so that's one use of it um another use I won't demo but just to remind you so sometimes like if we have say we had a list of all the employees over here and I want to pick the people I was going to make work overtime this weekend so I want to have a select box that selected the people I was picking so click click click click as they're selecting the different employees I'm putting them into a collection so I can be like all right here's the list of people I selected great let me now you know press the process to continue getting that right so collections are used for that the next use of collections that we want to talk about is that collections can cache data sources okay so let's create a new screen and let's add um two data sources right so we'll go here we'll search for SharePoint way down here at the bottom is SharePoint SharePoint over in my powerapps videos and I'm going to add a department list and the employees list right so this is just adding them like you've always added data sources now that I've added them I'm going to insert a gallery and I'm going to show employees right nose cold stuff shows up here because collections they're just tables there's employees and that pulls them in so in this list there is a column called Department and so if I wanted to then use the Department's list to find out who the department manager is for executive in this case I would insert a label in here all right I guess I'd say you could and then I'm going to do a lookup to departments right that's my SharePoint list and then where uh title equals this item dot Department right and then we do manager and then there you go you see all the managers right so the problem with doing this this works this is terrible don't ever do this but what's happening here is that for every one of these departments it is making a call to the data source so if there's a hundred departments here then we're calling SharePoint 100 individual times to find those 100 different managers departments isn't going to change and it is a tiny list right so another use of collections insert a button here is I can go right here and I can say collect or we'll do quitter collect right most typically in this scenario not clear data clear collect and then what we want what do we want to collect I want to collect this into a new one so we'll call it coal Department remember you don't call it cold cow you can call it anything you want doesn't matter and for the item here instead of making records we can pass a whole table okay so if I do that what's going to happen this is going to create a collection called cocal and if we're looking cool Cal it is that entire SharePoint list right so in one call I got the whole SharePoint list and stored it into the collection so now I go over here and replace the lookup here and change this to Coal cow I get the same results but I get them faster because now if I have 100 Apartments it's checking memory a hundred times to get that instead of making 100 Network calls which are very expensive very slow to SharePoint so caching data with collections is a really neat way to neat it's a really interesting way to grab data and use it right so this is a very popular first use of collections it's just caching things keep in mind that clear collect or or collect either one is not delegable if you do not know what delegation is it is irresponsible to build powerapps you don't understand delegation right that's where you get the little yellow triangles the blue underlines watch the video on delegation four times and then come back it is not delegable so you can't cash a list with more items than the delegation limit and the delegation maximum limit could be two thousand it's 500 by default so if you had a list with 10 000 records you can't cash that in collections now if you're thinking Shane I saw this clever thing on the internet one time and how to like stock collections don't do that don't ever build collections more than 2 000 items if you can avoid it so the other thing that collections can do the same way that this said let me grab coal cow and let me uh or let me grab departments and put it in cold cow you can do the reverse say that we had a collection full of departments right so let's do it we're gonna be brave right so insert another button so let's say that I have a collection so clear collect coal Department cash right once again names don't matter and then we'll say all right in this one I want to have title equals demo and then um manager equals dude I don't know okay so if I did that right what does that do that makes a collection called cold apartment cash and it has one row in it manager dude title right so now that I've done that if we insert another button I can actually bulk write that to back to um our data source right so SharePoint in this case so what you can do is you can say collect and then in this case it is our SharePoint list departments and then give it coal Department cash like so so if I press this button now what it will do is it will take whatever's in cold apartment cash as long as the data structure matches and it does because I have a title manager column and those are titles the only required column so if I now press this button notice it took a half second if we go over to department so just use my little edit data tricks here look at the bottom there is demo and dude so this is one of the bulk ways you can do it now there's a lot of really cool bulk stuff you can do I guess I'll just put the link to that video up there above I have lots of videos I just try to make this one not too long um but so that would talk to you about bulk ways to you know use collect to push data out there now the last thing I'll just remind you is that you know these collections they are um you know they are tables so for example if I went back over here and I'm like hey you know I want to be able to get rid of these things well how do you get rid of stuff in a table right well you change this icon to look like a trash can and then you could use our dear friend remove and you say remove from cool stuff this item and so now if I click on the caller's record it's gone right now if I click on chain one it's gone right so all of your table functions work so remove add columns show columns you know we do a lot of stuff we have to manipulate massage collections to be exactly what we want all your table manipulation functions will work so keep that you can patch collections um you know they're a table the only caveat I'll throw is that collections don't work with forms you cannot use forms and collections together there's some Shenanigans to make that work again I'm not here to teach you Shenanigans I think you know that by me about me by now so there you go that's what we've got for today um if you need any help with collections or remember over at www.powerapps911.com right we have Consulting training mentoring right we'll get somebody on a call when you screen share just to fix your one problem let you move on no big deal let us know reach out to us over there um if you have any questions or comments that I can help in regards to this video leave them below I uh I try to respond to as many of those as I can and I always use those for ideas for future videos and with that I'm going to say thanks day
Info
Channel: Shane Young
Views: 75,764
Rating: undefined out of 5
Keywords: Shane Young, powerapps911, PowerApps, Power Apps, Collections, Collect function, Clear function, ClearCollect function, Remove function, data management, gallery, input controls, data source cache, data manipulation, app performance, tutorial, Microsoft Power Apps, powerapps collections, power apps collect data, powerapps collection table, powerapps collect function, power apps collect, power apps collection limit, power apps collection vs table, power apps collection
Id: 4zM-Oyhpc3U
Channel Id: undefined
Length: 18min 48sec (1128 seconds)
Published: Mon Apr 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.