cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ontheclock
Frequent Visitor

Create multiple rows from one list item depending on date range

I have a Microsoft List where staff enter the dates they are on leave. 

Note: The dates in MS List are in American format

 

LeaveListScreenshot.PNG

I'm trying to create a flow that checks the MS List above and creates multiple entries in Excel depending on the Leave Start Date and Leave End Date. The flow needs to add a row for each working day (Mon-Fri) between those dates excluding weekends as seen below;

LeaveDates.PNG

I can create a flow that enters the working days into excel from MS List but stops adding entries when it gets to the weekend (pictured below)

PowerAutomateExample.PNG

Can this be achieved in Power Automate and if so how? 

11 REPLIES 11

@ontheclock First you'll need to create an array of dates between your Leave Start Date and Leave End date. I'm not sure what the trigger of your flow is. However, for the demo below—I'll be using a manual trigger and a Get Item action to get a specific item from the SharePoint list. You can do the same for your case and once your flow is ready to go you can adjust the trigger if needed.

 

Remember to rename your actions to keep your flow organized. Test often so you can troubleshoot early before you build out your entire flow.

 

For more flow troubleshooting tips—check out This YT Tutorial: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows

In this tutorial I cover:

 How to troubleshoot a false Condition action result

 How to get dynamic content when it isn’t selectable from the list of dynamic content

 How to troubleshoot an Apply to Each action that isn’t looping through

 How to troubleshoot a skipped Apply to Each action

 How to troubleshoot a Filter Query

 How to use a SharePoint yes/no column in a Filter Query

 How to use Compose actions to troubleshoot a Power Automate flow

How to troubleshoot multiple emails being sent

 How to troubleshoot multiple Teams messages being sent

 

Get Item

Add a Get Item trigger and insert the ID of an item in your SP list for testing purposes.

creativeopinion_0-1704251565513.png

 

Initialize Array Variable

Initialize an Array variable to store the dates. You'll need to set the array upon initializing the variable with the start date.

creativeopinion_1-1704251677372.png

Insert an expression between the square brackets. Use the formatDateTime() function. 

creativeopinion_2-1704251728296.png

Select the dynamic content tab and insert the Leave Start Date dynamic content from the Get Item action.

creativeopinion_3-1704251798110.png

Add a comma, single quotes and insert your date format.

creativeopinion_8-1704252115886.png

creativeopinion_9-1704252135134.png

 

Run a test. Verify that the variable contains the leave start date in the format you've specified.

 

creativeopinion_10-1704252155624.png

 

Initialize an Integer Variable

Initialize an integer variable. Set the value to 0.

creativeopinion_5-1704251855758.png

 

Get the Number of Days Between Two Dates

You'll need to get the number of days between two dates. Use an expression:

div(sub(ticks(LeaveEndDate), ticks(LeaveStartDate)), 864000000000)

Replace the text in blue in the expression with the appropriate dynamic content from the Get Item action. 

creativeopinion_6-1704251907426.png

 

Run a test. Verify the Compose action is outputting the correct number of days between your two dates. Keep in mind that this expression will return the number of whole days between the two dates but does not include the start date itself in the count which is why the start date was added to the array upon initialization.

creativeopinion_11-1704252183880.png

 

Create Dates

Add a Do Until action. In the first value field, insert the Integer Variable. Leave the operator as is equal to. In the second value field, insert the outputs from the Compose action above.

 

The Do Until action will loop through until the integer variable (varIndex) equals the number of days in the Compose action above. In this case it will loop through 7 times.

creativeopinion_14-1704252430687.png

Add an Increment variable action. Select the integer variable and set the value to 1. This action will increment the variable by 1 each time the Do Until action loops through.

creativeopinion_15-1704252517761.png

Generate the Date to Add to Array

Add a Compose action. We'll use this action to store the Date you'll be adding to the array. 

creativeopinion_16-1704252621445.png

We'll need to add days to the Leave Start Date each time the Do Until action loops through. Insert an Expression and use the addDays() function.

creativeopinion_17-1704252726293.png

 

