How to Calculate Business Days Excluding Weekends in Power Apps?
In Power Apps, to calculate the Business days excluding the Weekends and your week start with Sunday, you have to use the below formula
Set(
Duration,
With(
{
varDateRange: ForAll(
Sequence(
DataCardValue30.SelectedDate - DataCardValue29.SelectedDate + 1
),
DataCardValue29.SelectedDate + Value - 1
)
},
If(
And(
IsBlank(DataCardValue29.SelectedDate),
IsBlank(DataCardValue30.SelectedDate)
),
0, // Return 0 if either date is blank
CountIf(
varDateRange,
Weekday(Value, StartOfWeek.Sunday) in [1, 2, 3, 4, 5] // Sunday = 1, Friday = 6, Saturday = 7
)
)
)
)
Breakdown of the Formula:
This sets a variable called Duration
to store the final result.
Set(Duration,
This creates a temporary variable varDateRange
that holds a table of all the dates from the start date to the end date.
With(
{
varDateRange: ForAll(
Sequence(DataCardValue30.SelectedDate - DataCardValue29.SelectedDate + 1),
DataCardValue29.SelectedDate + Value - 1
)
},
If either start or end date is blank, return 0 as the duration. (No valid input = no calculation.)
If(
And(
IsBlank(DataCardValue29.SelectedDate),
IsBlank(DataCardValue30.SelectedDate)
),
0,
This part filters the dates to only count working days.
CountIf(
varDateRange,
Weekday(Value, StartOfWeek.Sunday) in [1, 2, 3, 4, 5]
)
And the Weekday(Value, StartOfWeek.Sunday)
returns the day number (1–7) with Sunday as the first day of the week:
- Sunday = 1
- Monday = 2
- Tuesday = 3
- Wednesday = 4
- Thursday = 5
- Friday = 6
- Saturday = 7
So, this includes only days 1 to 5, from Sunday through Thursday = working days in most Gulf countries.
Hope it helps!
See Also PowerApps Business Days Between Two Dates