web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Subtract Days off from...
Power Automate
Suggested Answer

Subtract Days off from a Date Range

(1) ShareShare
ReportReport
Posted on by 6
Hello all, 
 
I am collecting data from a PowerApps App for employee day off requests. Right now they select a start and end date to create a date range, and that date range is sent to a Sharepoint List via Power Automate HTTP request to SharePoint. That all is working fine, however, we also need to have it subtract the employee's days off so that their scheduled off days are not included in the calendar entry. We have a separate entry on PowerApps that collects which days they have off, but now we are having issues figuring out how to send it to the sharepoint calendar without including those days. 

I'm not sure if this is even possible to do, but any assistance would be appreciated. Please let me know what more information you may need to assist. 
 
Thanks!
Categories:
I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at
    Hi,
     
    If there is a seperate entry in power apps where user can enter how many days will be off- why can't it be passed to power automate and subtract it from date range itself - i hope start and end dates are passed from power apps to power automate & further calculation are done in power automate.
     

    Thanks & Regards,
    Nived N 
    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs
     Found my answer helpful? Please consider marking it as the solution!
     Your appreciation keeps me motivated. Thank you!

     
  • JD-12102249-0 Profile Picture
    6 on at
    Forgive me, i am fairly new to this so It may need to be explained exactly what may need to be added and where. 

    Right now this is how the body of the HTTP request is formatted.


    We collect a start date, end date, and specific days of the week they have off on their schedule. So for example it could be a start date of 10/27/2024 (Sunday) and end date of 11/2/2024 (Saturday), then say Wednesday and Thursday is selected. So we would need only Sunday, Monday, Tuesday, Friday and Saturday to be added to the calendar, excluding Wednesday and Thursday. 

    I am not too sure of how to subtract specific days from the date range? 
  • AlexEncodian Profile Picture
    4,409 Moderator on at
    You could try logic like this. 
     
    In this example, lets assume integers are dates. You start with a range 1-10 and want to exclude 5,8 and return 1-4,6-7,9-10
    • Initialize Variables:

      • Create a variable varStartDate (type: Integer) for the start of the range (e.g., 1).
      • Create a variable varEndDate (type: Integer) for the end of the range (e.g., 10).
      • Create a variable varExclusions (type: Array) containing the exclusion days (e.g., [5, 8]).
      • Create a variable varResult (type: Array) to store the final result (empty array).
    • Apply a Loop to Iterate over the Date Range: Use a Do Until loop or Apply to each to iterate through each day in the range varStartDate to varEndDate.

    • Condition to Check for Exclusions: Inside the loop, use a Condition action to check if the current day is NOT in the exclusion list. If true, append that day to varResult.

    • Final Output: Once the loop finishes, you will have an array in varResult containing all the days that are not excluded.

  • Suggested answer
    Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at
     
    Compose
     
    {
    "StartDate": "2024-10-27",
    "EndDate": "2024-11-02",
    "ExclusionDays": [3,4]
    }
     
     
    Select
     
    From:
    range(
    	0,
    	add(
    		if(
    			contains(
    				dateDifference(
    					outputs('Compose')['StartDate'],
    					outputs('Compose')['EndDate']
    				),
    				'.'
    			),
    			int(
    				first(
    					split(
    						dateDifference(
    							outputs('Compose')['StartDate'],
    							outputs('Compose')['EndDate']
    						),
    						'.'
    					)
    				)
    			),
    			0
    		),
    		1
    	)
    )
    Map Date:
    addDays(
    	outputs('Compose')['StartDate'],
    	item()
    )
     
    Map ExclusionDay:
    contains(
    	outputs('Compose')['ExclusionDays'],
    	dayOfWeek(
    		addDays(
    			outputs('Compose')['StartDate'],
    			item()
    		)
    	)
    )

     
     
    Filter array
     
    From:
    body('Select')
    Filter:
    item()['ExclusionDay']
    is equal to
    false
     
    Compose 2
     
    length(body('Filter_array'))
     
     
    The output of "Filter array" contains the dates, "Compose 2" outputs the count. 
     
  • JD-12102249-0 Profile Picture
    6 on at
    This all has been great help so far, however, I am still getting stuck in a few places. 
    1.  For Exclusion Days, I have got a conversion to numbers now, so when specific days of the week are chosen on PowerApps, it'll send it as a number to the Power Automate Flow. But now, those numbers are appearing as a string, instead of an integer. I've tried a few things to convert it to an integer, but then I can't get it to be in the right format. Because of the integer issue or the formatting issue, the Filter Array step is marking everything as false. 
       
    2.  I am also having trouble figuring out what to do with the output dates from the Filter array. I am not sure how to correctly send the data to my sharepoint calendar/list. The example i've been using is a request from 10/20 - 10/26 but days off equal Wednesday, Thursday, Friday. I then need the dates of 10/20, 10/21, 10/22, and 10/26 to be marked off on the calendar. However, no matter how I try to add the data, it fails. 
    Thank you so much for all of the help so far, I'm still learning and appreciate everyone that has helped me get this far. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard