@Anonymous
You can create your own function using a component in your app if you find you need to do these calculations often.
Also, I would advise a formula more conducive to how PowerApps is designed rather than a programmatic design.
Here are the steps:
1) Create a new Component in your app. Name it what you want (I will call it cmp_Functions)
2) Make sure you have the Enhanced component properties feature turned on in the settings.
3) In your Component, create a new custom property.
a) Call it DaysOfMonth
b) Set the Property Type to Output
c) Set the Data type to Number
d) Create a new parameter. Call it MonthDate and set the Data Type to Date and time, also set the parameter to Required. Then save the parameter.
e) Create another new parameter. Call it WorkDays and set the Data Type to Table. Do not make it required. Save the parameter.
f) Then Save the property.
4) In the property chooser in the formula bar, select the WorkDays property/parameter and set the formula to [0,1,2,3,4,5,6] (this will be all days of the week - the default)
5) Select the DaysInMonth property and change the formula to:
With({_monthStart: Date(Year(MonthDate), Month(MonthDate), 1)},
CountRows(
Filter(
ForAll(
Sequence(DateDiff(_monthStart, DateAdd(_monthStart, 1, Months))-1, 0),
Weekday(DateAdd(_monthStart, Value, Days), StartOfWeek.MondayZero)
),
Value in WorkDays
)
)
)
And you are done with the Component.
Now, insert the component in your app screen. At this point you can use the component function any place in your app.
For example, if you want to see the total number of days in a selected month, then set a label text property to:
cmp_Functions.DaysInMonth(yourDatePicker.SelectedDate)
This will show the total number of days in the month.
To show the total number of days in a month and exclude Sundays, then set your Text property formula to:
cmp_Functions.DaysInMonth(yourDatePicker.SelectedDate, [0,1,2,3,4,5])
Excluding Sat and Sun, then the formula is:
cmp_Functions.DaysInMonth(yourDatePicker.SelectedDate, [0,1,2,3,4])
Note, the weekdays are set to Monday as 0 in the main formula. So, Monday is 0 and the days count up from that.
I hope this is helpful for you.