Add hierarchy to inspection location
The Inspections sample app allows users to create and perform inspections in the app. There are three apps, one per persona to perform, manage, and review Inspections. The three apps are—Inspections, Manage Inspections and Review Inspections.
By default, the Inspections app is designed for a single store. But what if you perform inspections on multiple stores? You'll want to add a table for stores to the app and let the user select the store in which they are performing inspections so that you can track at which store the inspection was performed.
In this article, we'll learn how to update the app to add a hierarchy of stores so that inspections can be performed for different stores.
Watch this video to learn how to add hierarchy to inspection location:
Prerequisites
To complete this lesson, we'd need the ability to log in into Microsoft Teams that will be available as part of select Microsoft 365 subscriptions, and will also need to have the Inspections sample app for Teams installed. This app can be installed from https://aka.ms/TeamsInspection.
Edit the Inspections app
Login into Teams, and right-click on Power Apps app from the left-pane, and select Pop out app.
Select Build from the top ribbon.
Select the team in which the Inspections app is installed.
Select Inspections to open the app in Power Apps Studio.
Add a new table called Store
Select Data from the left-pane.
Select + Add data.
Select the + Create new table.
Enter table name "Store" and select Create.
Select the Add Column button to add a new column.
Enter column name as "Store Number", and select Create.
Add a few sample records in the table, and select Close.

Update Items screen
Update the formula for the following controls to allow the Items screen to show inspections.
Search for and select lblIssues_Header label in the Tree view.
Select the Text property.
Replace the following section of the formula.
Remove formula section:
With( { varDefault: "Issues reported (" & CountRows( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.Issue ) ) & ")", varOOBTextId: "_translateVariable_IssuesHeader", varParam0: "(" & CountRows( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.Issue ) ) & ")" },Add formula section:
With( { varDefault: "Issues reported (" & CountRows( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.Issue ).'Area Inspection Step' ) & ")", varOOBTextId: "_translateVariable_IssuesHeader", varParam0: "(" & CountRows( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.Issue ).'Area Inspection Step' ) & ")" },Search for and select lblNoIssues_Header label in the Tree view.
Select the Text property.
Replace the following section of the formula.
Remove formula section:
With( { varDefault: "No issues (" & CountRows( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ) ) & ")", varOOBTextId: "_translateVariable_NoIssuesHeader", varParam0: "(" & CountRows( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ) ) & ")" },Add formula section:
With( { varDefault: "No issues (" & CountRows( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ).'Area Inspection Step' ) & ")", varOOBTextId: "_translateVariable_NoIssuesHeader", varParam0: "(" & CountRows( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ).'Area Inspection Step' ) & ")" },Search for and select galNoIssuesAttachments gallery in the Tree view.
Select the Items property.
Replace the following section of the formula.
Remove formula section:
ThisItem.'Area Inspection Images'Add formula section:
LookUp('Area Inspection Steps','Area Inspection Step'=ThisItem.'Area Inspection Step').'Area Inspection Images'Search for and select galIssuesAttachments gallery in the Tree view.
Select the Items property.
Replace the following section of the formula.
Remove formula section:
ThisItem.'Area Inspection Images'Add formula section:
LookUp('Area Inspection Steps','Area Inspection Step'=ThisItem.'Area Inspection Step').'Area Inspection Images'Search for and select galNoIssues gallery in the Tree view.
Select the Items property.
Replace the following section of the formula.
Remove formula section:
Sort( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ), Value(Sequence), Ascending )Add formula section:
Sort( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ), Sequence, Ascending )Search for and select galIssues gallery in the Tree view.
Select the Items property.
Replace the following section of the formula.
Remove formula section:
Sort( Filter( locSelectedInspection, Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ), Value(Sequence), Ascending )Add formula section:
Sort( Filter( galInspections.Selected.'Area Inspection Steps', Outcome = 'Inspection Outcome'.OK || Outcome = 'Inspection Outcome'.'N/A' ), Sequence, Ascending )
Add a column to capture Store in the Area Inspections table
Select Data from the left navigation menu.
Locate the Area Inspections table, and select ... (ellipsis).
Select Edit data.
Select Add Column, and enter the table name as "Store", type as "Lookup", and related table as "Store".
Select Create.
Select Close.
Add a new screen with a Gallery of Stores
Select the Tree view from the left-pane.
Select + New screen from the tree view.
Select blank layout.
Rename the screen to "StoreSelectionScreen".
Update the Fill property to
gblAppStyles.Background.Fill.Select + Insert to add a gallery to the new screen.
Select Stores as the data source.
Rename the gallery to "StoresGallery".
Set the following properties for the gallery StoresGallery.
Property Value Template size 108 Font size 20 Height for Title4 45 Font size for label Subtitle4 18 Height for label Subtitle4 45 Go to the Items screen, and copy the Back button from the top of the screen.
Paste the copied button on the new screen.
Repeat the previous steps to copy the label lblIndividualAreasHeader from Items screen that reads the text as location to the new screen.
Set Y property of the label to
btnBackToHome_1.Y+btnBackToHome_1.Height.Set the following properties of the gallery StoresGallery.
Property Value Y btnBackToHome_1.Height+lblIndividualAreasHeader_1.HeightHeight Parent.Height-btnBackToHome_1.Height- lblIndividualAreasHeader_1.HeightOnSelect Set(gblSelectedStore,ThisItem);Navigate('Items Screen')Go to the Items, select the Back to home button on top, and update the following button properties.
Property Value OnSelect Navigate(StoreSelectionScreen, ScreenTransition.Fade)Text "Back to Store Selection"Go to Checklist Steps screen.
Select the OnVisible property of the screen, and update the patch function for updating the Area Inspections app to add the store value in the formula.
, Store: gblSelectedStore
Update the Welcome Screen navigation
From the tree view, select the Welcome Screen.
Select the button Perform an Inspection (btnInspect).
Update the Navigate function from the OnSelect property of the button so that it takes you to the StoreSelectionScreen screen instead of the Items screen, with the remaining of the formula unchanged.
Navigate( StoreSelectionScreen, ScreenTransition.Fade );
Publish the Inspections app
All the changes to the Inspections app are completed. The app can now be published by selecting the Publish to Teams button on the top-right.

Edit the Review Inspections app
Open Power Apps in Teams.
Select Build tab from the top ribbon.
Select the team in which the Inspections app is installed.
Select Review Inspections to open the app in the editor.
Select Data from the left-pane.
Select + Add data, and add the Stores table to this database for this app.
Refresh the Area Inspections table so that the Stores column shows up in the table.
Add a label to display the store on the Inspection
Open the tree view, and select the Items Screen.
Under the group grpInspectionSteps, select label called "lblInspection_SubmissionDetails", and update it's Text property to the following formula.
If( DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Days ) = 0, If( DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Hours ) > 0, galInspections.Selected.Store.Name & " | Submitted by " & galInspections.Selected.createdby.'Full Name' & ", " & DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Hours ) & " hrs ago", If( DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Hours ) = 0, //"minutes ago" galInspections.Selected.Store.Name & " | Submitted by " & galInspections.Selected.createdby.'Full Name' & ", minutes ago" , If( DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Days ) = 1, //"yesterday", galInspections.Selected.Store.Name & " | Submitted by " & galInspections.Selected.createdby.'Full Name' & ", yesterday", galInspections.Selected.Store.Name & " | Submitted by " & galInspections.Selected.createdby.'Full Name' & ", " & DateDiff( Date( Year(galInspections.Selected.createdon), Month(galInspections.Selected.createdon), Day(galInspections.Selected.createdon) ), Today(), Days ) & " days ago" ) ) ) )
Test the app
Open the Inspections app in the team in which it's installed.
Select the Welcome screen from the tree view if running inside Studio, and select Preview.
Select Perform an Inspection.
Verify that the Store Selector screen opens.
Select a store. The next screen should be the Items screen.
Select a location.
Select a food inspection checklist on the next screen.
Select the button Begin Inspection.
Answer the questions that are part of the inspection, and then select Review Inspection.
Select Submit Inspection on the next screen.
Now, login into the Review Inspections app by selecting the Review Inspection tab on the top in the team where it's installed.
Select the location that you selected earlier to show a list of inspections performed.
Select the inspection that was submitted earlier.
The screen displays the store name.
