Month Picker in Power Apps
For the enabling month picker in PowerApps. There is no direct option in Powerapps. We need to do a workaround procedure for a month picker.
This month Picker is a custom build.
With the help of SharePoint List, we can get the month picker working,
Proceed with the following steps
Step 1: Create a Sharepoint list with the columns month in Letters and in numerics.
Refer to the following pic:
Create a new list in a SharePoint
with column title and number
with single line text data type
Step 2:Inside a power app Create a gallery with the data source as the month picker SharePoint List
Step3: Wrap the gallery with 3 columns and adjust the rows as per the requirement
NOTE: Create a gallery with a Vertical view and with a wrap count of 3.
Adjust the gallery as per your requirement
Add the List that you created the month picker in the data source of the gallery.
Inside the ITEMS dialog box use the following formula.
SortByColumns(Month_Picker,"ID",Ascending)
To display the values inside the gallery use button instead of a label.
On the button, text use the ( ThisItem.Title ) formula.
You will get the custom build gallery as a month picker, Now you can add the date-time function and navigate between the months.
Step 4: On App Start -
Add the following functions,
Set(currentyear,Year(Now()));
Set(currentmonth,Text(Now(),"[$-en-US]mmm"));
Set(showmonth,Text(Now(),"[$-en-US]mmm"));
Step 5: On select of the gallery buttons add the logics to get the start and end day of the selected month
Set(monthpic,ThisItem.Title);
Set(Datefrom,"01/"&ThisItem.Number&"/"¤tyear);
Set(DateTo,"30/"&ThisItem.Number&"/"¤tyear)
in the button use these function to display the get the start date and end date of the month.
Step 6: Insert a '< ' and '>' icon and add the year functions like the following
Set(currentyear,currentyear-1); in '<' icon of onSelect and
If(currentyear=Year(Now()),"Future year cannot be selected") in '>' icon of onSelect. to avoid selcting future dates
Step 7: Using the label function display the set dates ( monthpic, Datefrom, DateTo ) in the labels
Refer to the following pic in the final stage
And by this method, we can get the month picker in power apps.
Comments
Post a Comment