Mastering User-Defined Functions in Power Apps: A Comprehensive Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
guys userdefined functions is something that uh has been released to us um I just saw this yesterday from a post from uh Matthew devani uh where he talked about userdefined functions and what we're going to need to do is use the very latest version now you know we've got named formulas we've had name formulas for a while but now we can create our own userdefined functions how excited are you Kurt about this or or like how does that change anything as you're developing apps is this a big deal or it changes everything you know I I I don't even know where to start with that but I I guess my whole view of power apps you know we talked about this when they came up with the name formulas that it was a good try but it wasn't even close to userdefined functions yet but it was a step in the right direction and we thought that that was that meant that's what's coming next and guess what here it is right so we have parameterized user Define functions and I always thought uh power apps you know when I when you first introduced me to it I thought it was a toy language I thought it was a joke and I was having a very hard time um accepting it and I started liking it better but I always felt like for it to be a real language um user defined functions have to be there and it's here now so I I kind of feel like back in the days with Visual Basic when you had 3.0 we thought Visual Basic was a toy language and then when it came out 4.0 it was it was something that was beautiful and and I really feel like this is uh this is the equivalent of Visual Basic 4.0 now it power apps is on its way up man yeah guys if you have any background whatsoever in software development or coding you've always had a a you know some way to create a function or a sub routine or something like this uh this is like a a this is huge guys this is really big deal so yeah we're doing real programming now yeah so so Kurt I I would love for you to just throw out some idea now we're gonna go run through uh you know a sample here uh but just like just thr ideas like I um I've been using powerups so long I if I guess if there's something that needs to run several times in your application instead of having that block of code in five times in your application you define it once and then you call it right right so that's a whole I think I I think what we should do is let's get let's get your let's get this thing set up so that it can receive userdefined functions let's start there and then I think we should talk about what is userdefined function and then we talk about why do we even put them in there why why why do we care you know and then maybe we could come up with some really cool ideas to make a userdefined function so it'll work you know what do you think absolutely and remember people pay big money for this oh that's crazy that's crazy this way my life's gonna be when you're teaching me at the community college I you would say that and that meant it was going to be on the exam and also people pay big money for this out in the real world yeah this is like a this is a game changer right but you you know you got to do a couple of uh Hoops you gotta jump through a couple of Hoops here to make sure that you can even see these users defined functions uh some of the some of the people that are watching this right now they're probably over there looking oh how do I get this and then they can't even figure it out so why don't you show them how to do it Darren yeah very good so um the first thing that you want to do I'm G to back completely out I started a new project I've already got some measles here um great new project go into settings and you will go down to support you want to make sure that you I mean at least this this week that you're using the absolute latest version so yesterday Kurt when we were looking at this I believe the last two digits were 10 if I if I'm not mistaken oh wow so they've already created a new version and um I would have to say so this is right now it's an experimental feature and it does feel like an experimental feature um well the problem that I'm having right now Kurt and maybe you've experienced I'm sure you've been playing around with this so I'll select the very latest version so guys the latest version um now I do have the version where it was actually um released in okay so I'm gonna I'm gonna put that on the screen here so you guys can see it um and I want to put on the screen because you guys people may uh not be watching this live here right so I'm going to show this on the screen this comment okay so that's what it was yesterday when we were playing around with it so 2413 so we've gone up four versions since yesterday yeah what does that tell you they're working on it yeah okay so my current authoring version it is that latest version okay so I'm going to hit cancel what I'm finding is as I'm working with this it will reverse to the the stable recommended version yeah and it's very frustrating have you noticed that at all yet yeah it takes it took me a couple of times to go through to make it stick you had to do it like like Twi two times so that that version number guys I have up on the screen you want to make sure right now it's the last two digits are 14 make sure it's at least that version or higher okay so I'm going to release that and I see you guys in chat thanks for joining us today guys so we'll be uh keeping an eye on that so now that I've done that you want to go to uh upcoming features okay uh as of today I could just scroll all the way down look user defined functions user defined functions udfs are named formulas with parameters for logic reuse okay so uh it may not always be an experimental so just type in functions and um that should bring it right up okay a full page refresh is needed to apply this changes now this is the point where I think it sort of like kicks me back to a previous version sometimes um now something else that you'll notice is there's another feature right that you may need to enable and that one has got the word engine in it okay new analysis engine enables new analysis engine which improve the authoring performance I don't know why you wouldn't turn that on besides the the fact that it's experimental but that feature for userdefined functions requires this feature to be turned on okay so I think we're I think we're set up so I'm going to click close yep okay I'm gonna hit save all right so over here on apps expand app just to see what yeah we just have the host there um so here's the app object and we'll go into formulas and um I should have I should have zoomed in here now Darren I got a I got a question before we go to that um sure I thought when I clicked on that maybe everybody else is thinking that too but maybe you you're not doing it so maybe maybe not you don't have to exit this program and go back in um because it's talking like you want to do a it I thought when it says you got to do a page refresh that that's what it meant that's not what it means though huh oh that that might be it um so look I'm just going to take one look at this make sure that I'm still on the version I'm expecting okay so a 1314 that looks good so you're saying a so I'm gonna back out I thought that's what it meant we had to do so I could have been wrong on that no may maybe that's the reason I was having problems with it was that I was doing that so maybe maybe that's the case um may have saved me there Kurt I still had to do it like two times even even doing that so yeah um let's see what happens now we'll once this becomes a little more stable we'll probably create a new video that will go over this more streamlined where we're not struggling with all this stuff you know go check your version real quick see make sure you're on the right one see because the last time for me it wouldn't take it until I did it twice oh there it is look at that look at that yeah so now go do it again oh my goodness and then hit the hit the c y and reload it and then go back and leave again and come back in it seemed like it kicked me out it did it did didn't it seem like it took that time doesn't it yeah that might be the page refresh right yeah so it's probably going to be okay now okay so let's go back in here and check this out come on 134 y okay now I think you're ready to go now do we have these okay user defined okay yeah make sure you check that other one too make sure that other one's on there too it's a good point 14 okay I'm GNA type in engine so again everybody you might have to go through this process two times for it to take um I don't know if it's a propagation issue or you know that you gotta wait a little longer or it just it's a bug maybe it's a bug Microsoft sorcery is what I call it Microsoft sorcery you gotta get up and you gotta Circle your chair you gotta walk around your chair three times counterclockwise and then that'll make it work okay so this is essentially what I was playing around with now that's not how you do uh name formulas I'm just going to comment this out uh Kurt you want to step me through doing a a simple simple uh userdefined function you got one in mind for me well we have we have uh we got one sitting right there let's just do um let's do a who's the man let's do a who's FX who's the man so I've got this code was meant for my button because Kurt and I we were we were playing around here I'm just going to cut that out I don't need that don't need that in the button I'm going to call it okay I want to call a function yep and give it two strings and a random number now Kurt why would we want to pass in a random number because that random number is going to determine it's G to go out there and it's going to go look and see who's better me or you and it's going to bring it back that's what's going to happen so let's go do that let's go so we're going to generate a a random number one to 100 yep that's right and then based on the number let's say if it's if it's under 50 it's you if it's over 50 it's me and if it's exactly 50 it will be ammer yep that's what we do come on let's go make it happen let's make it happen all right so how do we do this so let's go let's well first thing we're gonna create the name right FX you go ahead you know how to do this um you're not gonna you're not gonna help me out here Kurt sure I am all right so we're gonna call this okay let me go get the the name of this who's the man who's the man now I like your prefix of call that FX I like that I like that FX why because it tells you it's a userdefined function well it tells you it's a function okay but we know that it's a userdefined function right because you know you got the FX that's the formula and that's the language right that we're using FX so FX yeah yeah Power fix and something else I think is great let's say you're in a butt and you're trying to call one of these uh userdefined functions or you know you've got a a property you want to be dynamic anything that you define here in the app. formulas it's my recommendation that you always start it with a prefix like FX so I know that I've I've created something here it's defined in the formulas yeah so as you're typing in a code you hit FX hopefully you'll get like all the list of everything that you have access to in the formulas yeah so let's go ahead let's set up these parameters here so next what we're going to do now is we're g we got we got three parameters so we've got to set up these three now okay in in the call we did the call first but we'll go back to the call in a minute we know that there's three parameters so what we want to do is that I want to name these so that you can know that this is going to be any value that you put in there it's going to take it so let's create a one called any any uh any text any text or any name okay sure any name and we're g to give it a type right and that's GNA be text now what I can't remember the syntax was it um maybe it's a colon look at that it was a colon these are all the types yeah of values that you can Define as a parameter or an argument being passed in and we probably should call it any name one and any name two right okay because we can't and you probably said that because we can't have two paramet with the same name those parameters essentially become like little variables inside of our function they are variabl they are absolutely variables they actually create at this point now it doesn't it's not I don't think it's referential I think they're value variables so that just means it's going to be pointed it's going to be create a copy it's going to create a copy of that variable that you bring into it right it's a value parameter we could go down a a rabbit Trail on what you just said perhaps many people didn't didn't at that that that sentence that you said that the thing that you said out there that's a okay let me let me just say this because we are creating the parameter right so so you you saw the call and what happens is we got a we got a call out there that's going to be a person's name right it could be any text but it's gonna be a person's name in our case and so what it does is it's gonna actually take the contents of that memory location that that's sitting in and it might just be this the cpu's Reg register at that point because it could be a string literal and you're going to put that that copy of that contents into this so it makes a copy of that it doesn't so now you get you go in here and if your function somehow changes this that these values if they change any name one when it when the function's done it's going to go back to the old the old the old value because it's just a it's just a copy of it it's not it's not a reference to the location so Kurt when you taught me Visual Basic there were two different ways we could pass in a parameter by reference or by value now let's let's take it back to some other languages here tell me like uh maybe C C++ you would pass a value in or you could pass the pointer to it right y so in this case um it's passing a copy um and there's another thing called by reference which would be a pointer to it like to the memory location okay okay what are the difference between the two well if you passed it in as a as a reference that means a function could change the value that's right but if you just pass on a copy that means it's not going to change anything so just sort of that distinction guys what you get from this YouTube channel or content that me and Kurt uh provide we're teaching you coding and and programming Concepts that would apply to any language so um I I think maybe one of our accelerator students told us just this week uh they were in a I believe they're in a computer science uh degree program and uh they're taking some programming classes like I already know all this stuff CT Darren am am am is over here going very true yeah so right and that's what I was trying to say was uh just to kind of uh so that people don't get confused in that you're bringing in a value a value parameter and that's what this is at at this point I don't know if powerups is ever going to give us an opportunity to do a reference when you say a reference to a location that means it's actually bringing in the location so that that way if you make any changes in there it's gonna actually change the memory the values that are in there but when you're doing a value parameter just says hey go make a copy of that during the time that this this function is running and when it's done go back now Darren what's the whole point of writing a function what is what's what is the whole purpose of a function in its literal sense when we're talking about fundamental programming to return a value to return a value one value so we're gonna do all this stuff now that value might be null that value might be nothing but it's gonna return that you know so that's the whole point this goes way back in the days of the Greeks and the you know back with with with the with the abacuses would that be abai the Abacus this is there's nothing new Under the Sun here the know they with these mathematicians back in the old days they didn't want to have to write all this crazy stuff every time they wanted to reference it so they did they did they called it a function and and that function it says go out there and do all this crazy stuff and bring back this one value because that's all I care about so that's what that's what we're doing here in programming we're gonna go out here and do all this crazy stuff and and I got some I got some things I want to talk about with this in a little bit but I really want us to just see the like what we're doing right now an example of that but it kind of talk about it along the way here so so we are creating this function out here that goes way back to the old days and it's going to go it's the same principle we're GNA go out here we're gonna go do some stuff and then we're going to return one value and that is so important in programming so we have right now we've got so he's got any name one and any name two and this is going to go right down our parameter list and then of course you see he's got a random number he's called it random number and he's going to make that a a number right so um okay so we don't have notice that we don't have integer decimal so it's just number numbers can be all kinds of different forms but ay we're in a we're at a Power FX um world here and we got to work with their types so we have a number and let's just trust that the number can handle any type of number you know at this point you know right so now that the rest of this now the syntax I think I can't remember was there a colon here yeah yeah can you tell us what goes after this colon what is this about so now this is going to be the the the return type this is what it's going to return remember Darren said that the function the whole job of a function is to return a value so those parameters it says we're going to go do a function with all the stuff that we're bringing in with it and then we're going to return a value but we got to tell what to return so it's going to return we got to tell the type you know what is the package that we're going to be sending this value back in and we're going to send it in in this case we're going to send it in as text okay so I'm going to pick text here because what we're gonna do this function is going to determine who demand and it's going to be based on some really complicated stuff you know we're gonna go out look at all of Darren's qualities and all of Kurt's qualities and we're gonna determine who's better in the moment all right so how are we gonna figure this out Kurt should we do a switch statement or an if or a loop what should we do here to figure out who demand so I don't know what your your rules are on this but you know to me it's arbitrary but I I like the idea um of doing it in an if but you know what just for the syntax because we don't use switch very often and we might do something different down the road with this function let's try it with a switch how how would you do that with a switch Darren I'll do a switch okay which is like a complicated if statement right yeah usually like my rule is if we do more than more than uh two ifs if you gotta do two more two nessed ifs do a switch you know okay but in our case you know this is really a simple thing but you know I didn't know if you wanted to try the arcade switch way or no I think this is good because we can make this more and more complicated or you know we add all kinds of different values in here right so so we got three parameters being passed in and I want to look at this random number so that's what I'm going to look at if this random number okay I'm sorry not Darren no if it's less than 50 right okay let's um okay so for the switch you almost got have a we would compare this to some other value yeah um I'm gonna I'm gonna be honest I I I almost feel like so if if we were to do an if okay I could say if the random n well of course I got to spell if right it's a lowercase that's important so if that random number is below 100 then um you know I'm going to I'm going to return uh Kurt below 50 below 50 below 50 if you're below 50 um otherwise if it I'm just gonna actually I'm gonna take this whole line here oh I'm yeah you're my brain's not on yet Kurt okay you're doing a lot of driving stuff you're you know let me you know no I'm I'm I've got some brain fog going on maybe I need to go get my Red Bull and then if it's 50 we want it to be uh ammer that's right so um what I'm going to do here if it's over 50 then we're gonna do Darren now if it is 50 now I love the way you did that if I want to talk about this for just a second guys yeah Darren this this is proof that Darren Darren actually listened to me you know sometimes I feel like he listens to hears every third word I say but when I was when I was teaching back in I I would always make sure the biggest thing I want I hope that I can um express to you guys is that it's so important to have control over your program if I can't if I can't teach anything else is that you must have control of your program at all times and what he has right here he's got a he's got a perfect scenario where he says look if this thing is less than 50 I'm not even going G to go any F farther I'm going to hit Kurt and it's going to go out and but if it's not then I'm gonna go check and see if it's greater than 50 and if it is then I'm gonna stop else I'm gonna give it to ammer here because there's only one letter there's only one thing left and that's that right there so he has perfect control of his program not only does he have perfect control over his program but he also has control over the over the operating system the the the the the the computer the core because what he's doing is he's saying I'm not going to go out here and tax this thing I'm gonna this is as slick as you can make this you know in other words you're gonna you're trying to get this done as as clean and concise as possible so that you don't take computer time you never know you might be sharing this computer time with a whole lot of other people or a whole lot of other programs so yeah so with any code like this you create I always like to have like a little code block at the top that says hey the parameter is one um you know you you could describe the the you know the parameter and we should probably have a a third parameter here for the uh random number exactly right and uh this should be between one and 100 now could we get zero is that a possibility Kurt with the how the random function Works um could you you could we probably should do a plus one in there um or do a Roundup if you do a Roundup you won't get zero so now here here's the thing too um that's what we'll do we'll do a Roundup in that but we also should check to make sure um well there's no data entry so we know that there's if there's no data entry coming in for that third parameter we know we're okay right um we got to make sure that that the parameters coming in are going to be valid if that was a data entry the r random number is putting in a number between one and 100 so we're okay there but if it was if it was a text thing then we would have make sure that we didn't get 101 in there right or or 200 because then we would have a logic a the program would run but it would be a logic a because Darren would win every time because he's gonna get more more values and I don't like that I will have a problem with that because Kurt wants to be better than Darren sometimes we'll see what the function gives us here in a moment so John Brennan says you don't need a second if and that's actually true so this is something that I feel like maybe I got from UK Kurt something I feel is a a good programming practice you know if I have a branching or a looping construct within a branching or looping construct um I'm always going to indent you know and so I uh something that you might encounter is we could we could have done a third one here right if we say random number look at that we have that as an intellisense item here because it knows that I have a parameter variable I can work with okay if it's 50 okay then we'll do ammer right could have done that could um didn't need to though that's didn't need to no yeah I I think I kind of feel like John and maybe I'm wrong John when you were talking about that that you were like not sure where we were going with it yet in the moment um so you know I didn't know so so uh but that that third one that that third process down there yeah so um you could actually flatten this you don't have to to do this you could have done uh you know taking these out and just have parameter after parameter for the if sort of like a switch what I was thinking about doing with a switch or what you were thinking about doing with a switch um so that that is a possible and I know there some to debate that um what's better over another as far as in readability if it's something simple like this my brain coming from other programming languages see this and I'm like I know exactly what's going on if I had flattened this and not used you these nested ifs and just made them a parameter parameter parameter you know going on down with the if um I don't know it just doesn't make as much sense for me so you might have a preference one way or the other what I would recommend for for anyone is that at your organization as as if you're a freelancer working for small maybe mediumsized uh uh organizations you almost can go about things the way that you feel is the best practice but if you're an employee for a large corporation or you're a contractor working for a large corporation chances are they have their own coding guidelines for for any of the the development going on so and if they don't have one you're probably going to get some bonus points from somebody if if they if if they've got a good sense about them as far as in doing software development get some brownie points for suggesting that you create the uh the guidelines the the coding uh guidelines and standards for that organization um but this is the type of way that I I like to write my code that's the way I've been taught so I know this guy beside me here is probably gonna agree with me on this do you agree with me Kurt on on pretty much what I just described there yeah I do um up to that point of the equals 50 because to me that that's the only one that's left available so you could have that last fbn else you didn't need to do a check on that right because but um because that would be your else now now Mente up here says that nested if slow performance and is good to avoid them in power apps um i' I've not seen that literature I'd be interested in seeing that um to because that and you might be right I'm not saying that you're you're you're not but I'm just thinking in a traditional sense you're thinking about programming you're not going to go into the nested if if the first one is now maybe the interpreter's got to go in and look at the whole thing before um it just depends on how that processor looks at that but but under traditional languages traditional processing um that it's going to take that top if and it's going to say and if it's in that one it stops right there it doesn't go into the second or third if in the way Darren has that set up it won't go into the second or third So In traditional sense that would be the best and fastest way to get something done well well Kurt if I may interrupt you and sort of plug something that you say all the time uh that you apply whenever you're teaching the switch or the select case depending upon what language you're in yep what you do is let's say we've got a we've got a switch and we've got 50 options okay well what you do and what you've taught me is do an if right before it Y and make sure it it even qualifies to go into those 50 options right exactly right won't even go in there that's right yeah and and then I'm gonna add one more level to this if if anyone here is performance-minded or they they've got this big question about performance um the question is is this going to be inside of a loop if there's any inefficiency in something like this you're you're never going to notice it uh in my opinion if we're talking in a general sense okay somebody always find an exception give the exception right here you've got a loop okay maybe 2,000 you go through 2,000 items and inside these 2,000 items then you're G to call this thing every single time um any type of looping if there's any inefficiency in a loop you're going to not notice some scaling issues and and and performance issues and that's where you really need to to in my opinion my professional opinion that's where you need to focus um it for most of the time when dealing with performance focus on anything that's repeated over and over again and that could be a gallery by the way so keep that in mind yeah and now now boy I tell you what we're get we're getting into some really good stuff here uh now these are now the some of the things that I'm talking about these are fundamental philosophies that programmers have been arguing about for a thousand years okay but um here here we've got another one uh Patel I don't know how to say your first name I'm sorry um says you can avoid nested if by just using one um power apps IF function supports multiple conditions and that's right it does however that's what I was just that's what I was just saying uh to to John Brennan yeah you could definitely flatten all this but now but now here's the thing about that there's a lot of things that are supported in a lot of languages doesn't mean it's always the best you know all money is not good money right so so you gotta look at it like that way so for instance I'm gonna give you couple examples Darren just brought one up one of the big things and I used to I used to flunk students for this um if you went into a switch statement or in in other languages it might be a case statement where you have a where you have a list of items that something can be and if you go in there without making sure that those items is going to be the the item that you're looking at in that switch is going to be one of those values in other words if you don't wrap that switch around with an if if you're not darn sure that every it cannot be any other value then you're locking in because see at the end of that switch you have an else clause or in the case you have an else clause and if you have to use an else in a switch statement that's a problem that shows me that you don't have control over your program so you can use an else but that doesn't mean it's good and also and if you're looping in some languages you have a break and if you're getting a for next Loop and you use a break in a for next Loop because what's the rule of using a Forex Loop you know you got to have the loop and you know the number of times you got to use the loop but so so if you've gotta leave and well and what's the rule about that hold on the pp the PPC students know that right right that's true now what's the rule on on on looping and and procedures and functions what is it on all those things Darren what's the rule going going in and going out have have one entry point and one exit point exactly right you have one entry point and one exit point so when you enter a loop like a Forex Loop you should have one and and the only point is is when that Loop gets done that you know the number of times so if you're doing something you don't know the number of times you got to do a break in it that means you don't have control over your program that means you're lucking out of this so I I just I just I know sometimes my philosophies turn into Dogma um and that's just because I'm really strong in in in my convictions of what I'm doing but I I I I try to teach people that now obviously out there in the real world you guys do what you want to do you know I mean and it's okay but I just want to try to teach how to do how to do code where you're in really good control over it you know so so Kurt what do you think of this code I changed the code while you were talking does this look cleaner does it look more of a like is it more is it I I don't know what what are your thoughts on this so we had we had what three nested if statements and now we've just got a single IF function yeah you could you could do it that way and looks okay to me and this is go ahead I I guess you wouldn't even need oh no you got you got another one equals 50 else now so so that comma there I guess that last comma has got me bothered will do ever happen first it won't but second I wouldn't like it anyway because now you're looking into it now you got an else in there so this is this to me this is representing a switch this is representing a switch right here you know um I don't want to get uh too much into the Weeds on the on the the branching I I I did respond to what people said I flattened it uh some people like this so if you guys like it there it is is this should never happen because a number is e is always going to be less than 50 greater than 50 or 50 those only three options right so it's never going to happen here and if you want to put something in here you can say dooo stinks now if you ever see doooo stinks anywhere you know you've got a bug right I got in trouble I got in trouble working working with you Kurt I had one of our clients where we write some code for and one of the this engineering firm like you've got a variable initialized to doooo stinks is that is that standard operating procedure here and I'm like uh uh I didn't know what to say I'm like a new I'm like well I was a baby programmer you told me don't say that I was a baby programmer back then Kurt and then um yeah so I didn't know how to respond to that but uh um so yeah anyhow so let's get back to our so so let's wait before we go back to let's go review that one time because we talked about this thing we we went deep in the woods and got we digressed quite a bit into conditional branch which could have been a whole another live stream right um so so we have again this is the construct of a of a function right here so what we're doing is we've got two parameter three parameters two of them are text based one of them is a number okay and it's going to take those texts now what are you returning o You're returning so so what we need to be doing is we need to be testing so what we've got is we've got hardcoded stuff here Darren um if we were doing who's the man we would need to be and they were bringing that in they could change those names so we want to put uh uh any name one for the top if it's less than 50 yeah and any name two if it's greater than 50 Kur you're so smart God I love it when he says that he almost never says that you're you're not always right but when you're right you're really right okay and so uh who's got the power Darren who's got the power I got the power that was an odd thing for you to do right there that was so silly that's so silly okay so uh I think go ahead I and I'm going to be fine for these hardcoded values here but we definitely needed this yeah because that's the point of the function right because you're bringing in you you solve here here's the here's the philosophy on on programming right you learn to solve a problem one time and then you repeat it learn how to repeat it and what we've done is we solved the problem one time we put it in this function and now we have a repeatable problem solving machine here we have a function and this is going to go go into what Darren calls Darren's bag of tricks later on he's going to have a function a list of functions that he can put in any program that's gonna have his tools we're gonna talk about that later anyway what you got to say Darren I I almost want you to repeat not not that necessarily the last part but the first part is that's the trick to programming it it's the total thing you create it once and then it's done you just call it you use that learn cop past things all over the place if you can you can Define them in here in functions and always use it rather than having this logic 25 times to your application and we got we're we're gonna talk a lot about that here in a little bit because I want to talk about why we make these functions and and all that but I guess I just want everybody to start this off by seeing the anatomy of a function so you're going to go into the formula section of your of your power app program and you're going to create a function name you can prefix it with FX like Darren did I think that's a great prce practice you have a parameter list and you see those lists and then you have a colon at the end of it and that is the return what's the purpose of a function what does it do Darren what's a function do a function should return a value return a values that's the big thing I want everybody to know so you're gonna return a value and that value is gonna be that text it's G to take this code that we've got in here we got this if condition right here it's G to go down this thing it's going to look at that random number and it's going to return the value that that if condition return you see that if is aun function right that if is a function and it's got parameters in there you see that you got parameters comma separated parameter list in there and so what it's going to do is that if is gonna return a function it's gonna return whatever is true in that statement right so I have a go ahead I was just gonna say just to finish that off somewhere in the deep dark recesses of Microsoft's power apps somebody wrote a program a baby program a function called if and it goes out and it does the same thing we're doing here it's going out there doing some stuff with these parameters and it's going to return a value okay go ahead Dar yeah yeah I was just saying for the return value since we have the the text here uh this is always a good idea document your code uh and and don't think of it as some for somebody else it could very well be you coming back in here six months what does this thing do string representing who and I almost I I feel bad as a whose demand I almost feel like uh who's the rock star okay maybe I want to be a country music singer everybody wants to be a ninja a pirate or a rock star Kurt and I want to know who the rock star is okay okay so Kurt I feel like what we need to do I I feel like we can come up with a some a couple of names we can throw in here but a random number um how do we come up with a random number give us a little Spiel on working with random numbers in power I I mean I don't want to spend you know half an hour on it but maybe a good five minutes of of how all this random num stuff works I do want I do want you to do something like that with this go out there and put a label out there on the screen label yeah and in the text in the text for that do the rant do a Rand function I'm G to make this nice and big so everybody can see it okay so you're telling me there's a function out here yeah that will give us a random number that's right go out there and do Rand now we talk about this ad narium in accelerator but um this is this is good stuff people pay big money for this guys so Rand you use the Rand function with empty par parentheses go ahead out there and give me okay now it's going to give you a number between zero and one that's what the Rand function is going to do a random number between zero and one and you think to yourself now this is for the people that haven't really worked with this a lot but there's not a whole lot of random numbers between zero and one is there well if you look at it at the integer level you're right zero and one that's the only get that's the only thing you get right but if you take a number between zero and one a real number well how many numbers are between zero and one with a real number Darren how many random numbers are there between zero and one if you take a real number not an level but at a real number level I guess we could have like an infinite amount couldn't we infinite man infinite right so it's a lot of numbers you can have in there so then you're GNA do some really cool stuff to make that go back so let's go back to that label there so I I am experiencing some technical difficulties right now um and I'm trying to figure this out okay I don't want to look at that I want to look at this one I think I think it's who want equals there you there I found it I was so I created a virtual machine for this because we had some fun with a virtual machine guys so awesome we did a live stream last night we should talk about it a little bit they are so oh I'm sorry D I'm talking over top of you go ahead all right so yeah you had an issue we're working with a client and you could not open a power apps project and I said well try it on a different computer try a different browser try Incognito it would not allow you to open it so if you guys have ever and I could get into it like what was going on and it's like okay we create I'm like let's create a virtual machine it's going to be up there in the cloud you just log into it with remote desktop use power apps and it should work and boy did it boy did it oh boy it's so fast it it's just so smooth you're working off a virtual machine right now right there that is right you notice the difference in how it how just the just the clickability just the the the the navigating around do you do you feel like it's just more solid yeah well I think part of the reason for that um is that I'm using Windows 10 instead of Windows 11 because I don't like Windows 11 like at all guys I I'm going to share with you something uh really profound here Microsoft I I think they great they create great operating systems windows but it's only every other okay you guys remember uh well we we had um like Windows 2000 which was like the first really good version of Windows in my opinion uh and sort of replaced NT uh and then you've got uh then you had Windows me that wasn't good but Windows XP was good what was after XP I think it was Vista Vista and then and then they created another one that was good so I think I think they've got two teams that do operating systems so so right now there's somebody creating a Windows 12 and the 13 and like maybe one team's better than the other yeah but that's that's my little Spiel on um Windows operating systems but yeah the virtual machine ended up being really fast so I cre to day I I absolutely love it and I'm thinking I'm trying to think of ways I can I I really want to use that a lot more um okay so let's get back to this Rand function because I want to I want people to understand that so your create the Rand function returns of value just like you see it's a function we're talking about functions here now this is one of that was created by the power apps people the the power apps Wizards and they they uh they built a function that returns a value between zero and one now what we can do then is we can do some some math with this so let's take that Rand and um now just double click Rand just double click Rand you see how it changes every time you double click it you see that oh wow right this is what what they call um this it's it's a non-persistent function so every time you run this it's going to be something different now but you'll notice though that it did not change the value inside of the label that is yeah isn't that interesting okay so this is why I wanted you to do this so you so that you can understand what you have to do to change the na label is you have to give it an entry point change every time so let's go um let's give it a round let's put round in front of that round ah okay round round and let's I'm sorry not round let's go round up I want to round up every time because I don't ever want it to be zero okay never want it to be zero so we gonna round up and we're going to uh take on nope not there we're gonna take times 100 Rand times 100 because it's a decimal right and we're going we're gonna round up comma zero now you're G now we want to a whole number every time W see that see how that worked right there yeah now it says 12 yeah so I select it again it's going to get me 89 then 24 now now go and click your button now let's let's put that label let's put that function let's take that function that you did that whole code highlight that code that you've got in the text let's put that into a variable and and put it on your button so I'm going [Music] to let this out I don't know what that is okay just so I'm gonna put it in here but you said put it into a variable would you like that to be a global variable or a local variable let's do a local variable because that's good programming practice right that's right and what was like the variable name to be uh L number and then um and then Clos her up okay there we go okay so uh uh there we go okay so let's go ahead and run and then in that LLC number let's put that in your code let's put that in your um your text box oh in the label in your label I say text box label there we go and let's go ahead and and run your code and click a couple times to see what we get 30 54 67 you'll notice because I put that in that text box what it did is it changed it changed the way um how do I say that it it changed the Dynamics so if you don't do anything to change see by by how do I I'm trying to learn how to figure out how to explain this when you have it just sitting in the label and you're clicking it there's no Dynamics in memory happening but when you move it into a a variable you're actually you're you're changing the Dynamics of the memory and when it does that it's actually having to address it's having to re go back and poke that memory location where that where that uh random number is being generated at and it changes it it forces a change if you don't change any Dynamics in that the random number will not change interesting it's called it's called it's called volatile uh nonvolatile uh I'm trying to remember it's an old concept it's called non-volatile memory um and that's what random does so it's not immutable right it's not immutable that's right um so we've got [Music] so AMR was talk U requesting that we show this one so so that's okay so you have this infinite number between zero and one it's going to be a decimal so we times it by 100 to make that a whole number right now now let's do something else see some people like to use Rand between but I don't like to use Rand between I like to have control over my stuff so you know that and you know what it just comes back to I don't like to use other people's functions I want to make my own that's all I find it's great because you understand it then well I I know it I I wrote of course I understand how I wrote it but you're right Darren that that's exactly right when you're learning it learn it this way and then you can go out there and do now you know how Rand between works right yeah um so so let's do one more thing let's have a random number between one and and 50 or one and three okay you going to step me through that that so by the way before we go on uh Mr or Mrs Patel says my mind is blown by the fact that there can be infinite numbers between finite bound of zero and one that's great stuff isn't it that's called a real number it's infinite it just depends on how many decimal Pointes Point points places that you want to have right how many decimals you how how what is the level of precision when you talk about Precision it means the more precise is going to be the the The Wider the decimal right so so let's so if you wanted to do a random number between one and five just go just change that round up from 100 to five oh okay three two four I like it is that cool yeah if you do the round up you'll never get zero R the ram function in its in its Purity is going to give you a number between zero and one it can be zero but will never be one okay but if you do a round up if you do a round up you will get no zero and you'll get a one interesting okay yep very interesting okay I like that okay what do we do next Kurt okay so let's go ahead and go back to our function now that we you you kind of wanted to go over the Dynamics of Rand so we did that so let's go back to our function now let me ask a question would it be a good idea to take this right here and create a function out of that could we do that well why not why not we can call the function like uh random number Round Up R yeah you go make your own Ram between call it call it scooters Ram between scooter I don't know who scooter is I don't know who scooter is all right here's our code here something hold on I gotta tell people what scooter is so so there was a long time ago he used to be a student in one of my classes and I'd have I don't know 30 people in the class and um and and uh you know we're I'm I'm doing a Spiel I'm out here doing that like I do and Darren was a very active student he was really active and so he would raise his hand and he would ask me a question about how how this thing worked which meant like just like we did here I'm trying to show how to do a function and and Darren says no no no wait a minute we gotta we gotta show what this Rand does you know so so what he would do is he would ask me hey Kurt what does Rand do he raised his hand what does Rand do get me back for all the times I interrupted you yeah yeah that's right and so so so I'd say okay well scooter so you know because he had a good point he was just a real he wanted to learn this stuff man he was soaking this stuff up like a sponge and he didn't want me to Mi he didn't want to miss anything so I went back and I said well scooter because you know and it's fun to pick on people you know I like to pick on some people here and there not not to hurt them not ever to hurt them or you know but you know it's all it's all in fun it's all in just it makes the it's programming man programming is pretty dry so you got to have some fun right so I'm up there and I said well scooter and then you know it just it just made it fun you know what I mean um and of course I'm sure he did he's like scooter what's this scooter but it was good stuff man I Y so I still once in a while when he does something really good I call him scooter still that's funny all right what do we do from here Kurt got okay so uh let's go back and do our function let's go back through our function okay the function call we've got that done FX rockar so now we're ready to go to our call we we've defined our function what our baby program is going to do this is what called it's called a baby program it's just a little program just does a few things now we're going to go and do our call so go back to your formulas uh section okay you want me to go back in there okay oh oh I'm sorry I'm sorry you got to do the call I okay I'm lost there don't dar's Gonna Leave This live stream just he's gonna need a drink or something by the time he's done with this okay so so let's go ahead and change that text label okay to uh let's let's call that LLC Rockstar that that number up there that LLC see how you got LLC number up there yeah you know what I'm gonna I sort of like what we've done so I'm gonna create if it's okay with you I'm gonna create two of these sure and then um so we'll still have do to because we can make the uh the file available for everybody and they might want it okay so here uh not for the on select but for the text you want the text now do we do we want a call the function with this like a button or do we want to call it here no let's or you in a button yep every time we click that button it's gonna go find out who's the Rockstar so rockar boom start no star and okay and so now we're gonna go over and we're gonna say in that button yep and and it's going to equal uh FX okay and then you gotta put let's put look at that look at a't that cool look at it CTT the first time I've seen it you know what I say when I see something like this would you just look at it were you just look at it now I like the way you put your literals in there see this is how he codes so that way he doesn't forget anything right before he does anything he just says and puts these strings in there I like it so I'll put Darren and then Kurt and then Rockstar all right and let's see what happens folks let's see what happens here we go oh it's Darren Darren's the rock star let's try it again uh oh what did you do Darren what did you do Darren cannot be converted to a number what in the heck just happened there so let's go see what's in Rockstar an air an air is in rock star so okay so it's in our formula then wow who's the Rockstar we got oh you know what I meant to do was this random number that's what I meant to do and actually you've got it no nope nope you gotta actually put the whole function in there bud put that whole line of code in there that go that generated that one to five the Roundup well so uh what I was thinking was over here we generate a number yes right yeah so we got one to 100 right and then over here we'll always know what what number was used to to pass in oh oh I see what you did okay okay I like it I didn't see I mean as you can see Darren is the rock star yeah you can see it because I can just run it I can call it over and over it's telling me Darren every time I love it yeah because you're not you're not changing the number over there bud so you're like I said put that put that random number stuff over here play right Darren I think I think ammer is the new and improved scooter do you see what he said over here can we reference the number in the tax box so so what we could do that's what he did well so a text so um maybe what he means like for what I'm thinking is we might want to have um like who you want to ask about okay so for here we'll say um okay okay no he's asking can we reference the number in the text from the text box the number the number okay so you're saying he wants a number here and refer to it I think he's can you uh I think he's talking about the number that he's got over there that where that number five is at which is what you're doing yeah it could be a text box absolutely in fact I could say Lo number says yes that's that's what he did LLC number is the same thing that and then I mean they could edit it right and then we could say txt random number right um but we're not putting a random number in that function right there so in so we could use this random number here in the is selected if I can get it to open up on select where is my on select here we go so what you're saying is instead of of doing that we could use the um the text property of this but we probably need to turn it back into a number because anything inside of a text box is going to be a string that's right in fact why don't you just try it without it once and see what it does do it Kurt let's do it okay so I'm I'm going to make sure so I'm expecting Kurt to show up so we're creating our own little test to test our function right always Kurt now put 50 in there 50 oh it's okay so now put now put ll in there o LL yep and and hit who's the Rockstar oh can't do it so you got to have a value in there man well I've got a I've got a perfect fix for that we'll just click on this text box make sure just a number but but here's the thing it's not a random number because the random number already ran so you've got to put the random number formula in the parameter because the rules of the game say it must be a random number I'm I I I got this little Curt on my shoulder it's like Darren do you I gotta name my controls right right I'm referring to an in code and I don't want anything love would you teach me Kur you taught me not to use any static values didn't you that's exactly right make it Dynamic but it's okay to use the static values when you're learning when you're trying to solve the problem but we've learned how to solve the problem so now we're learning how to repeat it that's what we're doing now and this is how you repeat the the the solution every time no matter what except no I don't like it I don't like it like it no I want a random number put in I want that function taken out of that Generate random number and put into your parameter okay you want me to go on this button or this label I want you to go to to that Generate random number over there and I want you to take this on select and I want that code this code yep okay and put it over here so it's always gonna be in that parameter yep right there okay exactly do this I'm gonna comment that out now notice now notice guys that this is he didn't put a literal number in there he didn't put the a value in there he put a function in there so you can have just like just like in all the power apps functions you can have nested functions right so now every time you click that thing let's see what it does okay let's do it yeah I'm gonna type in here Darren [Music] Kurt look at there now if we had a counter you could you could do something like that too you could put in a collection and you could you could uh in fact let's just do let's just do a uh a function inside of that function that doesn't count right all right a function within the function do that do we want to do that no well because then what we could do is we could I gotta think about that a little bit you could you'd be return a record then well so yesterday we did something did you like what we did yesterday we were working on a SAR type of uh example I I was just thinking about how to do that within a function though um but we could create a function that goes out there and finds out who is the real man who is the real Rock Star by how many times who who's got the most you know all right all right let's let's do this here so um I'm going to do a collect I'm going to create a collection okay Patel says what will it take for the function to display dooo stinks you can't that's that that's the point so how many laks does it take to get to the center of a lollipop a Tootsie Roll a Tootsie Roll Lollipop Lollipop now now you know okay so this doooo stinks I think we need to talk about this a little bit guys so we're gonna talk about this probably in another place but when we're talking about variables and we're talking about initializing so think about you're sometimes you're writing an app that's got maybe hundreds of thousands of lines of code if you're doing something that's really really big and you've got a lot of variables sitting out there so when you're initializing things I I like to initialize my values to certain certain numbers that probably cannot be used in in that won't make sense and one of my favorite values isga 57 for my numbers if I have a number out there that's that's going to be generated by some thing that I need to be done I'll I'll initialize that value to 57 that tells me two things first of all thega 57 is my it's my signature in fact Darren probably knew that and he would if he saw negative 57 in the code he'd say well Kurt wrote this code and mine is Doo stinks his is doooo stinks and and and why that's important is because if you're looking at 100,000 lines of code and somebody's calling you on a support and says you know I get this number it's just Nega 57 it doesn't make any sense it's supposed to be a dollar amount I'm supposed to have a dollar amount it says negative 57 I know right away that that variable didn't get didn't get uh used correctly or assigned correctly and I also know that this was me that did it it's my code it was my code so that's that's good stuff to remember I I don't know I think it's these are little um what I call Pro tips because sometimes I come from the the the the Dark Ages when programmers had to fly over the seas to go to another country to fix the code that they worked on so you might be out there in the middle of of this thing um and live with live data and you're going what I gotta debug this code oh my God oh my God so then so then you're out there working on so these little tricks right there help you they're shortcuts and debugging you know anyway I think doooo stinks is better well D you might you might actually have a negative 57 somewhere it you're well it that's right I mean obviously you got to think about can this ever be NE 57 be a valid value doooo stinks is a great uh a great thing for um text you know for a text I think it is um is it appropriate maybe not but it sure will hey it sure will make people call you hey this program it says doooo stinks for the name somebody my name there's nobody's names doooo stinks I see minty here minty I've been missing you man at the at the um the the group meetings throughout the week hopefully we'll we'll see this next week and then um so AAA says triaa oh he works for the insurance company or is the insurance company Triple A hi guys came here um so this is a great question while talking about this um and I just found out about this yesterday that it was actually going to be released so I've been playing with a little bit I haven't done this yet which is having unlimited parameters well we already saw an example of this using the IF function you just keep on giving it parameters almost like a a nested if you know um as soon as I find out how to do that here uh if it if it is possible hopefully they they will because we we have functions like if somay it will be yeah we'll we'll cover it here as soon as I I find out how to do that well I'm sure I'm sure that this is still a a a baby in the process for for Microsoft right now they're still they're still probably fine-tuning this thing they've probably been working on this for a year and they've got it to a point where it's stable enough to be able to throw out to us and um I'm sure they're going to be adding things to it you know so Triple A uh mentions about the the version and that's right so that goes to show you right there that Microsoft Kurt just said it's you know it's just like a baby feature that's going to get developed here it's experimental so yeah um from yesterday to today it's gone up four versions they've been working like mad their hair's on fire this is funny if I saw dooo stinks the program I'd call cyber security okay so I've got a new one for you and the string is Doo stinks but don't tell the cyber security because they don't because it's a secret or because they don't they don't agree cyber security won't agree with this statement but doooo stinks so then people will call up and they'll like uh it's sort of like saying um making your Wi-Fi password you got to buy you have to buy something right so somebody comes to your establishment your business they come in and they free Wi-Fi and they're like hey what's the password you have to buy something oh okay well I'll buy this pack of gum and these Skittles um so what's the Wi-Fi password you have to buy something oh okay well I'll buy this and this and then about the third time maybe they're like how many things I have to buy you don't have to buy anything but the password is you got to buy [Laughter] something good stuff how all right I I digress digress he does um there I mean you could put it in like You' got there where you got a collection I like what you did there because you're thinking ah let's just put other stuff in there you could just make a one one one value collection right where you could just it would just have value in it but um let's do it Kurt isn't this what you were hinting at with the uh you know with the thing well actually I was thinking we were just going to make it very you can do it this way to show your collection but you don't have to show your collection you could just have a collection sitting out there in memory and you would just have a count a record a uh you would do a record count for the two parameters and determine which one's the most or you could do a sort on the on the the number so I'm trying to get to my collection that I created here so just to show you guys the code of what I just did there I did a collect call responses and I'm so I'm creating a collection of Records or rows who won and what was the date time stamp okay so I'm going to go down to this Gallery give it that collection name oh look Kurt Darren where did you do that at what code were you doing that at I'm sorry Darren it was while you're talking I okay okay so you got um so now every time you click on the button is it going to be collecting it's going to add to that okay I see now is it gonna be able are you gonna label the the current one the one that won that moment because that that's where we started this off so um yeah it it calls the function puts it into this field and I've got another field for when it was done and I put that each individual item into this collection here as they click on that button so if you look at this I'm going to close this up a little bit and we we'll double click on this and we'll look at what we have who won Kurt Darren the timestamp okay like that right but now what what I was asking was in that label where we had the original call at if you could go to the label um when we said who's the Rockstar version one okay you got you got it version one version two so it's not going to go and update that label with the current winner every time what what label do you want to update or do you well that's the one that we we started this off we were updating a label if you go back to your screen you got a lab you've got a label who won right yes if I click on one it puts it right here and that's the point so now in the in in this other version you're not gonna update that label every time right is that what you're saying probably should yeah that was what I was trying to get at sometimes sometimes you gotta learn how to speak Chinese or something with me because I I I don't got there's a whole language Kurt you gotta speak Kurt uh and and sometimes guys sometimes we Jive and sometimes we're like babbling idiots I feel like I've still got brain fog we should do this at 10 o'clock at night not 10 o'clock in the morning but nobody show we can ask one of the one hey Triple A asked a good question we're all good questions guys but can you pass object or collection table to user Define functions I believe we can we haven't tried it yet maybe we shall but um it it's got a untyped object don't they have that in there I thought um give me one second I I my brain's processing one thing sure um so I want to reference my collection and I want to look at the last the last one that was generated there you go there you go dot who won who won that's what you wanted right that's what I wanted so I keep clicking on this boom Kurt Kurt wow you're winning a lot man oh there's Darren well we have to have a number now we have to have a number sitting out there we have to have a number yeah we got it the whole purpose of this see see this is this is where Darren me get go so I ask a question and Darren goes off and does a whole big old thing and all I wanted was just a number I just wanted a number my coffee hasn't kicked in yet man I need another cup no you does no what it is you take my idea and you just make it go wild and it's like no I just wanted a little thing here so so we I just wanted a simple function out there I want a simple function now that you've got this collection we can do it a simple function to determine who's got the most in the collection who's got the power that's what you want to fure out who got the power that's what we want who's got the power that's right Darren um and I can do a wrap count of too so we can see more at once I'm going to save it okay now that I've done that now my brain can process something else what do you want do now we need two we need two functions written one function that will go out and and see who's got the most and then we need another function to return how many's in there how many items are in there we've already got we've already got that with the cat rows of the collection yeah but but this whole video is about creating these find functions so let's do this Kurt uh I'm gonna zoom out a little bit so I I got some more space to to look and dipe here now that's another question oh ammer in the private chat just said something about how much did they score each time so well I mean it's not really what the score was but what was that value we should be recording what that value was each time too right so we should do that in the collection okay so the value of what the value of that random number okay um can we hold off on that for now or do we need to do that now no we don't let's do it because I just want to do one thing at a time otherwise I I I'm gonna get all my brain will get it's not easy to mess my brain up but not only that not only that but you got to do something kind of special because if you call it again you're going to get a different number so go ahead okay so um we are finding out who's won or what is it that you want to do we want to know who's won the most I want I want a function that goes out and tells me who won the most who ultimately won okay so we need an opening and closing parenthesis do we need a pass any parameters in um I well I'm sitting here thinking I'm still kind of hung up on the on the uh the name who ultimately won maybe we would want to call it who won the so we we might have a function there could be several functions that are tied to this thing right so um maybe we need to have a most function and a least function um and because you could have more than one person in there um you could have an average function there's so many things we could put but for right now I just want let just keep it simple right so who won the most um and this is gonna be and so we don't really need a parameter nope I don't think we need a parameter okay because we're going to hard Code PO now if we wanted to to change the data source we would need a parameter to pass in the data source but since we're just going to go ahead and look at that one data source we don't need a parameter and right here it's going to be a text okay so we got that and we need an equal sign there right and that is pretty and we need a we need a semicolon there too uh now what is it complaining about uh the formula contains semicolon where print close is expected okay um well that's interesting I think we actually need to uh put some code in here I think is what's going on yeah don't you don't even necessarily need the parentheses on those I don't think right but I guess it doesn't hurt um so we need to do an if statement let's see uh we need to do us if right now we're just we've got two things so let's sort well how how do you want to do that I can see doing this in a couple of ways there we could we could actually create a collection with the the the the amounts with the name and the amounts um um okay so we um what I want to do is um this is what I want to do I got it now oh you got it what what do you want to do got it what I want to do okay so let's let's we can make that determination on our own so what we'll do is we'll do how many for each one so like like you you give it a name you give it the person's name goes out there and says how how many did did that person win so let's say we give the parameter of Kurt and it we'll go out through and do account rows with a filter of Kurt okay return that number and then and we could put that in a text box and then we could have another text box called Darren and we could pass that as a parameter okay person Yep this is feeling better man this this feels better it feels better yeah the other one could have been a little bit stronger I mean we could we could add on to these I I see a lot of of um chat chats in the private chat and the external chat so we can do all kinds of things um so we're going to pass in the person here so let's do a filter thas Thomas Thomas Hendrick says it should be URS ultimate rockar that be the name right I love it Thomas good stuff uh filter call responses um yeah and text uh what what you call it name or it's called oh who won okay so we're gonna say who won in there isn't this fun guys I just love this we're sitting here we got a good turnout so this is a huge feature um who one equals person I love it I love it look at that you gotta do a cat roll in front of that right well you got a spell filter right and then yes yeah count these things cannot be compared um and that's because power apps is confused once I put a semicolon in there now it's going to work okay now the the question the the statement that you made is uh or maybe the question that you post is do we really need those parentheses that as a developer I always like to see the beginning and the end of my function so I just Pro that you don't have to so we could maybe make this more simple you know I like to see where it begins and ends but whatever nice if we needed to put some kind of curly braces in there or something huh or beginning and end like in Pascal yeah there there you have it okay so that should work now that's so we put that in a text Bo a label out there we'll call that uh call that Curts wins yeah okay so FX wins look at that we we passing the the person okay so will you say text I'm gonna say txt person to yep got text look you've won seven times Kurt isn't that great look I don't know I mean I guess we we'll have to see here if it's more or less than than what I have now we need to put that now let's rearrange that so you got your two name labels up there your two text boxes put that up next to each each uh label so we can yeah I like it I like it so I'm gonna put this seven over here yeah okay I'm GNA copy and paste this I'm GNA put this one over here by Darren now you see how we did this guys this is so smooth man because we we we did all that code one time and now he can sit here and just put as many people in there as he wants oh Kurt's the ultimate Rockstar I'm gonna continue this until mine is bigger than yours look at and it's just a matter of time oh you're catching up dude you cheated you cheated I'm you're catching up oh my god look how fast he C oh he passed me Darren I have a feeling we could make a game in power apps now maybe what we could do is we could make we could get two icons and have rockets and we could have random num where'd you go you left me H Kurt has been experiencing some issues with his uh yeah oh no uh sometimes his his computer I bought I I I bought him a an alien wear so he could have a good computer and the thing crashes on him so I'm sure he'll be back in a moment or two all right so I'm gonna I'm going to take this opportunity to look at the comments here what do we have I was trying to understand some JavaScript function syntax and seeing how you write functions here it's made easy for me to understand the JS absolutely so that's what we do we're teaching software development at the same time that you're learning power apps here so that if you go and and learn anything else uh you can take these Concepts and apply it and learn other things faster or I'm a little offended well I my computer I think my computer's crashing again I I that's why told people yeah I'm like why you abandoned me I'm sorry you know I have abandonment issues right Kurt because you won it was because you won I just couldn't I couldn't handle it anymore you rage quit I was done I took my I took my toys went home so there we have it you see this comment here no let me see I got this private chat in okay I was trying to understand some JV syntax and seeing how you write functions here made it easy for me to understand the JS there we go thank you that's great so so here's the thing you had said something and and I'm glad you guys are here to watch this everybody's here to watch this because there's a lot of people out there that you know you never know we don't they don't know what the topic is here I guess you just you did display the topic before the live stream started but you you kind of need to join the live stream every day to see what's going on because we just you just never know what we're gonna start talking about here you know I mean we we started covering functions but we did a lot of stuff think about the Rand function we talked about we talked about a lot of stuff in between we talked about the if you know there's a lot of stuff that we cover when we're when we're talking about a topic so I'm really glad that and here here's here here's uh Patel's trying to figure out this JavaScript stuff and he's over here working with pars he's like bam and that's exactly the point I wanted to go to about accelerator um we teach fundamental programming it doesn't matter the language it doesn't matter the language we do focus on power apps we want that to be our genuine Focus but anyway absolutely yeah yeah so oh yeah so AMR was talking here as you Mr Rockets we can use slider bars to view who is ahead a more intuitive way okay so it's like a tug-of war in in the in the browser and then uh Thomas asked what kind of tug ofar concept with the slider okay so let's see if I can do this Kurt how let's do it do it hold on I'm gonna I'm gonna check something real quick I'll be right back because I very scared that my computer's gonna crash here so oh I'll be back yeah don't let that happen again okay so what I'm going to do is I'm going to move everything down a little bit the question is do we use the classic slider or the modern slider it should uh be able to work with either of course and I'm going see zero to 100 so the amount of times that will go I'm going to click on it a few more times and then this dot should move around so wow I've got I've got a I got a math problem here guys Kurt loves these math problems okay so I'm going to take these two numbers and and so excuse me as as I gotta think I gotta think through this we got two numbers and I'm going to click on this button a hundred times so if I 1 50 and 150 it should be right in the middle um but I want it to move as we go so let's say I won 25 he won 25 that should still be right in the middle okay so what I want to do is I'm going to take the two [Music] numbers G put a label here so I've got this label here. text but I want to do a value around it okay and I want to add this one how's your computer doing I can't hear you I don't hear you now yeah so you might need to um there's a sprocket Kurt for settings if you go into settings um you'll see General video and audio you click on audio you can pick a different microphone I don't know if that that's what's what's going on but you can uh change the microphone that way so I'm going to grab the uh this label here okay so I'm GNA add those two together and it's 92 then I'm G to divide those in two is that what I should do guys okay no that's not right I'm going to make that multiply that by 100 yeah that's not right um I don't know that I want to add those values together yeah maybe the uh maybe it's not a good idea to go down this this math uh thing here this is a cool little puzzle sometimes it takes me and I don't want to sit here for 10 minutes trying to figure it out uh Kurt might be able to figure out as soon as he comes on and uh maybe we'll look at that but but the idea guys that we'll eventually get hopefully be before the live stream's over so based on these two values out of like a 100 like 100% like where where does it fall so in this case um I'll I'll be I'll be sitting here in silence too long to make this interesting but um I think this is really cool what we've done so we've got a whole log of what's been going on here okay and we've got counts we know how to create a function so I'm going to click on app formulas we know how to create userdefined for formulas uh are user to Define functions a lot of times is what they're called in in uh other languages so that's um so I'm going to go I'm going to go into the cont the uh comment section and look um okay so here's a here's a good question model driven applications when are you planning to bring some fun with model driven apps um I don't um I don't enjoy working work with model driven apps so that's why I don't talk about them very much um but that's something that maybe we we should do uh talk about model driven so it's very easy to create like boiler plate uh type of of applications uh and screens uh based on your model you know your database model that you create in data verse so um yeah we do plan on eventually uh covering some of that now you can embed canvas power apps in model driven apps so if you want to have something like this in your model driven apps you can't embed it that's nice um oh so Mark says we could have a slider for each person oh that's sort of cool that that would make it a lot yeah that would make it a lot more interesting so Kurt it looks like Kurt's trying to get on um and and by the way Kurt if you can hear me I cannot hear you or see you now I've got a black rectangle there you are say something you're [Laughter] muted so we don't hear you by the way um I'm gonna continue to move this down so what I'm GNA do move this down a little bit okay and I'm going to create a slider for me and slider for Kurt okay uh so Darren will be I'll take this label here okay so this will be person one okay dot text but we want to take the value of that okay now What's the total what is the max well how many times has have been called okay so we could create yet another userdefined function okay FX total tries and this is going to be a number okay so we'll do this right here we'll say count rows and we won't pass anything in okay so use that I don't have any don't have errors anywhere else that's good so for the max instead of it being 100 it'll just be total tries now we'll need to have parentheses in there and look it says 47 there's been 47 tries say something can you hear me now oh yeah now sh okay what happened what was that about I don't no I don't know this machine just just went crazy on me um anyway I'm sorry boy looks like I missed a lot too yeah I'm like look I'm you guys I don't know how much fun you're having but I'm having more fun today than I've been having on these live streams ever this I'm having a blast here this is this stuff I just love this stuff absolutely this is really fun it is there's so much stuff now that you guys we are power apps is get is is is growing it's growing it's a real programming language now this is exciting guys I can tell there's some excitement just based on the the turnout for this live stream sot I created yet another userdefined function like total tries okay now we could have just said count rows everywhere but that's one way we could do it total tries total tries on the Max and then I'm going to take this into default so wouldn't it be cool to invert the number on just use one slider and invert the number if it's less it like like if the left side is stronger than the right side then you would invert the numbers so that they look like the slider is winning on this side you know uh let me finish this one thing and then then uh we've got that okay so somebody says I I saw so Mark says I I saw two sliders one for each player so as I click on this you see how they that's kind of cool Isn't that cool it is cool okay now what did you just say what did you just suggest let's let's let's think about now I've got to think about this because I haven't done this since maybe my sophomore year in high school but um so this is when you had all the problems I was thinking of like a tug-of-war thing we have one slider yeah person person one is on the left side person two is on the right right uh somebody said tug of war and it just made sense but I was having a hard time with the math so is this what you're talking about you see I've got a little lab up here and I'm trying to create a number within this thing yep and it's going to go similar remember the time when you did that in accelerator programing you were showing people how to do we were doing uh I think we might have been doing sliders actually a gallery height but we used a slider to make it right right and you had to make the top be the bottom remember and and it's gonna be the same principle I think that you did there I just gota remember how you did that and how how so it's it's it's gonna it's always simple when you figure it out the first time so oh yeah so we want to invert it so let's say if if if 63 if if 63 we want that to be so many far uh so much distance from the the max right so that's that's what is that 37 that's 37 points from the max if you went to 100 and 60 if now if Kurt had 63 or the left side was 63 we would want that to be 37 points from the minimum right so we would want that to be showing that so whatever side's better we would want to show so if the left side is going to be it's GNA we're going to be offset from the minimum right side it's gonna be offset from the maximum yeah what's that tell us so I was thinking like for this slider it would be zero to 100 yep so we take these values and figure out the the difference or something where should this little circle be within this SL are based on zero to 100 right exactly right and that's what I'm I'm trying to say in that is that so we've got two sides here you got a left side and a right side you got Darren and Kurt sitting here Darren's on the left Kurt's on the right so two numbers 63 and 60 the one that's the one that's going to be determined the highest number is going to be the side that we work from left or right which would be plus or minus in this case right 50 is right in the middle so we'll need to know that that 50 is right in the middle so if we both if I clicked on it three uh four times I'd have two wins you'd have two wins so on a scale from zero to 100 where in that well that would be right at 50 because I've got two wins you got two wins yeah you're going you're going down a different Road I like your road I like your road I like so it's like a in algebra like you have a ratio right y um and I'm looking for something to sort of draw I sort of want to draw this on the screen I can't be doing on a piece of paper here I need to we gota plus or minus the access that's what that's all the thing we got to figure out on the left side so in a ratio let's say um well one to 100 we're figuring this out in the middle of a live stream this is equals I know and I was trying to do it while you're having all your problems and I'm like guys you don't want to see me just sit here thinking about this but now that you're on here it makes the makes the process a little more interesting you know okay okay but you know how in algebra you've got an you know you've got a a a fraction right one out of a 100 and then over here on the side you've got some unknown value right so uh um we'll say times clicked we will know that number so what I want to know is X now how do we how do we do this in algebra so we've got one I got think about this one oh my goodness and I'm doing this notepad that's great so come on guys help us out here x let's go math and then down here I've got times clicked and we will know that okay so I'm going to do something like this okay so this is our algebra problem now how do you how do you solve for x okay well you take one times times clicked yeah and then okay this is supposed to be a line a division line um that okay so and and you go do crisscross pattern right one time and then then we have x times 100 I'm still stuck on this X over times click are you sure that's what we're wanting pretty sure okay I'm gonna go along with it you I think so all right let's say we do the times clicked if I can get the my cursor down here let's just say say it's three okay so 1 time 3 is three okay and then what is um my brain isn't working man um um I I I'm just gonna have CAD gbt do it I hey you know math class when I was a kid you're never no you need to learn this stuff for real because you're never going to have a calculator sitting uh at at at your desk uh you you never walk around with a calculator in your pocket all the time but yet we have smartphones that do have that um so I'm gonna I'm gonna tell chat gbt here to solve for x I like I I just want to know how you're gonna tell Chad gbt to do this that's that's that's going to be interesting in itself or I could just tell what I'm trying to do and it'll probably just tell me okay y so I've got three divided by x00 but I'm sure I'm not thinking about it right I something seems wrong rearrange the equation 3x wow look at it they go 3 equal 100 3 over 100 to do this in a ratio way let's see if it helps me out a little bit um yeah that's what I'm trying to do Chad is I see this now man look at this thing go so guys if you like solving problems like this you love you you'll love coding I I sort to like it's a challenge right golly yeah so it multiplies you know thing and then it has this thing here okay now let's go I don't know if I'm thinking about this right I was my my Approach I thought was going to be easier but you just had to figure out which side to go the negative way on it so you got okay let's let's do your way first and then since you have more of a an idea where you're going maybe maybe I do I'm not sure we might end up in the same stuck in the same spot um I'm looking at you got two sides you got a zero side and a 100 side you've got two sides um you you got you got a left side and a right right side the left side is going to be the zero side the right side is going to be the the the 100 side if you look at your code right there 63 or at the numbers you got 63 and 60 63 is 37 points away from 100 so you're you're plotting 306 this is the um the offset from 100 or the offset from zero so so if it's the left side if it's the right side you're going to go up you're going to say say 100 minus the the the location there so it be it'd be 30 you want 37 100 minus 37 um and then if it's the left side you would want 100 if it was 63 on the left side you would want 0 plus 37 does that make sense so what do you want me to add Tope I'm not I'm not okay I'm not sure yet I'm I'm getting the problem out there first okay I'm right can you start from 50 uh this is from Mr Patel can you start from 50 on a scale from zero to 100 that's what I was trying to if Darren is selected Darren is selected you subtract one or higher from 50 g selected right and you guys are offsetting you guys are offsetting from the middle that's where I thought you were going Darren okay yeah let's continue with with your thought process so are you able to repeat what you said I'm I'm trying to wrap my mind around what you just said okay so we got two sides 63 and 60 if you just look at the two equations right two values that's right if the right side is 63 the the the right side would be offset from 100 right so if you look at 100 minus 63 is 37 points so we would want to put our slider position 37 points away from the max okay if if it was the left side we would want to be 37 points from from the Zero from the minimum we'd want to go up 37 points so we know that 37 is the value we just have to determine is it from the minimum or from the max so you're either adding from zero or you're subtracting from the max an absolute value so so you get the absolute value and then H You' gotta fig we've got to figure out which side is the left and which side is the right then okay so I have a label here here and we can do an output and that will that will be the default value of the slider okay so you want to the the the 60 and the 63 what I'm going to do is I'm going rename this label because it's driving me nuts because we're looking at it in code yeah I'll say label person one and then over here I'm GNA say and's person two let's further name that let name that again Darren let's call label left and label right label person left person right right okay and the left is going to be minus and the because we're looking at this on a slider POS value position right let's write some code let's do it now all we've got to do now is we find out who wins which side which side is the greater side uhuh and if and if if it's right then we're going to we're g we're going to grab an an absolute value abs of that the distance between 100 and oh boy if it's person right you said if it's less than that's right okay so then you're G to say person you're gonna you're going to need the value between the distance between 100 the max which is 100 minus that value okay so I'm going to copy this I'm going to say this 100 minus that is that what you want to see there yeah okay um we might need to put that in a uh in a variable but let's just keep it there for now um else okay so I I I think I I know where you're going with this so we could just call the we could do a wi block okay man this is a coding session we're gonna I mean if you're a coder you're gonna be using with be doing all kinds of cool stuff here right do this we'll do that okay and we'll go to the end and we'll create something up here in the width block called the wiener the wiener is the ma oh this is where we can use max out of those two who's the max I like it I'm just gonna copy this thing here between these two things we're not going to use a less than we're going to say comma so max should be able to take values and tell and in return the one that is larger oh wow okay man it's really complaining about me it's angry complaining about my code it's very angry it's very angry okay what is the deal here cannot use men values in this context what needs numbers huh well we're we're using we're using numbers yeah value that should give us numbers okay maybe we're not allowed to use max or men inside of a WID block is that what's going on so if I said if I just take this max out just for a moment here and I were just to add these values together so we got numeric Val it still doesn't like it okay so we know that's not it so whenever you're debugging problems with this guys uh you've got an error and you're trying to do some troubleshooting what you need to do is come up with uh you know need to consolidate uh the thing here so if I say winner okay so I have a WID block on a label and I'm returning that in comment it the block has no in comment identifier okay I must not be doing my my WID block right it looked good to me it looked good to me thought so too man what what am I doing WR now that isn't right right that what did I do wrong in my WID block okay so you got you that winner that winner on the after the comma the second winner that that shouldn't be there should it um so so it should be 10 that okay now that should work so I'm gonna take that out looks good it's giving me 15 okay it was giving me an error on my comment I'm like come on dude like what oh you know what it is on it okay there you go there we go okay so so let's go back to your Min and Max because I think that's gonna be okay okay why it shouldn't be okay so let's I'm gonna take that and uh we'll add these I'm going to add them together make sure that we're okay there and then we'll do the uh the max okay Max ask two parameters in the Max and it should give us whatever the uh the maximum value is of course I need an ending parenthesis there okay so there is this working right I have a 63 um and that's right Kurt you're winning and it's giving me 63 okay so at least we know that so what we're trying to do down here is you want to take trying to get you your math here so this you want to say 100 minus the winner the the winner number it's well that's a conditional number because it's going to either be a 100 minus or zero plus the winner number depending on which one one repeat that okay um let's see if I can uh so it's either depending on which one one it's either going to be 100 minus the winning number uhuh or zero plus the winning number because it's we don't know which side we're going on okay so should we do an absolute function here the winning number should be absolute okay um but the but we it's the offset that we got to determine the the the xaxis it's either gonna be plus or minus if it's the left side it's gonna be a minus or I'm sorry it's gonna be a plus okay you're gonna add from zero if it's the right side you're GNA subtract from 100 okay so just based on what you're saying I'm going to I'm going to put uh an absolute function around here okay what do we have we have a 37 now is that the offset you were talking about is that what you're really looking that's the offset yeah um you've got that already established with the winner right how many that is from 100 if we go back to your code and your width block I think you've already got that you don't need an ABS around that I don't think okay um because you're it's just giving you the no you're right you're right Darren I'm sorry I screwed you up I screwed you up yep that's right so we got an ABS of that then we're going to take we we need to know if we're going to add or subtract it so if it's if it's person one we're going to add it from zero if it's person two we're going to subtract it from 100 and there you have it all right so you want an if statement in here yep now I don't know you guys you guys out there are going to come up with a way Slicker way of doing this than I did this is me off the top of a head on a s well you know what that's called Kurt refactoring refactoring is all a part of the game guys your very first thought your very first solution to a problem uh sometimes they say the the the first thing that comes to mind is usually the right answer nope if you're a developer in any way it's the opposite the first thing you come up with maybe the you know is usually your bug it's usually your bug oh boy so we have okay who won there but let's uh but you want to know okay I'm I'm zoomed in way too much so I need do one more here and do a control zero okay so you said depending upon who's winning okay so I want to know who that is so instead of just having this you know here um another thing here right who's who's got the most got the most wins right so we need to know the ultimate rock star in the moment so should we do a Max on this we probably need to do a DOT I think we had something here um that did that didn't we yeah we did didn't we do like a um count rolls we found out who who was the did you could do count rows right on a filter yeah okay so I'm gonna use I'm gonna do something like this okay um if come on give me if this is greater [Music] than this the person who won look at you you're doing it this I like it otherwise do that nothing's ever easy Kurt is it like what is going on here did I what what what's going on my FX when you got to put it in a value ammer ammer said you got to put it in a value I think that might be right ammer that ammer guy is really smart well you know he's been going he's got some good instructors nope that's not no that wasn't oh no good ammer well I I'll make this simple okay so here's here's the left value okay um boom. text now here we'll have to do a value right what is going on that was weird we almost have it we almost have it person to right it still doesn't like it now okay so that what is you got something going wrong here okay I I have to got you got another comment in there okay you got else coding's hard work this hard work what are you doing here you got a true part and then you got a false part okay it is it's hard so if the one on the left is greater then we're going to return them otherwise it's going to be the second person and that thing so you've won the most but if I keep clicking on this and pass you up man that's hard to pass you up man it is I'm gonna make you work for it Bud um yeah I think it's always gonna be Kurt uh unless I just click on it so many times okay so now we have that lbon who's won most copy that I'm gonna go over here and so what you're saying here is what do you want to do here this is this is your code man talk talk me through what you want me to do the whole thing is is that if it's if it's the left side you've got to subtract if it's the I'm sorry if it's the left side you got to add if it's the right side you got to subtract so we got to determine on you we've got to know if it's a left or a right thing if it's a plus or a minus okay so so we are trying to stick this this first of all this we are trying to put something in a slider right a value in a slider right so the slider default is going to be um this this you're you're just going to do an if condition in there and you're gonna say if if it's a left number we need to have a we need to have a flag set determin if it's left or right okay I just I just got you there by doing this check right here if whoever is won is on the left that's who's won the guy on the left yep there it is yep you're right thank you so whose one is going to be we've got that that's a text though that's going to be the person's name right yeah I don't like it this is what I want to do I want to put that into a a number all right so what I want to do is I want to say uh if if if it equals that equal right there if that comes out to be true I want that to be negative one I want to assign negative one to that okay okay you want to say negative one here otherwise you want it to be what one okay that's going to be determined whether or not I am adding or subtracting because I'm going to be adding from zero or I'm going to be subtracting adding times negative-1 so this is so hard to do if I it's so hard to do with with um me trying to tell you to do okay so because it's not look it worked now if I catch up to you it should be negative one right I think so and um I think what I'm going to do is I'm gonna add a button here for Clear okay and in the on select I'm going to say clear on that collection call responses some so I'm GNA hit that button who's Rockstar okay so we have two items okay one and one we're in the middle I'm GNA hit it one more time so we have three so we definitely know we don't have a tie right yeah so there we go so you said boom so this the person who's won the most is the person on the left okay left winner and this is the right winner yep right now we're always G to be adding either if it's from a 100 or from zero we just got to figure out if it's going to go from 100 or zero so um so if it's if it's from the left the left is going to be if it's person left I think I got that backwards uh Darren I think person right because we're gonna be subtracting from a 100 if it's person right we're gonna be adding from person left so I think I've got that so change that person left to person right up there okay uh not there in that if for the negative one okay you understand where I'm getting out with that negative one I don't know I'm gonna times that absolute value that we've got well we had an absolute value right okay yeah I'm I'm gonna times that absolute value by negative one and I'm gonna add that absolute value to 100 if it's negative negative so be 37 I'm going to subtract it okay so so that's going to be times1 or times or times one that I was actually thinking I was gonna put that in a variable and times it by a variable name but okay two um times one else okay if got 98 now does that make sense we've got three votes Darren's got two votes Kurt has one so it's 2 V1 98 98 you're gonna be offset so I want offset from because Darren one though I need to be able I need to subtract or I'm sorry I need to add that 98 so it should it should be all the way over you see where I'm pointing my finger it should be all the way over to the uh to the right the ma it should be almost Max right so it should be 0 plus 98 so it should be all the way over um so that's what I want to do I want to add so if it if Darren wins I want to add okay so you want me to go back in here now so so we we've got that so what are we doing here with this if what what are we doing here with you got these two absolutes you got a if they're in one you're going to take that absolute time negative one yeah and and then um okay I got it go back there go go back to the formula all right okay now you're gonna say after that negative one uhuh before the comma there you go you're gonna say plus uhuh uhuh hold on hold on hold on plus one plus with winner number Winner number no that absolute value so it's going to be that ABS so so that absolute so what I'm W to do there is that absolute value minus the winning number times negative one I want to add that number from zero if it's on the left side add zero no add it from zero okay what does that mean add from Z zero what does that mean so in other words I'm at zero this is an offset from zero so it's going to be zero plus that winning number so it'll be that winning number I guess it'll just be that winning number right that's right it'll just be that winning number the right side is going to be a subtraction and I said that exactly I we've got that exactly backwards don't we I don't know the right side is going to be a subtraction from 100 so I needed plus that winning number so that we need the negative one on that one the right side winner okay uh what line of code do you the the select do you want me to to modify this line of code all right so uh the right winners you see where it says right winner in your comment that's what I was referring to I want that to be negative one you want that to be negative one I want that to be negative one make that a negative one and then change that yeah okay so the right side is gonna be 100 minus that so go to the front of that ABS go to the front of that line and put 100 minus that okay that code right there should if you put that in your default of that lab of that it should work okay so I'm going to go over here to default and I'm going to put this in there. text course we need to make it a value Okay so we've got 198 yeah it shouldn't be that okay so if I take 100 minus if I take I take see the screen of the code of the code if I take 100 minus the winning number that's gonna give me the absolute value right so it's gonna give me the offset so if I take a 100 minus the winning number okay most one text equals text ABS 100 minus the winning number so let's say if you've got at this point it' be 100 minus two 100us two should be 98 times one should be a positive 98 right I don't know look at the left winner equation okay okay now think this with me man okay if I've got 100 minus the winning number if I've got if I've got two 100 minus two is 98 right right times that by one that's positive 98 uhuh so it that should be uh it should go all the way over to the right should be 98 there be there should be no 198 so so if I say 100 minus the 98 oh wait a minute wait a minute wait a minute okay I'm sorry bro look time what 100 minus it's gonna be 100 plus there it is okay take that minus 100 minus make that 100 plus okay sorry I screwed that up not that one not that one the one below the right side witer one okay you want to do a plus here oh my goodness no Darren look man okay so go up to the left winner okay I just want I don't want that I I just want that right there that's 100 plus the winning number times one that's going to be perfect okay now the one below that okay right winner I want that to be 100 plus ABS not minus ABS all right you want to see the results well um no not done yet okay okay I just wanted to see what the result is as we're as we're coding so I put it right here in the lower left corner this 100 plus winning number is never going to be it's gonna be 100 minus that winning number up there you change that to a that left side left winner okay love winner that 100 minus winning number that's that's what I want right there I want that to be a 100 minus winning number okay you want a minus here yes that's what we started with was I somehow how you turn that into a Plus on me I didn't know okay now the one below that is going to be the same thing 100 minus winning number okay okay now if I look at that code 100 minus the winning number that's going to be two that should be 98 that should be right let's go let's run this that's always going to give us the winning number right it should it should never be a 198 or anything like that it should be hey so I have three votes you have one we're looking at the top slider right yeah that's offset from three that's perfect now let's go let's let's keep running here let's get to where Kurt's winning needs to win okay so something's still not right here with that default you know we need to reset we need to reset that slider bro do you think um well I think it's moving so it says five right say but it's not it's not changing the if you go down to the code it's not it's not doing the else because we're doing something very different in there okay so so what do you want me to do I I want you to go to the code okay let's do that yeah coding it should be other people are watching or talking and then going live where are you putting this code at that code should be in the default of the slider right no so what I do in the default is I look at that label okay okay so so we've got five so what's happening here if so our if condition up here is not working very well or the max one of the two because it's never changing back over over to the right side so right there you got a true statement if who one. text equals the left then it's going to do a certain thing otherwise it should be doing a plus it should be we should be doing it we should be taking it 100 we should be going from the 100 and maybe this thing this 100 shouldn't be 100 it should be the amount of vot amount of times it was clicked on right no because you want the max to be the total you want you want the max to be the the most so we're offsetting from it right okay all right unless maybe I'm doing the same thing am I doing the same thing down there on that second one if I say 100 plus go through that code with me right there ABS 100 minus winning number right now what's that gonna give us what's 100 minus winning number right now okay I am so you're interested in just that right yep what's that number so what I'm gonna do is I'm gonna bring over a label and I'm gonna show you okay I was just wanting to step through the code with with you okay all right um of course this label doesn't have the WID block so let me do something like this and I'll go over here and I'll do that and then this is all you want to see here okay 95 is what we have okay so we're taking 95 and it's saying that CT one so it should be 95 so we say oh so let's go down to the code I think I see what we're doing wrong let's go back to the code okay so we're taking if it's the left side it would be 100 minus 95 right it's saying 95 it's saying Curt is the right side so the winning number is 95 right now 100 minus 95 I don't know man okay I I I I don't know and and that's fine what what I was about to say a few moments ago is this might look really easy to everybody because I I see the comments going crazy oh you should do this you should do this and um it's not well my my thing is I can't I I just can't think with the with the moving around stuff I just have a hard time with it I you know if you're not in control of the mouse it's really hard it's it's it's like I'm like okay I I and then like I don't know it's like um I'm asking I guess I'm asking you to kind of think through it with me to make sure that I'm not on the wrong track here because I think I'm on the right track I just doing one thing wrong and and I'm I'm I'm trying to help you out I I have to do things in order to think about it right okay so inside this Cod this code the left winner okay we got that 100 plus abs winner and then here we' got the minus okay now did I do that right the 100 plus oh you know what I think it's opposite can we go back to my code again yeah just give me one second um okay so you got abs this one is ABS and then this one is the 100 okay all right I think maybe it's a parentheses issue here okay so so the right winner I want that right winner to be in this case I'm I want two to go away from it right so 100 minus sorry I I just G to move this around so we can actually see these these two and then put this one here this is the winner okay here we go so this this winning number this ABS winning number computation there's something wrong with it in my mind if I've got if I'm on the right side I'm trying to subtract I'm just trying to get an offset from the either the maximum or the minimum that's all I'm trying to get here that's all I want okay so if I'm looking at an absolute 100 minus the winning number if my winning number is two so it should be 98 if it's on the right side right I don't know you don't know so what would it be what would you okay so if my n my winning number is two my abs would be 98 there 100 minus two right would be 98 I I don't know what you mean when you say the winning number is two so you're talking about up here for this variable that's if Dar if Kurt has two wins and Darren has one if the if if the person on the maximum is two that's that's the point I'm trying to get at okay yeah so if if uh if this is let's just use a scenario this is two and this is one okay the winning number is going to be two but it's not the maximum amount or the uh the count I'm just saying and I'm just trying to walk through a a spot in here to see if this codee's going to work on the right side so if Darren has wins and d and Kurt has one or actually if Kurt we're on the yeah um the left side so the left side is the winner why doesn't it give me my collections there's my collection and say count I think I actually have a function for this FX total tries okay um and then of course we need that and that'll give us total tries um I knew this wasn't going to be easy oh it's well Kurt what I was thinking was what are we gonna talk about on a live stream this is how you do a user defined function we could probably cover that in 10 minutes but that's not what people come here for they want to see what the coding experience is like in power apps in the Power FX language and this is real world is it not yeah yeah this is the type of stuff if you and I were sitting we worked at the same place we're working in an office together this is exactly what this is going to look like guys this is the real world this is what people compliment us on anyhow I think I might have messed you up by by doing this you had a thought proc yeah I I I I just wanted to walk through the the code with you you're it's bouncing around so I can't even concentrate right now so just letting you go ahead and do what you're doing what I needed to do well you you kept on saying right right right and I'm like I I don't know I don't know I I don't know if it's right or not Kurt I don't know so well I'm say you said hold on hold on you said if if the the left guy has two the right guy has one we have a total of three that's what I needed to work out my brain okay so what you when you said right your question was when the winning number would be two based on this scenario here then you had like a question and so okay so let's can we go back to what I was wanting to do here we got we got this left winner line you see where you got your commented out left winner line yes it's right here yeah so if we I wanted you to step through this code with me right here and let's assume the winning number the winner number this winner number variable is two okay so if I have 100 minus two that should be 98 right yeah that was what I was asking that was my question times one would be 98 right 100us but you said you okay you said this line 100 minus two okay that's 98 right let's just work it out here is 98 yes that is true true okay times one would be 98 yeah you multiply anything by one you're going to get the same number so this equation that that I guess I'm asking you to step through this with me to make sure that my thinking is correct all right so I've got 98 there that's that's the value I want if the person who won the most is on the left side okay yeah and I just don't know if that's going to be right because because if it's on the left side that would give me my my my value would be 98 which would be two away from 100 right I'm trying to invert I'm trying to invert so so on the right side on the the left side no that is right I want 98 I want that to be 98 because the person on the left I need that to be 100 minus the 98 right I need to I need to be 100 minus 98 because I want that to that two to be the winner I want that to be sitting over there at two on the scale correct okay so the full question was you said if you take a 100 minus the number is that what you said if no no if I've got that number right there that value that 98 gives me the value of 98 right okay right and I want that 98 to be placed so I want that to be I I want in the end on the scale up there on the slider the maximum is 100 okay if I subtract 98 from that that will give me two if the person one on the left and I want that I want that to be I want that to show a two because that means that the person on the left one does that does that sound right to you um that would I mean that's always going to give you the the um the left side so here I mean it would be a two out of 100 yeah which that's if you look at your top scale up there your slider uhhuh it's sitting at about two right right now it's sitting at five but if if so if we took that instead of a two we put a five there that five that that five would be offset and see you could clearly see that Darren's the winner now because the tug of war is Darren's Darren's got five wins versus Kurt so on the on the slider scale it would be going to your side that seems like that works right there the problem is is that if right now Kurt has the five so I want that I want that slider to be over there on the on the Kurt side all right so let me let's use real values the three and the five okay so I'm going say three and five and the count of course would be um all of those added together which would be uh eight right so if we go down in here this would be 100 uh minus 3 which would be 97 times one that would give us a 97 well hold on Darren the max would be it' be five right because you got the winner number is going to be the the highest between those two correct so so in this case it would be five the person on the right okay so it be 100us 5 okay so give me 95 yep so you want that 95 to be that value there I want that 95 yeah I want that slider to go all the way up to 95 that's correct okay but I think what's going on is it's coming down here do we need to change any code down here at all I'm thinking that this is the code it needs to go down here yep I need it needs to be there so the the the condition is if who won text equals a personal on the left it's going to do the true which would be the top one so else we're doing the right side winner you we got that set up beautiful so why are we not getting so the code is the problem is in that line of code right there right there okay yeah because we're getting five we should be getting 95 exactly but we're getting five but we want it to be 95 right so we need to go that winning number 100 minus the winning number would be five right we don't want to go win 100 minus the winning number do we I'm I got it Darren you got it all right I think so I got it bro go back to that code man just all right so I just wanted to add another label here that's going to tell us if if we're in the true part or the false part okay and I'm gonna go in here I'm gonna say 36 here okay so what's giving us the number five is the false part so we know if we're not getting what we want the problem is right there on that line of code so now we're just going to take uh winning number get rid of that ABS part down there on that second line just take winning number 100 get rid of the ABS and then the 100 minus okay and it's going to be 100 plus winning number times negative one which would be you you need to maybe you might need to put that left and right parentheses around the winning number times negative one okay and that should that gives me 95 I think that's what you said you were looking for the 95 that's what I'm looking for so let's go run the code and see what we get now okay so now ctt's the winner now keep clicking here and see what happens when we get d the winner come on Darren win something oh my goodness well I'm G have to clear it there you go now I'm the winner yeah but now see but now it's going over there to the left side it should be over here to the left side so our condition is not seeming to work right the max now we um so Ben in the comments he he has said a lot and I purposely wasn't going to read because I wanted you to finish out your line of thought um so he's got some ideas that might help us if you want to look at that but if you don't want to look at it uh because I think he's doing something completely different than what you're doing so you wanna I wanna I want to continue what I'm doing here I want to find out why is it not got going to the left side why is it not showing it's showing that Kurt's winning here so why is that so it says false here that means we're still over here in the false part it should be on the true there shouldn't it well let's look at it who won the most is Darren and look at this person on the left is Darren is that right no it says one it should be personal one yeah maybe that maybe I messed you up with that man okay so we're looking at that this is the [Music] true it shows you how important naming your controls right are right that's why we name our controls is to keep from because we have a bug here we're confused it's not working right and I was using the wrong control Kurt Darren you and I would have had this thing done in five minutes man if it wasn't for two people trying to interact and so hard it's just so hard or we knew PE nobody was watching we yeah it's so hard I'm sorry guys okay so H so now we've got 99 is that what you wanted well let's go see it let's see how it places it out there let's go see what happens here so there's only been one vote and Darren W I want that to be all the way over to to the zero should be the left side okay so how do we take 99 and make it well let's go look at our cover see how I did wrong I thought I did it right let's go see what I was wrong I should be right 100 so we need to go 100 plus the winning no 100 minus winning number what that would be 95 times one we just need to go um winning number there that's it okay what we just you want this line of code to be modified right here I think yeah I think that needs just to be winning number doesn't it because we're just it's just the the uh it's just going to be the number of wins that youve got that's it okay on the left side on the left left side we started off with all this ABS crazy stuff it's just so simple it's just guys I think that might be right Darren that's all we want right just we want if if you two from there oh my gosh all right so is this line of code fine it's so far it is let's go run let's go run this thing let's see run it all right let's do it look at there okay we got one and one this is a tie it should be in the middle then okay but we have 99 so we have so you want this thing to be 50 right now we're in the fal sight so how do we make this 50 right right well okay so so let's get these numbers up here right so really what are we working with we're working with one and one okay so we go here one one one and we got two votes okay so the winning number is one okay so with this thing so what we have we have 100 plus the winning number is one and then we're making it negative okay is that right so we have okay so 100 plus a negative won is 99 but what you said you wanted how do we make this to be 50 right so so now what we're going to do now we're back to our proportion thing and and now we might be back to where I think um somebody over there maybe it was Ben um was starting at 50 and then we were going back and forth from the the distance yeah I think part of the confusion in in my head the the more moving Parts the the easier I can get confused were we doing the tug of war are we doing something a little you know different you know um we ended up spending most live stream figuring out this TG of War I think our I think our viewership uh likes this so guys go down to the comments below and let me know if if you know you you like this or not you're getting anything helpful out of this a comment or even a like really helps the channel and that's people like you know this is good content much appreciated and people pay big money for this so we're not done yet so uh something that somebody said was the total amount of the total tries should be factored into our little equation down here I've got I I I maybe I think it does I think it has to okay it's a percentage of the whole right right so we've got a 99 how do we take 99 and make it 50 so what we' got to do is we got to change so we've got one each person has one um yep it's a tie so so you take the winning the winning person and make it a the the number is going to have to be you're gonna you're gonna um divide that by the number of Tri so you would say you should get a percentage then you you would get a percentage right so let's say if you had a 50 if you had if you had five out of eight you would F take five divided by the number of tries five you won five times divided by eight tries if you had eight divided by eight would be one that'd be 100% I think if we take the winning number okay so um let me just try something out here we take the winning number divided by total tries that's gonna give us 50% right and then we're gonna take 50% and times that by a 100 yep okay that's what we're gonna do and then um 50 do I do the times 100 down here oh look at that we got 50 that's what we were looking for right we're looking for we were so close there is that it let's go see all right vote one more time okay Darren's got two you've got one now this label just went crazy on us here so quite right yet almost we just gota we got to do that times negative we got to do some placement it's a placement thing and I'm going to round this because it's giving me a decimal is that okay yeah does not like that it helps if you spell it right okay so we got we got twoth thirds is what's going on here yep that's that's fine I think that works man did we figure it out no let's go no I I saw saw something wrong play it some more you said play it some more yeah Play click on it click on it some more I think there's a problem here see it shouldn't be going to Kurt's side right there it should be going to Darren's side so it's just a we're close Darren we just got to do this it's that's where that times negative one comes into play because we want that to be placed that left side we want that to be placed um if Darren won you want it to be 75% it it should be 75% of that direction so it really should be 25% you see that we're inverting the number right so so we just need to invert that that equation so 75 you're if you got 75% you want it to be 25 points away from the zero so so get it done you want me to take it over now no I'm teas I'm teasing we're almost there Ben said we need it Ben says this is where your 100 minus comes in yep yep I knew I was close I just had all the pieces not together okay so we're getting there man so Darren's side would be the left side so text person one so that needs to be um what does that need to be Darren 100 okay so if we take 100 minus minus uh 75 would give us 25 right 100 minus the number okay what's the number the number Darren the number the winning number Mar says my head hurts that's what it's like to be a it's so fun this is hey this is a life with Kurt and Darren every day we just do this this is we're we're we're nuts that's how come Darren can't stand me after four o'clock okay so what happens is being a software developer is a roller coaster an emotional roller coaster psychological roller coaster now either you're really you're watching this you're really smart and you're like I I figured out in 10 minutes and you guys are going on here for two hours on the same problem well number one you should uh you know hopefully you feel smart but I think for the most the most of us it is a roller coaster and then if you're not a if my wife called me like Darren you know dinner's ready you know I'm like okay I'll go down there and I'm in this really funked up emotional psychological State because I I didn't get resolution and let's say if I went to sleep right it's midnight or whatever it's your bedtime you got to go to go to sleep well number one you're like ah well when you wake up you might have figured out maybe you had a dream or or something but when you figure it out it's such a huge win right so this is like if we're working an office you go find your buddy hey look at this with me so this is sort of like what this looks like and and then we'll resolve it boom all right you want to solve it and then go to lunch like me and Kurt we'll go out and get some general's chicken from from our favorite Chinese um place and we'll have a great lunch but if we went to lunch right now we would not have a good time would we no we'd be having a blast we'd be having fine okay so so this winner number let's get back to the point here because I don't want to lose this so so we're almost there I think so we got the bottom side the right side's working I think right um it's that left side we we need to invert that number so so if if for instance Darren wins 75% of time three to one then we want that to be 25 the difference SE from 100 100 minus the 75 would be 25 we want that to show up on the on the top one the the left winner okay so the first thing that you said is one of these these two is working right is it the true side here or is it the false side which one are you talking about I I feel like the right winner is working okay the right winner okay so this one right here yeah I'm focusing on your comment right there because I can't yeah okay so we need to work on this one okay y now now repeat what you said okay so what we wanted to do is right now in this in this state at this moment Darren has won 75% of the time three wins to one win so he's got a 75% so we've got that calculation right I think three divided by four should give us 0 75 winner number divided by total tries so we got three one yep so I'm going to say three here total amount is four okay so and we are on the true side so winner number is three total rzes four that should give us 75 and we multiply by 100 got 75 right but what we need to do is we need to subtract that what once you're done with that equation we need to subtract that from from what from 100 okay so now we got 25 let's try it let's see I'm almost afraid okay let's clicky clicky here let's see what goes on okay we need to keep clicking so Kurt can be the winner here okay it seems like it's working so boy you just keep getting bigger and bigger there yeah it's working it's actually it's moving good man because it's actually in proportion too this was great you guys out there you guys were Geniuses getting us to this point look at that what we almost were at even you you had us at even for a moment yeah get get us to where we're tied oh my goodness look at you well I gotta clear it and click hope Twi you can't divide by zero Kurt yeah I knew that okay there it is look at that we're we are in the center we finished it sh are are you sure this is uh we keep clicking let's see let's see winning here let's make sure the right side's going okay you're winning it right there yeah but I went to the left keep going keep clicking Bud well can we figure out why it's with these numbers why it's not doing what we wanted to do okay do so we got two three and five so let's click on this so we have two three and five and we've got 40 now is that is this right is this what we wanted I I think I think so um we are four fifths Kurt would be four fifths of the time winning I think um or three fifths it be it's round we're rounding though okay so but the problem is we should be on the right side of that thing not on the left okay so instead of this number being 40 it should be 100 minus 40 yep what' we do so and the reason why I did it this way maybe I've got a print y issue here going on I think I do Darren okay because you want that to be 100 plus so that negative one that times negative 1 should go on the outside of that whole thing we're on the right side winner which is the bottom line the one you're on 100 that times negative one should go apart from that division okay so get that division in there first so do you want to you want me to move this parenthesis I do I want I want you to get that I want no I want that parentheses to be on the right side of that 100 over there oh okay right here I don't know that yeah is that is that what I want Darren maybe maybe you were right maybe I need that on the other side okay um you might be right about that but but we still have 40 100 so really what we're looking for is 100 minus all of this that will give us 60 that's what I want so let's click on it a few more times oh I think we're close I think you you solved it down there at the end I think that last little I think that last little bump is what we needed that's what that's what Darren does Darren gets me across the Finish Line look at that okay we have a tie and it's at 50 yep now go to Darren come on let's see Darren win look at that it's working Darren now five out of four that's about right four four well that should be eight yeah but that's right there you wanted it to be 40% away so so we are doing the tug ofar thing we are so because I'm winning I'm winning slightly I should be slightly to the left of the 50 yep I'm gonna I'm gonna clear it and hit it once you can't divide by zero Darren so Kurt's winning 100% this is working is that true of course now we got a tie it's right in the middle hit it one more time Kurt's winning look at this dude I I think we did it I think we did it I think we did too you guys think you guys think we did this we at 50% let's get Kurt's winning now 60% now we're at to tie again now Kurt's winning again I think it's partial to you man it is four to four it's because I'm older and have more insurance and remember people pay big money for this you guys are funny for the price of a cup of coffee a cup of coffee yeah you can you can recover Kurt from his for the price of a cup of coffee you can re you can recover Curt and Darren's app hey this is fun though so so what did we solve here I mean this was this was Amber's Fault by the way I just want to put that out there this is Amber's fault because he said something about well we could do a tug of- war that just got us all on like we're like a bunch of dogs chasing squirrels now what a ride he says Hey Triple A says what a right Mark says my head hurts Ben just Ben just gives us a too am you're welcome to come on and and share your video if you want to give your thoughts on this you can defend yourself ammer if you want to um okay oh here he is here he is here he is hey Hammer this was your fault bud you started this well my initial plan was to have two sliders but then uh and then and then I was like okay yeah too for and work too I had both of them in mind so this was my fault because I said we should do it in one yeah this is good stuff guys this is cool stuff I mean what we did here is we talked a little bit about the functions which is what we wanted to do and we got into some real programming um stuff and and again you guys this would not be as hard if you're you know just sitting here by some of you guys probably sat out there on the side going had that solution done within two minutes you know so but um I I think think you did a good job on this one Darren thanks well I wanted to T touch base on uh on our uh personal pocket coaching absolutely because we actually go into to this stuff here um creating a variable watchbox now you got some math type of stuff you had a challenge in here um so on some of these you actually uh do some of that right you got string reversal that was a cool little exercise and personal pocket coaching yeah and so these are bite-sized or shall I say pocket Siz little lessons or challenges every day of the year if you want to know more about it what you want to do is go in here and uh you actually get the ultimate jump start kit as a bonus which I sell for 250 the full ticketing system course which I sell for 500 you get a a tutoring session with me and Kurt that's a $1,000 value and you get a video every day of the year and because prices change I'm not not going to mention the price go over there in the community click on the payment link and um you could you could get you could get the daily dose of Darren and Kurt every every day so so really what I I guess I just want to just say one more time I say I sound like a broken record or maybe to Darren is probably Chinese water torture but I I just I think that this is a great reference guys I can't say this enough that personal pocket coaching is a great reference library because these things are going to be labeled they're going to be concise as concise as we know how to make them and you know you're just get you're getting right to it so imagine doing this big exercise we had if we could have put this in a into a PPC this would have been done in five minutes you know it's like this how you do this you know so in fact I think I think either me or you or both of us should probably do a a slider or this exact exercise in a PPC um just so I'm gonna have to end it right here hold on for some reason YouTube thinks you're going to like this video next let's see if they're right or you can select this playlist which I've
Info
Channel: PowerApps Tutorial
Views: 4,572
Rating: undefined out of 5
Keywords:
Id: K3bP_L-nYws
Channel Id: undefined
Length: 179min 53sec (10793 seconds)
Published: Sat Jan 20 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.