The addDays() function takes two parameters. A date and the number of days you'd like to add/subtract from a date. Use a positive number to add days, and negative to subtract.

 

Select the Dynamic Content tab and insert the Leave Start Date dynamic content from the Get Item action.

creativeopinion_18-1704252786374.png

Add a comma and insert the varIndex (integer variable). Each time the Do Until action loops through it'll add the number in the variable to the Leave Start Date.

 

creativeopinion_19-1704252854403.png

 

Wrap this expression in a formatDateTime() function. Go to the start of the expression by pressing the UP arrow key and type in formatDateTime with an opening parenthesis.

creativeopinion_23-1704253206839.png

 

Go to the end of the expression by pressing the DOWN arrow key and add a comma and single quotes. Between the single quotes type in your date format.

creativeopinion_24-1704253252826.png

Run a test. Verify the Compose action output.

creativeopinion_25-1704253430239.png

 

Get the Day of the Week

Add a Compose action.

This Compose action is optional—however, I prefer using a Compose action to store a value I'm using in a Condition action to help with troubleshooting.

 

creativeopinion_20-1704252965890.png

Insert an expression and use the dayOfWeek() function. This function will return the day of week as an integer that represents the day of the week, where Sunday is 0, Monday is 1, and so on up to Saturday, which is 6.

 

creativeopinion_21-1704253003114.png

Click on the Dynamic content tab and insert the output from the Compose action above. Note: This is why it's important to name your actions!

creativeopinion_22-1704253082116.png

 

Run a test. Verify the Compose action output.

creativeopinion_26-1704253454383.png

 

Condition Check

Add a Condition action. You'll use this action to check if the date is a weekend day before appending it to the array of dates.

 

Add two conditions to your flow. Ensure you are using the And operator. In the first value field insert the output from the Compose action above. Change the individual condition operator to is not equal to. In the second value field, enter 0 and 6.

 

This condition action will check to see if the date is a Sunday or Saturday. If the date does not fall on the weekend, it'll continue with the actions you place in the YES branch.

creativeopinion_28-1704253496420.png

 

In the YES branch, insert an Append to Array Variable action. Select the variable and insert the output from the Date to Date Compose action. 

creativeopinion_29-1704253591282.png

creativeopinion_30-1704253665056.png

Add a Compose action outside of the Do Until action to store the variable so you can review the output.

 

creativeopinion_31-1704253703328.png

Run a test. Review the output of the Compose action.

creativeopinion_32-1704253744713.png

 

Apply to Each

Add an Apply to Each action to loop through each date in the array variable. Add any additional actions into the Apply to Each loop.

creativeopinion_33-1704253816174.png

Hope this helps!


If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response!

👉 Watch my tutorials on YouTube
👉 Tips and Tricks on TikTok

 

ontheclock
Frequent Visitor

Thanks for the indepth support for this question creativeopinion. I have attempted to create this flow using a 'when an item is created or modified' trigger.

PAFlow.PNG

I cant get past the first Do Until and received the following error message

PAFlowError.PNG

 

Appreciate your support

@ontheclock It's hard to say without being able to see your expression. The error is indicating that the value you are passing isn't a timestamp. Please upload a screenshot of your expression.

Please see below;

 

FlowError.PNG

@ontheclock Looks like you are missing the closing parenthesis for the addDays() function. Right before the comma.

creativeopinion_0-1704386755647.png

Hope this helps!

I thought so too but when I add the closing parenthesis and try to update PA says the expression is invalid

 

formatDateTime(addDays(triggerOutputs()?['body/LeaveStartDate']),variables('varIndex')),'dd/MM/yyyy')
 
Thanks

@ontheclock Sorry, I missed this... you have an extra closing parenthesis here:

creativeopinion_0-1704406339837.png

Your correct expression should be:

formatDateTime(addDays(triggerOutputs()?['body/LeaveStartDate'],variables('varIndex')),'dd/MM/yyyy')

 

