Requirement: Calculate working days according to month selected in dropdown control
Add label control-Text Property as “Working Days”. Then Add a DropDown, DatePicker and Label control
DropDown- Items Property:
ForAll (Sequence (Month (Today ())), {MonthNumber: Value, MonthName: Last (FirstN (Calendar.MonthsLong (), Value)).Value })
OnChange Property:
UpdateContext ({startDate: Date (Year (Now ()), Dropdown3_1.Selected.MonthName, 1), endDate: DateAdd (DateAdd (Date (Year (Now ()), Dropdown3_1.Selected.MonthName, 1), 1, TimeUnit.Months), -1, TimeUnit.Days)})
Default Property:
Text(Now(),"[$-en-US]mmmm")
Here we need to get passed out months working days to current month working days,for this the above formula are used. And MonthName and MonthNumber are functions.
DatePicker- DefaultDate Property:
Date(2023, Month(Dropdown3_1.Selected.MonthName & "2023"),1)
Format: "yyyy"
StartYear: 2013
EndYear: 2050
Label- Text Property:
With({StartDate:Date(Year(DatePicker2_1.SelectedDate),Month(DatePicker2_1.SelectedDate),1),LastDate:DateAdd(DateAdd(Date(Year(DatePicker2_1.SelectedDate),Month(DatePicker2_1.SelectedDate),1),1,TimeUnit.Months),-1,TimeUnit.Days)},If(StartDate=LastDate,Sum(If(Weekday(StartDate)=1,0,1)),Sum(ForAll(Sequence(DateDiff(StartDate,LastDate,TimeUnit.Days)+1,0,1),If(Weekday(DateAdd(StartDate,Value))=1,{DayCount:0},{DayCount:1})),DayCount)))
Here the StartDate and LastDate are the variables. Now Click on the Preview button, by default the dropdown display the current month. As we select month from dropdown,the working days display on label control as shown in below video.