Power Apps Combo Box DefaultSelectedItems

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's quick thursday tip we're going to talk about the combo box and how to set its default selected items we're also going to look a little bit about how the table structure works the record structure works and just help you guys understand this control that sometimes has its mind of its own should be fast should be fun but first here's our intro hi my name is shane young with powerapps 911 those guys and today we're going to look at the combo box and more specifically about the combo box setting default selected items so i've done a whole video on that i'll make sure that it's linked somewhere but what i want to do today is just concentrate on this idea that getting the combo box to set itself to default that you want is a lot of times more difficult than you wanted so let's switch over to my desktop let's just play with this goofy little control and see if we can make it happy today all right so i've got a completely blank app i just created the app and the very first thing we'll do is going to be like hey insert input and a combo box and like i said i'm assuming you have some familiarity with it you're just here to figure out a little bit better how to set this thing and to that end the first thing i'm going to do is we're just going to throw a data source at so instead of using this goofball over here i'm going to say hey i want to add some data i'm going to search for sharepoint there it is and connect in now keep in mind we're doing this with sharepoint as our data source but we do not it is not dependent on sharepoint this is just the easiest one for me to demo for you guys and in a minute we're actually going to handcraft a bunch of stuff which will be even way more unique so we're going to pull in my powerapps videos and then my good old famous employees list we'll connect it in and after a second it's in there so now we'll make sure we click on the combo box we'll say use employees and then you'll notice right away that it doesn't show a usable field so i'm just going to say show people's first names you'll also remember you get the little yellow thing here that's because the search functionality of combobox is not deliberable to sharepoint not talking about that today but just want to make sure you knew that's why the yellow triangle is there okay so then if we hit the drop down and hold down the alt key cool we got some names in here so now the first question you guys are always like hey how do i get this the default so you click on the box you're like every other control on the planet you use default well guess what default does nothing for combo boxes so don't even look at it you need to go straight to default selected items and this should be your clue that it behaves a lot different than you want right because we thought about a drop down if i wanted to default to chewie's record i would literally just type in chewy and it'd be like cool but it's not going to work here it gives me an error and if you hover it's going to give you a hint expected a table value so default selected items has to either be a table or a record right it doesn't tell you it can be a record but it actually can just be a record so that means that in order for this to work you can never just throw in your text like this you have got to get a record now this is where a lot of people struggle with like what record okay so the the key message here is go back to your items right whatever your items is so in this case it's my sharepoint employees list but if this was a hard-coded items if it was uh you know a collection whatever your items is the record has to come from the same data set so that's that's that's the hardest first part of this and we're going to come back to submit we're going to put in some hard-coded data to really make this a little trickier but right now we have employees so then what i'm going to do here is i'm going to go back to default selected items and so this can't be this but if we wanted just a single match we could use lookup which returns a record we say look up in employees where first name wherever first name is first name equals chewy and so that's a query that gets chewy's record and as soon as powerapps is done you can see that the control defaults to that so you can use a lookup and because it that lookup returns a record and that record matches the data set that is in the items property dot connected okay so that's the first challenge that a lot of you have is this idea that you know how do i get that one in this case i've got to do a lookup now what if though with the with uh the combo box you can select multiple right so if i choose chewy and daniel so how would i make chewie and daniel both default well look up returns a record one match so that's not going to work so then now what i'm going to have to do is i need to do some type of filter and so typically that's going to look something like this right because filter returns a table of data and default selected items can be a table of records that match your items so filter employees and so here you know i probably don't even have a good filter well all right we're just going to make this work so i would say filter the records where first name equals chewy or first name first name such a pain has a space in it so i hate spaces first name equals daniel we do that and that and so after that processes it hits the two matches for us so we have managed to set that now you're looking at that like well shane but i get like seven or whatever right it doesn't have to be exactly that i just used that because that was like was on top of my head say that i want all the executives selected right i could i could have said where department equals executive executive i got a spell executive correctly fun thing i didn't learn about business until i was in business school i'm bad at spelling anyway so there you go those are the four people in our company that are marked as executive in my fake list of data filter employees by department so whatever filter criteria you want okay so that's that's the basics that's that's pretty straightforward but that's the big hump that a lot of people get over you want to make this more complicated of course you do so remember that you know you could have this uh default right right this forming be whatever it is so for example we could have done something like maybe we have a so drop down in here just for giggles i don't know why i'm doing this but i'm getting inspired i'm gonna say hey drop down using poise and so then now what i could do is be like all right and then show me first name again because i don't like not seeing first name there you go and so what i might do no you know what instead of first name i'm going to say i want to do a distinct give me the list of departments right that was what we're just playing with let's let's stay on the story shane there you go so this should show us the distinct to sort departments very fun go back over here and so set the default selected to be filter department equals drop down one dot selected dot result so then now if we change this from executive to it we should see i think daniel and chewie yeah because they're both in i.t janitorial i think that's jeff and fausto there you go so right i realize you're not ever going to build the app this way but what i want you to understand what i want you to take out this is a small lesson that how this filter happens doesn't matter because you guys are all of a sudden thinking what if i have it stored in a variable or whatever i have somewhere else it doesn't matter okay so that's our first one ready to make it harder let's make it harder let's do another drop down or another combo box let's pull it down here and so sometimes you guys for whatever reason you might have the data hard-coded right so you're gonna be like hey i want a dynamic table of yes no maybe i don't know why you wanted that in a combo box but you did and so when you put this in your combo box you're like all right cool cool that that works yay i want to set default selected items here so you guys immediately roll back to your old style okay i just want to do yes right this doesn't work default no never never go away default selected items all right well now let's put a yes there i want default yes no so then you're like but shane i how do i get a record i don't understand fair so what you can do there's a few different ways to do this one is but at the end of the day this has to be a record that matches so you could do something like this you could build a record on the fly called um was this this is wait now this is value value equals yes and that's going to work and you're like wait shane how does that work why does that work okay what do we do whenever we question these things we go back to our items property oh that is not the items property and this is the items property and so what i want you to do is i want you to select all this and so powerapps says that's the table you knew that expand it that built us a single column table and the column name was value so that means that this record is value colon yes value colon no value colon maybe so that is why because i knew my shortcut syntax i was able to craft my own record here to do it all right ready to see a really cool trick right you guys are probably i'm probably losing some of you i apologize but you need to start wrapping your heads around this that's why i'm showing it to you okay so what if i wanted to do yes and no well you're like well you know can i do like an or in there or something no no this is what the records look like so i need two of these records so you're like all right well then let's just do something like oh let's do an and here i don't know i don't know what kind of crazy ideas you guys have in your head this isn't going to work so we do something like that right powerapps is like i don't know what you've done okay if you need two records what do you call that you call that a table so we need to use the table function to make this so what we're gonna do is we'll go back to the front we're gonna say hey table do something like this yes and no are selected what what now if you're really tricky right you're like well shane did i have to do that nope you know what you could have done yes no oh square square right table two columns records match power out or combo box is happy so i show you a couple different ways to think about that one because i think that's one of the important lessons to start to take out of this especially for people that know lots about powerapps is you got to be able to understand when you see these things and think a little bit deeper okay so the next little one here i know that this is gonna be a little bit longer of a cutie than i usually like to do but i'm gonna go over here i'm gonna make a variable and say set bar defaults so say that you're getting the value out of a string right so maybe you've got this string yes comma maybe and you're like hey that's what i stored because that's what they chose last time i want to have the combo box to default to that how do i do that fair enough well let's set the variable because you might be getting this from something like parent.default or from gallery.selected right i don't know where you're getting it from but that is now the value you've got you got yes and maybe you want to set this thing to default to that so you could do something like this you could say split var defaults and split it on the comma that re creates a table called result with yes and maybe result yes and result maybe doesn't equal is not the same as value yes and value maybe so that doesn't actually get us any defaults right when you get it wrong you just get nothing matched okay ready now we're going to say rename columns rename the result column to value because that's what that thing wants boom is that neat so once again maybe not something you completely are going to do but it gets your head wrapped around hey i've got the data shaped this way i got it from a weird place and it looks funny how do i get it back to a place that it might work that could work you also could have taken all this you could put it into collection that would work you could put it back into a table like we talked about there's a lot going on here but i just want you to take that you can do this the last one i'll show you because this was one that just kind of prompted me to make this video um so the customer uh she had returned her data in a different way i don't remember the exact scenario okay i took like seven support calls that day but basically we had to do an in right so she had like a string of data and she wanted to match all the records where they were in so she ended up doing something like this she said um filter and then she went back to her items property right because this is where her this is the table that she wanted to filter so she said hey filter that table and default selected items she put that right there and then she said value right so value is the column in there so check to see if the value is in var defaults and so this operator gave her a way to right so that way she didn't have to split or any of that she just had that string remember var defaults is a yes column maybe so we just look to see is any of the records is the yes record in there it is so it shows up is there no record in there it's not it shows up is the maybe record in there it is and it showed up so another way to think about this okay so i realize there's a lot of chaos all at once i think most of you just wanted the first five minutes of this you probably stopped watching already but i wanted to kind of go that extra mile because i get a lot of questions about setting default selected values at the end of the day it's all about you know making sure that you're returning a record from the items property okay um if you have any questions comments leave them below if you have other ideas other weird things other scenarios you want to see me cover like this i'd be happy to right these these are the videos that's why i made the whole cutie idea right i want to make these quick little videos that just let me show something that seems completely arbitrary but by putting in your utility belt you're going to thank me later um remember hit the subscribe button right now i feel like you guys been slacking lately on subscribing so hit the subscribe button for me if you don't mind and with all that i think i'm just gonna say thanks and have a great day before you go be sure to click on the subscribe button over here so that way you'll be notified when new videos come out if you need any help or you want to work together whether your problem is big or small check us out at powerapps911 we'd do it all i rhymed or if you're looking for more formal training offerings we have those linked up here somewhere so check them out thanks and have a great day
Info
Channel: Shane Young
Views: 107,682
Rating: undefined out of 5
Keywords: Shane Young, powerapps911, PowerApps, Power Apps, powerapps combobox, powerapps combobox sharepoint list, powerapps combobox defaultselecteditems, powerapps combobox default value, powerapps combobox items, powerapps combobox defaultselecteditems not working, power apps combo box, powerapps table function, powerapps split string, powerapps split string into collection, powerapps in operator, powerapps combo box, learn powerapps
Id: AXAbmy9zYTU
Channel Id: undefined
Length: 14min 25sec (865 seconds)
Published: Thu Mar 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.