Thank you! The flow is running without errors but the inputs in excel aren't correct. It also seems to have not included the 09/01/2024, 12/01/2024 and added 07/01/2024 which is a weekend? (the leave dates I inputted in MS List was 05/01/2024 - 12/01/2024)

 

ExcelError.PNG

I would like the 'Leave Date' column to generate only one date per row like below

ExcelRequest.PNG

Here is an overview of my flow

FlowOverview.PNG

Here is my Apply to Each 

ApplyToEachv2.png

@ontheclock You need to understand the logic of how you set up your flow to understand what the cause of your issue. To do this, you need to review the outputs of your flow run. As recommended in my original post you should be running a test at each point (where I recommended to run a test). It's a lot easier to troubleshoot your flow while you are building it than trying to build it all at once and troubleshoot it after.

 

First check that the initial array item has been set properly.

creativeopinion_2-1704420240041.png

 

Then, check that your Integer variable has be set to 0.

creativeopinion_3-1704420265528.png

 

Confirm the Day Difference in the Compose action to ensure that is what you are expecting. Remember that this expression will return the number of whole days between the two dates but does not include the start date itself in the count which is why the start date was added to the array upon initialization. For this example, you are expecting 8 days between the two dates, however the number of whole days between is actually 7. This is fine since you'll be appending the last date to the array anyway.

creativeopinion_4-1704420300103.png

 

Next, check that your increment variable is incrementing by one. The value should match the current apply to each number. Each time the Apply to each action loops through, it should add one to the value.

creativeopinion_5-1704420440811.png

 

Next verify the dates, the dates in the Compose action should only be incrementing by ONE DAY. These dates should include the weekend days as the weekend days will be filtered out by the condition.

creativeopinion_6-1704420497147.png

 

You need to ensure that the Compose action is outputting the correct number for the day of the week. 0 for Sunday, 1 Monday..... etc and 6 for Saturday. 

creativeopinion_7-1704420574564.png

 

Next, verify the Condition action and ensure that if the date is a weekend day (eg. 0 for Sunday or 6 for Saturday) that the Condition outputs false. A date will only be appended to the variable if the Condition action returns true.

creativeopinion_8-1704420617607.png

Before you even add the Apply to Each action to your flow, you should verify that the dates in the Compose actions are correct and that no weekend dates are included. If this is not the case, and weekend dates are included you need to troubleshoot your flow first before you continue to build out your flow. 

 

For more flow troubleshooting tips—check out This YT Tutorial: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows

creativeopinion_9-1704420702703.png

 

The reason why you are getting the output in your Excel row is because of the dynamic content you inserted into the Leave Date. You inserted the output of the Compose action that has the array of dates (refer to screenshot above). This is why each row in your Excel is displaying all the dates and not the current date being looped through.

creativeopinion_0-1704419881062.png

 

The way the Apply to Each action works is it's looping through each item in an array. For more tips and tricks on how to use the Apply to Each action refer to this YT Tutorial: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow 

 

What you need to use instead is the Current Item dynamic content. To better understand what the Current Item is (because the output will differ based on what you are looping through in the Apply to Each action). Add a Compose action and store the Current Item value and run a test.

creativeopinion_10-1704420908506.png

Because you have a Do Until and an Apply to Each action loop in your flow—ensure you are selecting the correct Current Item dynamic content.

 

Run a test to verify the output. By running tests often it makes it easier to troubleshoot. Use Compose actions throughout your flow to help you troubleshoot but also to understand the logic of your flow.

creativeopinion_11-1704421033862.png

 

 

I've reviewed the outputs of my flow and found the issue. The flow is identifying 09/01/2024 (Australian Date Format) as the 1st of September (01/09/2024 American Date Format) which is not a weekday. I've changed the regional settings in MS List to the correct timezone but still not working correctly. Would you work around this using a convert time zone action?

A slightly more elegant way to create this date array (that also handles holidays):

https://powerusers.microsoft.com/t5/General-Power-Automate/Working-day-difference-between-2-sharepoi...

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

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!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

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  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

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.    

Updates to Transitions in the Power Platform Communities

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

Users online (848)