Using Variables in Power Automate Desktop - Full Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a variable is a container that stores a value or a set of values that could be used later on in the workflow variables can store data types such as text numbers dates booleans and data tablesen a Microsoft most valuable professional let's learn some Microsoft power automate desktop a text variable stores any kind of text from email addresses to text contents of a text file to create a text variable go up to actions search for a set variable and drag it in here we will call it our text and as you can see as I click up here a variable is surrounded by percentage signs up here you don't need to write them because if I write our text I click away how automate desktop automatically adds them whenever we want to refer to this variable later on in the workflow we will type this text and remember the percentage signs let's give it a value here I'll say it was a right cold day in April and The Clocks Were Striking 13 like this this is the text that we want to work with so I click save here if I run my robot by clicking run up here nothing happens but over here in flow variables you can see that this variable got initialized and if I expand it a bit here's our value the variable type you can see that by text value this is a text variable we can manipulate a text variable in all possible ways for example let me close this here and go up to actions find a crop text and put it in here we will need a text to work on and this is our text up here a smart thing is that if you click this little X out here to the right then you can select variables we only have one so we can double click our text or click it and then click select either works always use these variable Pickers whenever you can that reduces the risk of arrows we don't misspell these things so now we have our text here to work with let's say I want everything after the comma and the space so that will be and Clocks Were Striking 13. click the mode here the drop down say get text after the specified flag the start flag that would be a calmer and then a space down here we can see that a variable called cropped text is produced that will be everything after the comma and is flag found that is if this comma and space is found in our text if I click save and run the robot once more we can see that it is flag found is indeed true so it finds it and that's what we expected and if I go into cropped text I can see that and Clocks Were Striking 13 mission accomplished one other common text manipulation action is the replace so if I go up to actions find a place replace text and drag it in just before the crop text so the text to path that will be our text up here and again remember to use the variable figures out here so click the X double click the our text the text to find let's say I want to replace 13 with 14. so I write 13 here then I go down here replace with and I'll say or chain like this in the variables produced this will get saved in a replaced variable let's just save it back to our text variable so the crop text can use it then in the variables produced if I click this Arrow we can see that a replaced variable is getting produced that will be this text with the 13 replaced for 14. let's save it back to our text here so we can use it in the cropped text here again you can see I can use the variable figure so we do click this x choose our text and double click it that's it let's click save now try to run your robot once more go over to the cropped text here you can see and Clocks Were Striking 14 and actually you can also click closure if you open up the our text you can see that we will placed 13 with 14 that's why our cropped text says 14 in the end as well click close now go up and click variable hold shift in on your keyboard and click crop text right click and then disable actions this means that if I run the robot now these actions will get ignored but we save them for later if we want to recap what we learned today the next variable type is numericals that is all numbers go up to actions find a set variable and drag it in here we will give it a name let's say salary 2022 and again if I click away power automate desktop will automatically add these percentage signs that mean that means that this is a variable in the value we will give it a numerical value that could be 51456 and then 0.5 this will be the salary for 2022. if I click save here I run the robot once more then I go over here to my flow variables I double click it now we can see that this is a numeric value that was expected and we click close it's important to say that this flow variables these variables that get shown over here are the variables that getting initialized here in the flow it will show the last value the variable have and here we only have one action so of course this will be the value that we gave it then I can click close we can do all sorts of mathematical operations we surround the math with percentage signs to find our 2023 salary our 2022 salary gets adjusted with inflation which was 6.5 percent let's create that calculation go up and find a set variable and drag it here the variable name that will be in relation so the inflation was 6.5 percent we can write this as 0.065 this is 6.5 percent then we can click save now you can find a another set variable and drag it in here drag it down here we will call this salary 2023 and what we want here is that we want to add 6.5 percent to this amount let's go down here we agreed that a math operation should have percentage signs in the start and in the end and we can start doing that by simply just clicking this x here double pinning the salary 2022 we now have the percentage sign in the start and in the end yes this is not much of a calculation but then I want to say multiplied by and then I want the parentheses and then I want to say plus I want to find the inflation over here we created that variable so I double click that and I also want a parentheses whenever we do math and variables that is code blocks with the percentage sign in the start and in the end we only need a percentage sign in the start and in the end so we should delete this and we should delete this whenever something is in text format without a single quotation mark like this surrounded by should look like this whenever we see these texts inside a code block that means that they are variables and that is right our salary 2022 got created up here and the inflation got created here let's click save and see if we can calculate salary 2023 that is over here that is the inflation adjusted salary now click close the next variable type is booleans that is a variable type where the value can be either true or false let's go create a search so I find another set variable and drag it in the variable will be called is hi salary like this and to give it a neither true or false value we will have a percentage sign then I'll say true and a percentage signed if I want to give it a false value I should just have written this but for now this is true I'll click save then I'll click run the exact same thing will happen but except that this bit is high salary is now true we can see it here if I double click it we can see that this is a Boolean value it's not dependent on anything up here it's just independent if I had double click it and let me just do that if I have deleted the percentage signs click save if I run it now and then I go inspect it over here we can see that it's now a text value that is because if we surround a true or false by percentage signs it becomes a Boolean I'll do that and then I'll click save once more now we want to make the is high salary dependent on the salary 2023 double click this set variable to open then we'll delete this so and let me just drag this one down here so we want to look at the salary 2023 so I click this little X here double click the salary 2023 then again we learned that every math operation every code P should be surrounded by these percentage signs so I move my mouse in here I can make a space and then I can say greater than 80 000 for example these spaces will get ignored by runtime but it makes it easier for you to read but we could skip them so it could look like this instead doesn't matter it will be the same thing we're doing so right now the is salary will have a true or false tie to it and that is if the salary 2023 is larger than 80 000. we know that this is only 54 000 so this will be false let's see if that is true I'll click save here I'll run the flow and the is high salary is false I can click close let's disable all so I click here and now I can of course press shift and click the hello set variable and also just press Ctrl a that will Mark everything right click disable now we need to talk about dates we use dates a lot in our flows We compare them we type them into systems go up to actions to get the current date and time we'll find a get earned date and time and drag it in here this will retrieve the current date and time if I click this drop down I can also choose to retrieve only the current date the time zone that will be the system time zone that will be the time zone that you will use in 99.9 percentage of the cases but you can choose another time zone the variables produced is called q and date time I'll click save if I try to run it here you can see that we get a date if I double click it you can see that this is a date time this is the universal date time format it comes from net and it is month days years and then an hour minutes and seconds in 12 hour format if you come from a different culture like me for example we write days first then month and we use a 24 hour format then we need to convert our current dates for example in Excel sheet to this date time format in order to compare that is the only way we can compare and one other thing it might be that you see the date time in here but you should get shown a different format based on your windows culture up here so these two can be different but it is this one that is the actual date time let me click close let's convert this date time to a text so we can use it in for example an email you will find a invert date time to text down here and drag it in here the date time to convert that will be the current date time so I click this x double click the Q and date time we will just use a standard format and in here we can specify what format we will have right now only be a short date I can click this drop down and here I could for example say full date time long time then I will have the days in uh Tuesday and then May 19th and again a 12 hour format it will produce a variable this action called format date time so when I click save here and I run the robot if I double click the format of date time we have formatted time again if I open up this convert date time to text by double clicking it these standard ones they are quite limited they will be quite us oriented but what we can do here is to click this drop down here and choose custom then we can specify our own python for example let's create the way we write date and time here in Denmark so I can use it in email so I'll write to these that will be days a forward slash two begins forward slash or wise that will be years then space hours colon and minutes this is the net custom date time format you can easily Google it and learn everything about it it's very easy especially if you use it in Excel you don't have to use these forward slashes by the way you can also just say I want this daytime format but let's try to click save try to run the robot and see that we can actually format the current date time to a formatted daytime I double click it now you can see we formatted it to a text value we can use it in email or write it too Excel click close here again you can press this one here now try to click control on the last one on your keyboard click with your mouse that marks both of them right click disable actions a list is a collection of items of the same variable type bid as a single Dimension array in programming terms if I go up here we'll actually have a native action for creating a list so if you write create new list find it here and drag it in here let's give our list a name we will call it the part means and click save so if I run my robot now I click run we will just create a new list you can see it over here it looks quite empty and if I double click to open it you can see that this is a list of General values it's completely empty you don't see anything down here let's put something in it so I'll click those here I'll go up to actions and then I'll find an add item to list drag it in here what do I want to edit let's add in Finance into the list again use the variable picker out here so take this x departments or click save now try to run your robot once more you can see that if I double click over here we now have a list of text values and we have Finance as the first item it's important to say that lists are zero index that means that this first item has index 0. that is a little bit weird if you're using to know that the first item is always one two but in programming terms it is zero index so when we want to refer to finance that is index 0. let's click close let's add a couple of other items I have another add item to list this one will be called ID I have the Departments here I'll click save let's also add a human resource so I'll say human resources it will also go into my departments I'll click save try to run it again that's it if I go over to departments we can see that we now have three items in our list and it's index 0 1 2. I'll click close to write out a specific element in our list we can use the index number go up here and then find a display message a display message is very simple it just pauses the robot and reads a message to the user let's see it in action go up to message to display so we want to look into the Departments list like this x double click the Departments go in here we want to have the it out that was index one a mega hard bracket start say one a hard bracket in like this I also want to say keep message box always on top that means that this will go forward this message box in a little while over our other programs the variables produced is called button pressed we will not use it for now click this Arrow best practice is to always disable the variables that you don't use so you don't confuse yourself so Tim will just untick it here and click save now go run your robot that's it we have printed out ID we can also iterate through each element in a list find it for each up here yep and drag it in yeah so value to iterate that will be departments yeah double click it I also want to say store into q and item that is once we iterate we can refer to the current item in current item but let's call it current Department again we do this because best practice is to give our variables a meaningful name so now it says current Department I'll click save so we're entering through each department in departments let's drag the display message down here and let's go fix it so I double clicked now delete this and we'll refer to the qn department click the sex you're in Department I'll click save try to run your robot once more that is finance I.T and Human Resources we iterate the list instead of having to create a new list and add three items to the list we can actually create this list with just one action so go up to actions find a said variable and drag it in here just before for each we will give it a name departments so I'll double click to departments and then I'll create a list here a list in a set variable is getting created by two percentage signs I'll have a hard bracket start I'll have a hard bracket and that's it and again the spaces those will be ignored by runtime but it makes it easier for you to read let's put our items in the list so we'll have a single quotation marks I'll say Finance single quotation mark armor single quotation mark it Palmer and then I will say human resources oh human resources like this this is how a list is going created you can also instead of hard coding these you could use variables from early underflow by picking them here in the variable picker we will not we will just click save here that means that we can mark this create new list press shift on our keyboard and mark the last add item the list right click disable actions click run once more this will be the same flow that we just built we just created the list with one action instead of four there's nothing wrong by using the native power automate desktop actions sometimes getting to know these set variables these workarounds will make your flow more efficient but please use whatever you prefer especially here in the beginning data tables contain data in tabular form just like an Excel sheet rows and columns the data table is a collection of data rows let's go create one so I go up to actions here and I'll find a create new data table and drag it in here in the end you can see now that our table has zero rows and zero columns and the name is called data table let's first rename this I'll call this one employees tip and we will go up here and click edit we want to have some data in we will have a two column data table so I can double click the column one and I can write name double click the column two and then I can write gallery let's fill in some data so in here I will have Anna her salary will be 72 000. we will add more rows so I'll click this plus two times and then I can add more data I will also give her a salary six thousand 67 500. again you can jump between these if you click enter here you can see I can jump with the arrows if you prefer that instead and simply just start writing here I can say Clara and I can have it out here I can say 76 000 like this so this is my data set click save click save run it again if I go over here to employees and double click first of all you can see that this is a data table that was what we expected you can also see that we have our three rows and two columns again it's your indexed that means if we want to refer to the first row we will say index 0 second row index one the third row index two I'll click close let's try to get the second row that was Becky so find a display message again a display message pauses the robot and display it's to the user the message to display I want to get the first row from here so then I'll click X double click the employees and go up here simply just in a hard bracket write in one that will be the second row keep message box always on top and we will disable this button pressed since we're not going to use it I'll click save run it once more now we got the Becky row out clicked okay that's it now I want to write out Becky's salary and that's inspect the data table once more so we are writing out this entire row I just need to specify the actual column and we can see here that this is the first column this is the second one and again these columns are zero indexed so this will be 0 and 1. I can click close here so try to open up the display image once more go in here have a hard bracket start and here I'll say one and a hard bracket end then I can click save try to run it once more that's it we got back his salary printed out I can click ok another thing we could do to make it even more stable was to double click the display message instead of giving the index of the column we can give out the actual header I can say salary and here it's important to have it in single quotation marks that is because this is not a variable so the employees was a variable that was the data table variable so that one is not in percentage sign but the salary that was a text that was the column header that we're trying to refer to that's why it will go into single quotation marks click save click run this will just print out Becky's salary once more but we refer to it by the name we can also iterate through a data table we will do that with a for each so we'll drag it down here we will iterate through the employees so go find it again we'll rename the store enter that will be the referral for the current item that will be current employee in our case we'll click save and scroll a little bit down it's here drag in the display message if I've run this that means that this for each will Loop through each row in employees that will be three rows so this will run three times and then it will just display this static message all three times so what we need to do is to refer to the current employees instead double click the display message delete this click the xia double-click the current employee that's it I can click save we can run it once more so here we are printing each run of the rows out like this let's say that I want to get a specific column that could be the salary again so I go into the display message I go here since this is only a row we don't need a row in referral right now so we can just skip to the column referral here we could either say index one or as we did before a salary like this in hard brackets and remember the single quotation marks then I can click save click run up here so here we are getting the salaries out that is nice imagine that we're getting these salaries into a system we can also add the names then we had the solution there up here in the qn employee if I double click this this is the last one of these rows that we iterated through that will be Cloud so this is our data row looks like and that's also in line what we talked about in the beginning that a data table was a collection of data rows then we'll click close let's try to create our data table with a set variable instead it gives us flexibility when we create more advanced flows go up to actions find a bit variable and drag it in here we will again create the employees we will create it with the data just as we used RPM to create new data table again you will need a percentage sign in the start and in the end we'll go in here we'll also need a curly bracket start and a curly bracket end let me make some spaces so it's easier to read to create the rows we will go in here these curly brackets and have a start bracket and an N hard bracket so here we can create a row let's just go in here let's create the first row that was Anna in single quotation marks in a comma separated then we will say that was 72 000 like this so this is a one data Road data table let's just try to see if this works so if I click save here we will also disable this create new data table so I right click here disable actions now we will iterate through the employees data table it'll only be one row in it and look we have no salary column so this will actually fail what we can do is simply just double click the display message and refer to the salary column bytes index now we'll use the one we'll click save try to run there you go that was a salary we can create the entire data table so if I double click this set variable we will create the other two data rows so that'll be a comma then we'll say Becky and single quotation marks common and back is salary that was 67 500. and a hard bracket end the last row that will be Lara like this then we will have her salary that was 76 000 like this so we could actually because these are numericals we didn't have to make these single quotation marks around them but it's often more easy to treat them as text and when we want to use them we simply just convert it that's it now we just need to hit a row we will have it in front here so let's have a start add bracket then in single quotation marks we'll say name single quotation mark then a comma and again in single quotation marks we will have the salary an end hard bracket the comma two specify that this is a header row we go in front and make a hat like this try to click save if you get an a-roll you have put in a comma wrong or maybe a single quotation mark make sure you write it let me double click it directly as you see it here otherwise it will not work now we can of course refer to column one that will be these three salary columns but we can also use the salary now since we have a header I can click save here I can run the robot again we will just print out these salaries just as before nothing changes and if I go into employees you can even see that a data table looks exactly like before we have the name salary index fuel one two then click loads again click here press shift on your keyboard click here right click disable action the custom object consists of key value pairs it's easy to convert to jsons and let's go create one we will use another set variable for this go up here in variable so I'll say currency and we will create the actual custom object here again you know the drill we will have the two percentage signs then we go in here we will have a curly bracket start we'll also have a curly bracket end like this to put it in here we will say US dollar in single quotation marks then we will say a colon and then we will have the currency rate that could be 761.63 and then another single quotation mark so this will be the first key value pair if you know dictionary from other programming languages this works exactly the same later on in the flow we can call US dollar just like a dictionary and get the value back let's add some more values that will be comma separated so here it could be the hero like this I'll say colon and then I'll say 743.66 and again we will have the last item we'll have the Indian rubies and again when you click save here in a few seconds if you get an arrow that is because you have written in something wrong just make sure that your currency also look like this I can click save we get no Arrow so this is our custom object if I try to run it we got it initialized over here I can double click it you can see this custom object we have a name that is the USD Euro and engine Ruby and we have a value to use it in the flow say that we want it to get to Euro rate then we can have a display it should show over here drag it in here the message to display we will need to look inside the currency so I'll say UNC then I'll go in here and we wanted to get the Euro out so that'll be that'll be hard bracket single quotation marked and then the EUR that was the trigger that we used in our custom object like this keep message box always on top variables produced let's disable it we're not going to use it so this is a good habit it's not necessary your robot will work fine if you forget it but let's try to do all these best practices right from the start that will help you a lot when you create more advanced robots click save now try to run it there you go that is the Ural currency rate 743.66 let's also try to do a calculation so double click this display message in front of the percentage sign say one euro is and then we have this calculation divided by 100 and then you say Danish Kronos so these are Danish Kronos currency rate I come from Denmark so that's why I use it click save try to run it once more there you go it's that easy click OK Network and get help to your power automate desktop Solution by joining the I love automation Discord right here your next lesson is here
Info
Channel: Anders Jensen
Views: 7,176
Rating: undefined out of 5
Keywords: power automate desktop, variables, text, text variables, numerical, boolean, datatime, list, datatable, custom objects, microsoft power automate desktop, anders jensen, tutorial, using variables in power automate desktop, how to use variables in power automate desktop, power automate desktop tutorial
Id: IurF01TE-0E
Channel Id: undefined
Length: 36min 23sec (2183 seconds)
Published: Mon Apr 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.