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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Wrong counting of days
Power Apps
Answered

Wrong counting of days

(0) ShareShare
ReportReport
Posted on by 290

Hey, I have this code 

 If(
 Weekday(
 StartDate.SelectedDate;
 StartOfWeek.Monday
 ) = 6 Or Weekday(
 StartDate.SelectedDate;
 StartOfWeek.Monday
 ) = 7 Or Weekday(
 EndDate.SelectedDate;
 StartOfWeek.Monday
 ) = 6 Or Weekday(
 EndDate.SelectedDate;
 StartOfWeek.Monday
 ) = 7;
 "You can't choose weekend";
 EndDate.SelectedDate < StartDate.SelectedDate;
 "Wrong order of days";
 (RoundDown(
 DateDiff(
 StartDate.SelectedDate;
 EndDate.SelectedDate;
 Days
 ) / 7;
 0
 ) * 5 + Mod(
 5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate);
 5
 ) + 1 - If(
 LookUp(
 Employees;
 NameOfEmployee = User().Email
 ).Title = "NOARKCZ";
 CountIf(
 Holidays;
 DateOfHoliday >= StartDate.SelectedDate;
 DateOfHoliday <= EndDate.SelectedDate
 );

and im working with this:

Filistyn_0-1639384774308.png

basically you choose Vacation between two dates and it will calculate how many days are between the dates. "Holidays" is a Sharepoint list, where I've listed all the holidays. It also excludes weekends. It works perfectly, but over Christmas it doesn't seem to work. 

 

Any idea why?

 

Categories:
I have the same question (0)
  • Filistyn Profile Picture
    290 on at

    I think that the problem seems to be, that if there is a difference, between two dates and the day, where the holidays are, are also weekend, it will subtract it as a 2 days, because the code thinks, that the day is weekend and also holiday.

  • Verified answer
    v-JessicaG-msft Profile Picture
    Microsoft Employee on at

    Hi @Filistyn ,

     

    You could exclude holidays and weekend overlapping days from your count. I have test for your reference, please try the following workaround:

    vJessicaGmsft_0-1639654640907.png

    Formula:

    RoundDown(
    
     DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) / 7, 0) * 5 +
    Mod(5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate), 5) +
     CountIf(
     Holidays,
     DateOfHoliday >= StartDate.SelectedDate,
     DateOfHoliday <= EndDate.SelectedDate,
     ( Weekday(DateOfHoliday,Monday)=6 || Weekday(DateOfHoliday,Monday)=7)
     )
    

     

     

    Best Regards,

    Jessica Gu

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 401 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard