Hey everyone,
I am trying to record a desktop flow on my company's legacy app that will help automatically download certain reports we need multiple times a day.
I have been able to work through a majority of the steps and most of my reports are able to be downloaded automatically. I have one problem however. I have my flow work through a few certain steps and fills out prompts for my specific location, buyer information, dates, etc. However, I have run into the problem where I am asked to enter "Today's Date" or a specific set of dates with some of the reports. I am writing to see if anyone knows how I can have my flow dynamically change the date to today's date or a set of dates, so I do not have to go through everyday and change it to the current day's date.
Thank you, I understand if this is a relatively confusing question so please ask any clarifying questions, any help is much appreciated!
Solved! Go to Solution.
Use the Get current date and time action to get the date for today.
Then use Add to date time to calculate whatever you want. Even though the action is called 'Add', you can also add a negative amount of days or months, effectively subtracting a value and thus calculating a date in the past.
For example, using Add to date time and adding -%CurrentDateTime.Day% days to %CurrentDateTime% (the latter being the output of Get current date and time) would give you the last day of the previous month. A datetime type variable has properties for .Day, .Month and .Year that allow retrieving various kinds of values and making various calculations for whatever you need.
Anything more specific than the above would require that you provide the types of dates to be calculated.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
The following set of actions could do the trick:
Here's a snippet that you can copy and paste directly into PAD to create these actions automatically:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
SET StartDate TO $'''%''%'''
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\RPA\\DatesList.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
Variables.RetrieveDataTableColumnIntoList DataTable: ExcelData ColumnNameOrIndex: $'''Date''' ColumnAsList=> DateList
Variables.SortList.SortList List: DateList
LOOP LoopIndex FROM DateList.Count - 1 TO 0 STEP -1
IF CurrentDateTime > DateList[LoopIndex] THEN
SET StartDate TO DateList[LoopIndex]
EXIT LOOP
END
END
NOTES
Input file
I just created a very simple Excel file with a single column called 'Date' and the dates there:
That's why I use 'Date' in the Retrieve data table column into list action to get the dates into a list. If your column will be named anything else, you might need to change that in the action.
Retrieving the column
The Retrieve data table column into list action is needed because Read from Excel worksheet will return a table by default, but you need a list to be able to use the Sort list action.
Sorting the list
The Sort list action sorts ascending by default and you cannot change that, unless you enable sorting by item properties. Since I assume the text in Excel to be strings, those do not have valid properties to sort by, so I kept the default and then in the Loop action, I made the flow go backwards from the last item to the first one. This way I start with the latest date and use Exit loop as soon as I find the first date that is lower than the current date.
Date format
The dates in my Excel file are actually formatted in a way that Excel recognizes as date values. This results in PAD also recognizing the values as dates. So, I do not need to convert them to dates and can in fact compare them with the current date right away. However, if your dates are interpreted as strings, you might need to use the Convert text to date time action inside the Loop before using the condition, so that you have two dates to compare, instead of comparing a date to a string (which would result in a type error).
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
Here you go:
https://www.linkedin.com/pulse/power-automate-desktop-pad-best-practices-part-1-date-michael-annis?t...
Best of luck!
Use the Get current date and time action to get the date for today.
Then use Add to date time to calculate whatever you want. Even though the action is called 'Add', you can also add a negative amount of days or months, effectively subtracting a value and thus calculating a date in the past.
For example, using Add to date time and adding -%CurrentDateTime.Day% days to %CurrentDateTime% (the latter being the output of Get current date and time) would give you the last day of the previous month. A datetime type variable has properties for .Day, .Month and .Year that allow retrieving various kinds of values and making various calculations for whatever you need.
Anything more specific than the above would require that you provide the types of dates to be calculated.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
Thank you! This helps a lot. Another little aspect of this I have a question about.
I am also trying to have one of my flows enter two separate sets of dates in order to yield data from the current time period (ex: 20230701-20230707). Any ideas on how I can get that first date to stay the same for the month, but also move onto the next month when it comes around?
Thank you for your help
When you have the %CurrentDateTime% after using the Get current date and time action, you can use that for the current date (end of your period). You can then use Add to date time to add -%CurrentDateTime.Day-1% (minus the current day minus one, meaning if the current day is the 7th, you'd be deducting 6) to get the first day of the current month. That's the start of your period.
If you want them formatted in a specific format, you need to use Convert date time to text to convert them to a sting value that you can then use.
I figured out how to do this when it regards just the first day of the month. I am now wondering how this would work since these time periods I am needing do not always start on the first, (ex. June's month begins on 5/27, August begins on 7/29, September on 8/26). Do you know how this could work? I have it currently set to input the first of the current month, but would prefer it to go more along with our business calendar.
Again, thanks for your help
Is there some sort of a logic behind these dates? Does it always start on a specific weekday or something? If there is a logical explanation for the algorithm, it can be calculated automatically. If there isn't one, you will need to store a list of dates somewhere and then read that list via PAD and get the date that is applicable to the current period (latest date from the list that is still before the current date).
This would probably be quite tricky to calculate automatically. You could probably do it, but the logic behind the calculation would be quite complex, I think. It's not even that your year starts on the first. So, you would first need to find the first day of the year and then calculate the quarters and the months.
I would suggest storing the list of dates in some file, like an Excel sheet or even a plain text file. Then read it and find the latest date in there that is still before your current date. That would be the easiest to implement.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
What function/s do you think would allow me to extract the most recent date from the excel? Currently just have a separate sub-flow set up to open Excel and recognize the entities in the doc. Thought I'd have to create some sort of output variable but having some trouble doing so.
The following set of actions could do the trick:
Here's a snippet that you can copy and paste directly into PAD to create these actions automatically:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
SET StartDate TO $'''%''%'''
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\RPA\\DatesList.xlsx''' Visible: False ReadOnly: False Instance=> ExcelInstance
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
Variables.RetrieveDataTableColumnIntoList DataTable: ExcelData ColumnNameOrIndex: $'''Date''' ColumnAsList=> DateList
Variables.SortList.SortList List: DateList
LOOP LoopIndex FROM DateList.Count - 1 TO 0 STEP -1
IF CurrentDateTime > DateList[LoopIndex] THEN
SET StartDate TO DateList[LoopIndex]
EXIT LOOP
END
END
NOTES
Input file
I just created a very simple Excel file with a single column called 'Date' and the dates there:
That's why I use 'Date' in the Retrieve data table column into list action to get the dates into a list. If your column will be named anything else, you might need to change that in the action.
Retrieving the column
The Retrieve data table column into list action is needed because Read from Excel worksheet will return a table by default, but you need a list to be able to use the Sort list action.
Sorting the list
The Sort list action sorts ascending by default and you cannot change that, unless you enable sorting by item properties. Since I assume the text in Excel to be strings, those do not have valid properties to sort by, so I kept the default and then in the Loop action, I made the flow go backwards from the last item to the first one. This way I start with the latest date and use Exit loop as soon as I find the first date that is lower than the current date.
Date format
The dates in my Excel file are actually formatted in a way that Excel recognizes as date values. This results in PAD also recognizing the values as dates. So, I do not need to convert them to dates and can in fact compare them with the current date right away. However, if your dates are interpreted as strings, you might need to use the Convert text to date time action inside the Loop before using the condition, so that you have two dates to compare, instead of comparing a date to a string (which would result in a type error).
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
Wow this is awesome! I had some of those functions but was really struggling to figure out how to use them for this and how to get them to work. Entered this in as a subflow in mine and it seems to be working as of right now.
Thank you so much, this helped immensely!
One more little question for you:
I have my sample excel sheet of all the dates set up as follows:
When July 30th comes around, do you think I can leave this excel sheet the same and it will begin to pick the closest date to the current date, so that it will begin taking 7/30 instead of 7/2? Or do you think it will spark some sort of error or type in the right dates? I was thinking if it does end up doing this, then I can just end up trying to design a flow that deletes the top row or date furthest before today's date, and can just move down the line as time goes on.
I understand if you are not sure what will happen when the date comes around, I appreciate all the help you've given nonetheless.
The idea behind the flow itself is that it will loop through the sorted list backwards (from the latest date to the earliest) until it finds a date that is less than your current date, and then stop. So, you do not need to delete any dates. It should select the latest applicable date.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution.
If you like my response, please give it a Thumbs Up.
If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/
Dear Community Members, We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd. During this period, members will not be able to Kudo, Comment, or Reply to any posts. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!
We are excited to announce the Summer of Solutions Challenge! This challenge is kicking off on Monday, June 17th and will run for (4) weeks. The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities. Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”) - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024 Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods. You must enter into each weekly Entry Period separately. How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different. Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers. At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing. Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner. A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random. Individuals will be contacted before the announcement with the opportunity to claim or deny the prize. Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners. Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event. ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE** Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24 17 @Anil_g 7 @ManishSolanki 13 @eetuRobo 5 @David_MA 10 @VishnuReddy1997 5 @SpongYe 9JhonatanOB19932 (tie) @Nived_Nambiar 8 @maltie 2 (tie) @PA-Noob 2 (tie) @LukeMcG 2 (tie) @tgut03 2 (tie) Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate @Deenuji 12@ManishSolanki 19 @Anil_g 10 @NathanAlvares24 17 @VishnuReddy1997 6 @Expiscornovus 10 @Tjan 5 @Nived_Nambiar 10 @eetuRobo 3 @SudeepGhatakNZ 8 Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22 Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2 Anil_g2 SharonS2
On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners. The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights. Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.
We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for. We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer. Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together. Here's to new beginnings and endless possibilities! If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport. To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages