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 Apps / Counting wrong number ...
Power Apps
Answered

Counting wrong number of days

(0) ShareShare
ReportReport
Posted on by 20

Hi,

 

I used the next code. It's part of larger code that must calculate how many Mondays, Tuesdays ..ect there are in a Year without the holidays and weekends.

 

Sum(
  With(
    {
      // generate a one-column table of all dates between start date & end date
      varDateRange: ForAll(
        Sequence(DateValue(“3-27-2023”) – DateValue(“1-1-2023”) + 1),
        DateValue(“1-1-2023”) + Value – 1
      )
    },
    CountIf(
      varDateRange,
      Weekday(Value) in [2]
    )
  )
)

 

 

But I see a weird thing happen. With this code I mis 1 Monday in the Year 2023. After some research I saw that Monday 27th is not counted as the 13th Monday of the year. If I use the 28th or March or April 4th the total number will be 13. Was do I wrong.

 

Can someone help me with this problem?

Categories:
I have the same question (0)
  • developerAJ Profile Picture
    4,664 on at

    your format is wrong

    Sequence(DateValue(“3-27-2023”) – DateValue(“1-1-2023”) + 1)

     

    it should be 

    Sequence(DateValue(“27-3-2023”) – DateValue(“1-1-2023”) + 1)

     

     

  • Bosgraj Profile Picture
    20 on at

    Thanks for your reply.

     

    The format isn't the issue. I use US and Dutch format but both does not work.

    In my app I use two datepickers instead of the dates in this example which also gave the same result in both formats.

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Bosgraj,

     

    Your DateValue subtraction results in a decimal number that is rounded down before being served as the input to the sequence function. In short, you are missing a day in the Sequence array.

     

    In my opinion, the best way to calculate the difference between 2 dates is by using the DateDiff() function:

    Sum(
     With(
     {
     // generate a one-column table of all dates between start date & end date
     varDateRange: ForAll(
     Sequence(DateDiff(DateValue("1-1-2023"), DateValue("3-27-2023"),TimeUnit.Days) +1),
     DateValue("1-1-2023") + Value - 1
     )
     },
     CountIf(
     varDateRange,
     Weekday(Value) in [2]
     )
     )
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard