Named Formulas & User Defined Functions in Power Apps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone razza here this video is all about named formulas and userdefined functions these new features will transform the way we build canvas power apps so let's check it out in [Music] action in canvas power apps we have the ability to create variables we have different types of variables Global variables local variables Collections and now we have a new type named formulas any type of variable that you choose the data that you set in variables are stored locally on the device for the specific user session only I have a button to create a global variable we use the function set in this case when I click on this button it will set a global variable to the value one and since it's Global I can use its value in any screen of my power app then we have local variables we use the formula update context I'll give it a name Lo data and put the value one so when this button is clicked the value for this local variable is set if I go to screen two and try and refer to that variable it says this isn't recognized if we look at the variables Explorer v data is my Global variable and I have a context variable meaning a local variable called NOC data that is local to screen one next let's create a collection which is tabular data using the collect function give your collection a name and then start adding the items in your collection I'll add an item that has two properties flavor and quantity I can add multiple items in my collection as a collection can store tabular data so if I click on this button it will go and create the collection and add the records that I have defined named formulas is an Excel concept these formulas that we can write by heading over to the app object and creating them in the formulas property the formulas that we write here recalculate automatically like a spreadsheet for example x equal to 1 that's my formula I'll end it with a semicolon so I've added a text control value of x is I'll go and plug in the name of my named formula it says the value of x is one now the only place where I can change this formula is in app formulas with variables collections you can change its value in different places in the power app now this formula's value is always up to date for example if I change this to 10 immediately you can see that it has reflected in my text Control Plus there is no timing dependency for example let's take the app objects on start function on start is the first function that gets executed when the power app is launched and this is where we typically plug in logic to hold configuration data and more using variables and collections now when the app loads first on start runs all of these formulas have to be executed prior to taking the user to the home screen experience which can result in slow load times depending upon how large your onstart function is with named formulas there is no such timing dependency they can be calculated in parallel plus the named formulas calculation can be differred meaning the formula will only run when a particular screen is pointing to a reference of the named formula let's take all of these formulas as an example example when my app loads all of this logic has to run and then the user lands on the home screen I may or may not use all of these variables and collections on that specific screen but power apps will still have to do the work but what if I can take all of this and make these named formulas the Syntax for name formulas is different though all we have to do is give it any name of your choice equal to your formula semicolon I'll recommend following a naming standard named formula so I'll begin with NF here I was creating a collection to load data from my data source here I've transformed it into a named formula and I can do the same for the rest easily I was able to take all the information from from app onart and put it in named formulas named formulas will improve the performance of your app significantly named formulas should be your first choice there are scenarios where you need a variable purely because you want to change the value of that variable from different places in your power app similarly for collections named formulas you only have one source of Truth with named formulas you can Define the values directly query data sources call different types of connectors WR complex Power FX formulas and more additionally with named formulas we have the option to create userdefined functions how many times have you come across a scenario where you wanted to repeat a particular set of Power FX functions in different places in your power app with power effect we have a powerful Suite of formulas however there are scenarios where we would like to write our own custom formulas at the time of recording of this video it's in preview so I'll go to settings upcoming features there are two features I have to enable to use it one is new analysis engine and the other is user defin functions I'll save my app and reload the studio experience here I'm trying to calculate the profit and loss the user will enter the cost price and the selling price I want to show the result here in this text control and I can write a simple formula the value coming in from my selling price text input control subtracted from the value coming from the cost price control and divided by the value coming from the cost price multiply this by 100 to give me the result in percentage and currently those values are empty so it may throw an error if error function and if there is an error I'll put out the value as zero cost price 500 selling price 700 that's a 40% profit how about making this a user defined function back to named formulas I'll say calculate profit loss this is going to be a user defined function so I'll open function brackets I can also pass parameters first parameter will be cost price colon I can Define the type number comma selling price that'll be my second parameter of type number I'll put a colon here I can Define the return type I'll say number is equal to selling price Minus cost price divided by cost price into 100 I have to end any named formula with a semicolon I can even perform that same error handling here full power effect capability now to call this formula from the screen Cal profit loss you can see how it shows up as in Native formula and it's expecting two properties cost price that'll come from my text input for cost price and then the selling price the value property of my text input control for selling price and there's the result you can see how the calculation is taking place live I can reuse this formula across various screens and now let's say I need to make a change to that formula all I have to do is go to the single source of Truth and make an update here I've updated the formula to show different emojis depending upon whether it's a profit or a loss here it shows a profit of 60% I changed the value it's doing the calculation live now it's a loss of 40% and you can take named formulas to the next level from simple calculations to writing regx to validate passwords I can search for any user it will go and return all the details about that specific user my profile picture how many folks are reporting to me all of these calculations I can do in named formulas and simply just reference that formula directly here how about a scenario where you need to calculate the number of working days between two dates for example my start date is Monday Feb 12th my end date is Monday Feb 26th number of working days calculated is nine the name formula is also checking a holiday calendar that I have in a data source I can even check the current logged in users security rule is this user a system administrator yes does this user have the app opener security role no here I have a gallery control that's listing data from my issue tracking SharePoint list that's connected in my app and I've also leveraged the modern table control to show the data coming in from my issue tracking list now here as well we can use named formulas I'll create a named formula for issues created by me and here I can directly save filter my data source where the created by users email address matches the current logged in users email address and I can directly use that right here so this is listing out all the issues that are created by me once again I'll go and frame a named formula now imagine the scenario where I am adding data updating data in the list for my user session as I make those changes this named formula will recalculate so named formula can perform a calculation that is dependent on control Properties or database records and as they change the formulas value automatically updates you don't need to manually update the value as you do with a variable or a collection if you enjoyed this video then do like comment and subscribe to my YouTube channel and thank you so much for watching
Info
Channel: Reza Dorrani
Views: 21,578
Rating: undefined out of 5
Keywords: power apps, named formulas, powerapps tutorial, microsoft powerapps, power apps beginner, power fx, learn powerapps, power apps named formulas, powerapps formulas, named formula in power apps, named formula, named formula in powerapps, power fx named formula, set vs named formula in power apps, named variables, reza dorrani, user defined functions, powerapps functions, powerapps, named formula in power fx, power apps user defined functions, power apps new features, Formulas
Id: aIMhiLH9bLg
Channel Id: undefined
Length: 13min 40sec (820 seconds)
Published: Mon Mar 11 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.