Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

count working days

(0) ShareShare
ReportReport
Posted on by

i have one datepicker ,i want to count no of working days, below code is working but showing data for FEB,APRIL,NOV month. how to fix this?

 

With(
{
varDateRange: ForAll(
Sequence(31,1),
Text(Month(DataCardValue4.SelectedDate) & "/" & Value & "/" & Year(DataCardValue4.SelectedDate),"DD/MM/YYYY")
)
},
// show only dates Monday to Friday and exclude holidays
CountIf(
varDateRange,
And(
Weekday(Value,StartOfWeek.Sunday) in [2, 3, 4, 5, 6],

Not(Value in Col_Holidaylist.Date1)
)
)
)

Categories:
  • Verified answer
    v-mingkz-msft Profile Picture
    Microsoft Employee on at
    Re: count working days

    Hi @venky232,

    Please try this formula:

    CountIf(
    Filter(
     With({targetMonth: Month(DataCardValue4.SelectedDate), targetYear: Year(DataCardValue4.SelectedDate)},
     With({startDate:Date(targetYear, targetMonth, 1), 
     endDate:DateAdd(DateAdd(Date(targetYear, targetMonth, 1),1,TimeUnit.Months),-1,TimeUnit.Days)
     },
     ForAll(
     Sequence(DateDiff(startDate,endDate,TimeUnit.Days)+1), 
     Date(targetYear, targetMonth, Value)
     )
     )
     ),
     Weekday(Value) > 1 And Weekday(Value) < 7 
    ),
    Not(Value in Col_Holidaylist.Date1)
    )

     

     

    Best Regards,

    Kyrie

  • Sundeep_Malik Profile Picture
    6,480 on at
    Re: count working days

    Hey @venky232 

     

     

    Actually the expression/formula/function you are using has the days set to constant 1-31, but number of days vary from month to month

    To fix this, you can use a more dynamic approach that generates a sequence of dates for the entire month and then filters out weekends (Saturday and Sunday) and holidays. Here's how you can achieve this:

     

    With(
    {
    varStartDate: StartOfMonth(DataCardValue4.SelectedDate),
    varEndDate: EndOfMonth(DataCardValue4.SelectedDate)
    },
    CountIf(
    DateAdd(varStartDate, Value, Days),
    Weekday(DateAdd(varStartDate, Value, Days), StartOfWeek.Sunday) in [2, 3, 4, 5, 6] // Monday to Friday
    && Not(DateAdd(varStartDate, Value, Days) in Col_Holidaylist.Date1) // Exclude holidays
    )
    )

    •  varStartDate stores the first day of the selected month and varEndDate stores the last day of the selected month.
    • CountIf function to count the number of dates in the range between  varStartDate and varEndDate that meet the specified conditions.
    • DateAdd function generates a sequence of dates from varStartDate to varEndDate based on the sequence number (Value) passed to it.
    • Weekday function is used to check if the date is a weekday (Monday to Friday) and filter out weekends.
    • Not function excludes dates that are present in the Col_HolidayList.Date1 column, which presumably contains the list of holidays.

     

    I hope this helps 🙂

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard