Stage 8 of 17
In this stage you will build the Power Apps canvas app. You will create the app, connect it to the Microsoft Lists data source, build all five screens, add validation, and implement the submit and cancel logic. Every formula is explained — not just shown.
Why Are We Doing This?
Navigate to make.powerapps.com. Sign in with your Microsoft 365 account.
Select "+ Create" from the left navigation. Choose "Blank app".
Select "Blank canvas app". App name: "Leave Request App". Format: Tablet (this gives more screen space for the form). Select Create.
The Power Apps Studio opens. You will see a blank canvas with a properties panel on the right and a formula bar at the top.
Save the app immediately: File → Save. This creates the app in your environment. Save frequently throughout the build.
In the left panel, select the Data icon (looks like a cylinder or database). Select "+ Add data".
Search for "SharePoint". Select the SharePoint connector.
Select "Connect directly (cloud services)". Enter the URL of your SharePoint site (the URL you noted in Stage 7). Select Connect.
A list of SharePoint lists on that site will appear. Select "Leave Requests". Select Connect.
The Leave Requests data source now appears in the Data panel. You can reference it in formulas as "LeaveRequests".
Verify the connection: in the formula bar, type "LeaveRequests" and press Enter. If the connection is working, you will see the data source reference without an error.
Beginner Tip
Rename the default Screen1: right-click it in the Screens panel and select Rename. Name it "HomeScreen".
Add a Rectangle control as the header background. Set Fill to a dark colour (e.g. RGBA(15, 27, 45, 1) for navy). Set Width to Parent.Width, Height to 80, X to 0, Y to 0.
Add a Label inside the header. Text: "Leave Request App". Set font size to 20, bold, white text. Position it inside the header rectangle.
Add a second Label below the header. Text formula: "Welcome, " & User().FullName. This displays the logged-in user's name from their Microsoft 365 profile.
Add a Button. Text: "New Request". OnSelect formula: Navigate(NewRequestScreen, ScreenTransition.Fade). This navigates to the New Request screen when tapped.
Add a second Button. Text: "My Requests". OnSelect formula: Navigate(MyRequestsScreen, ScreenTransition.Fade).
Add a third Button. Text: "Administration". OnSelect: Navigate(AdminScreen, ScreenTransition.Fade). Visible formula: User().Email in ["admin@contoso.co.uk", "hr@contoso.co.uk"] — replace with your admin email addresses.
Add a Label showing pending requests. Text formula: CountIf(LeaveRequests, EmployeeEmail = User().Email && Status = "Submitted") & " pending request(s)". This counts the current user's submitted requests.
CountIf(
LeaveRequests,
EmployeeEmail = User().Email &&
Status = "Submitted"
) & " pending request(s)"What this does: CountIf counts the rows in LeaveRequests where both conditions are true: the EmployeeEmail matches the logged-in user's email, AND the Status is Submitted. The & operator concatenates the count with the text string.
Add a new screen. Rename it "MyRequestsScreen".
Add a Back button. Text: "← Back". OnSelect: Navigate(HomeScreen, ScreenTransition.Back).
Add a title Label. Text: "My Leave Requests".
Add a New Request button. Text: "+ New Request". OnSelect: Navigate(NewRequestScreen, ScreenTransition.Fade).
Add a Gallery control (Vertical gallery). Set the Items property to the filter formula below.
Inside the gallery, add Labels for: Title (Request Reference), LeaveType, StartDate, EndDate, WorkingDays, Status.
Add a status badge Label inside the gallery. Set the Fill property to a colour based on the status (see formula below).
Set the gallery OnSelect property: Set(SelectedRequest, ThisItem); Navigate(RequestDetailScreen, ScreenTransition.Fade). This stores the selected record and navigates to the detail screen.
Add an empty state Label. Text: "You have no leave requests yet." Visible formula: CountRows(Gallery1.AllItems) = 0.
Set the screen OnVisible property: Refresh(LeaveRequests). This refreshes the data every time the screen is shown, ensuring the gallery shows the latest status.
Filter(
LeaveRequests,
EmployeeEmail = User().Email
)What this does: Filter returns only the rows from LeaveRequests where the EmployeeEmail column equals the logged-in user's email address. This ensures employees only see their own requests (SEC-001). The filter runs on the SharePoint server (it is delegable), so it works correctly even with large lists.
Switch(
ThisItem.Status,
"Approved", RGBA(34, 197, 94, 0.15),
"Rejected", RGBA(239, 68, 68, 0.15),
"Submitted", RGBA(59, 130, 246, 0.15),
"Cancelled", RGBA(245, 158, 11, 0.15),
RGBA(156, 163, 175, 0.15)
)What this does: Switch evaluates ThisItem.Status and returns a different background colour for each value. The last argument (RGBA(156, 163, 175, 0.15)) is the default — used for Draft status. RGBA values are Red, Green, Blue, Alpha (transparency).
Why Explain Formula Logic?
Add a new screen. Rename it "NewRequestScreen".
Add a Back button. Text: "← Back". OnSelect: Navigate(HomeScreen, ScreenTransition.Back).
Add a title Label. Text: "New Leave Request".
Add a Dropdown control for Leave Type. Items: ["Annual Leave", "Sick Leave", "Other"]. Label above it: "Leave Type *".
Add a DatePicker control for Start Date. Label above it: "Start Date *".
Add a DatePicker control for End Date. Label above it: "End Date *".
Add a Label for Working Days. Text formula: see below. Label above it: "Working Days (weekdays only)".
Add a Text Input for Manager Name. Label above it: "Manager Name *". Hint text: "e.g. Priya Sharma".
Add a Text Input for Manager Email. Label above it: "Manager Email *". Hint text: "e.g. priya.sharma@contoso.co.uk".
Add a Text Input (multiline) for Comments. Label above it: "Comments (optional)".
Add validation error Labels (see validation section below).
Add a "Save as Draft" button and a "Submit" button (see submit logic below).
Text(
RoundDown(
(DateDiff(StartDatePicker.SelectedDate, EndDatePicker.SelectedDate, Days) + 1)
- (2 * RoundDown(
(Weekday(StartDatePicker.SelectedDate, StartOfWeek.Monday) +
DateDiff(StartDatePicker.SelectedDate, EndDatePicker.SelectedDate, Days)) / 7,
1
)),
0
),
"0"
) & " working day(s)"What this does: This formula calculates the number of weekdays between two dates. It starts with the total days (including the end date), then subtracts the number of weekend days. The Weekday() function returns the day of the week (1=Monday, 7=Sunday with StartOfWeek.Monday). The RoundDown(x/7) * 2 pattern counts the number of complete weeks (each containing 2 weekend days). This is a simplified calculation — it does not account for bank holidays.
Validation prevents invalid data from being submitted. Each validation rule has a corresponding error label that is shown when the rule fails and hidden when it passes.
Validation: Start date is blank
Error text: "Please select a start date."
Visible property formula
IsBlank(StartDatePicker.SelectedDate)IsBlank() returns true if the date picker has no value selected. The label is visible when this is true.
Validation: End date is blank
Error text: "Please select an end date."
Visible property formula
IsBlank(EndDatePicker.SelectedDate)Same pattern as start date.
Validation: End date is before start date
Error text: "End date cannot be before start date."
Visible property formula
EndDatePicker.SelectedDate < StartDatePicker.SelectedDateCompares the two date values directly. In Power Fx, date values can be compared with < and >. This is true (error shown) when the end date is earlier than the start date.
Validation: Leave type not selected
Error text: "Please select a leave type."
Visible property formula
IsBlank(LeaveTypeDropdown.Selected.Value)Checks whether the dropdown has a selected value. IsBlank() on a dropdown's Selected.Value returns true if nothing is selected.
Validation: Manager email is blank
Error text: "Please enter your manager's email address."
Visible property formula
IsBlank(ManagerEmailInput.Text)Checks whether the manager email text input is empty.
Validation: Manager email does not look like an email
Error text: "Please enter a valid email address."
Visible property formula
!IsBlank(ManagerEmailInput.Text) && !("@" in ManagerEmailInput.Text)The ! operator means NOT. This rule is only shown when the field is not blank (to avoid showing two errors at once) AND the text does not contain "@". This is a basic check — it does not verify the email address exists.
Common Mistake
If(
IsBlank(StartDatePicker.SelectedDate) ||
IsBlank(EndDatePicker.SelectedDate) ||
EndDatePicker.SelectedDate < StartDatePicker.SelectedDate ||
IsBlank(LeaveTypeDropdown.Selected.Value) ||
IsBlank(ManagerNameInput.Text) ||
IsBlank(ManagerEmailInput.Text),
DisplayMode.Disabled,
DisplayMode.Edit
)What this does: This formula disables the Submit button when any required field is blank or any validation rule fails. The || operator means OR — if any one condition is true, the button is disabled. DisplayMode.Disabled makes the button grey and unclickable. DisplayMode.Edit makes it active.
Patch(
LeaveRequests,
Defaults(LeaveRequests),
{
Title: "LR-" & Text(Now(), "YYYYMMDD") & "-" & Text(Rand() * 9999, "0000"),
EmployeeName: User().FullName,
EmployeeEmail: User().Email,
ManagerName: ManagerNameInput.Text,
ManagerEmail: ManagerEmailInput.Text,
LeaveType: LeaveTypeDropdown.Selected.Value,
StartDate: StartDatePicker.SelectedDate,
EndDate: EndDatePicker.SelectedDate,
WorkingDays: Value(WorkingDaysLabel.Text),
EmployeeComments: CommentsInput.Text,
Status: "Submitted",
SubmittedDate: Now()
}
);
Notify("Your leave request has been submitted.", NotificationType.Success);
Navigate(MyRequestsScreen, ScreenTransition.Fade)What this does: Patch() creates a new record in the LeaveRequests list. Defaults(LeaveRequests) provides the default values for all fields not specified. The record is created with Status = Submitted, which will trigger the Power Automate flow. After creating the record, Notify() shows a success message and Navigate() returns the user to the My Requests screen.
Patch(
LeaveRequests,
Defaults(LeaveRequests),
{
Title: "LR-DRAFT-" & Text(Now(), "YYYYMMDD"),
EmployeeName: User().FullName,
EmployeeEmail: User().Email,
ManagerName: ManagerNameInput.Text,
ManagerEmail: ManagerEmailInput.Text,
LeaveType: If(IsBlank(LeaveTypeDropdown.Selected.Value), "", LeaveTypeDropdown.Selected.Value),
StartDate: StartDatePicker.SelectedDate,
EndDate: EndDatePicker.SelectedDate,
WorkingDays: 0,
EmployeeComments: CommentsInput.Text,
Status: "Draft"
}
);
Notify("Draft saved.", NotificationType.Information);
Navigate(MyRequestsScreen, ScreenTransition.Fade)What this does: The Save as Draft button uses the same Patch() pattern but sets Status = Draft. This does NOT trigger the Power Automate flow (the flow only fires on new records, and the flow's condition checks for Status = Submitted). Required field validation is not enforced for drafts — the employee can save an incomplete request.
Add a new screen. Rename it "RequestDetailScreen".
Add a Back button. OnSelect: Navigate(MyRequestsScreen, ScreenTransition.Back).
Add a title Label. Text: SelectedRequest.Title (this displays the request reference of the record selected in the gallery).
Add a status badge Label. Text: SelectedRequest.Status. Fill: use the same Switch() formula as the gallery status badge.
Add read-only Labels for each field: Leave Type, Start Date, End Date, Working Days, Employee Comments, Submitted Date. Each label's Text property references the corresponding field of SelectedRequest (e.g. Text(SelectedRequest.StartDate, "DD/MM/YYYY")).
Add a Decision section container. Visible formula: SelectedRequest.Status in ["Approved", "Rejected"]. Inside: Labels for Decision Date, Approver, Approver Comments.
Add a Cancel Request button. Text: "Cancel Request". Visible formula: SelectedRequest.Status = "Submitted". OnSelect: see formula below.
If(
Confirm("Are you sure you want to cancel this request?"),
Patch(
LeaveRequests,
SelectedRequest,
{ Status: "Cancelled" }
);
Notify("Request cancelled.", NotificationType.Warning);
Navigate(MyRequestsScreen, ScreenTransition.Fade)
)What this does: Confirm() shows a confirmation dialog. If the user selects OK (true), Patch() updates the existing record (SelectedRequest) by changing only the Status field to Cancelled. This is different from the submit Patch() — here we pass SelectedRequest as the second argument (the record to update) rather than Defaults() (which creates a new record).
Add a new screen. Rename it "AdminScreen".
Add a Back button. OnSelect: Navigate(HomeScreen, ScreenTransition.Back).
Add a title Label. Text: "Administration — All Requests".
Add a Dropdown for status filter. Items: ["All", "Draft", "Submitted", "Approved", "Rejected", "Cancelled"]. Label: "Filter by Status".
Add a Text Input for employee name search. Label: "Search by Employee Name". Hint text: "Type a name to filter".
Add a Gallery. Items formula: see below.
Inside the gallery, add Labels for: Title, EmployeeName, LeaveType, StartDate, EndDate, Status.
Add a record count Label. Text formula: CountRows(AdminGallery.AllItems) & " record(s)".
Set the screen OnVisible property: Refresh(LeaveRequests).
Filter(
LeaveRequests,
(StatusFilterDropdown.Selected.Value = "All" ||
Status = StatusFilterDropdown.Selected.Value) &&
(IsBlank(EmployeeSearchInput.Text) ||
StartsWith(EmployeeName, EmployeeSearchInput.Text))
)What this does: This filter combines two conditions with &&. The first condition checks the status filter: if 'All' is selected, all records pass; otherwise only records matching the selected status pass. The second condition checks the search input: if the search box is empty, all records pass; otherwise only records where EmployeeName starts with the search text pass. StartsWith() is delegable to SharePoint, so this works correctly with large lists.
Build all five screens following the steps above. When complete, test the following scenarios manually:
Need more help with the concepts?
Visit DosToDigital for guides, templates, and deeper explanations.