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)
)
)
)
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
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
)
)
I hope this helps 🙂
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional