Lab - Using the ForAll function in a gallery
Read this first - before you start the lab!
Important
For this lab, do not sign in with your credentials. Use the following steps to sign in to your lab environment with the correct credentials.
- Select Launch VM mode in this unit.
- You'll see a PowerShell window and a Windows Command window appear. After about two to three minutes, they'll close, and Power Apps will open automatically. Wait for the Power Apps home screen.
- To see the lab instructions, select the Instructions tab on the lab side bar.
You can now begin your work on this lab.
This hands-on lab shows you how to use the ForAll function in a gallery.
Sign in to Power Apps. If you are using the virtual environment, skip to step 2.
On the Home screen, select Canvas app from blank.
Name your app New App , format Tablet and click Create.
Select the Insert tab and add a button, and set its OnSelect property to this formula:
ClearCollect(CityPopulations, {City:"London", Country:"United Kingdom", Population:8615000}, {City:"Berlin", Country:"Germany", Population:3562000}, {City:"Madrid", Country:"Spain", Population:3165000}, {City:"Rome", Country:"Italy", Population:2874000}, {City:"Paris", Country:"France", Population:2273000}, {City:"Hamburg", Country:"Germany", Population:1760000}, {City:"Barcelona", Country:"Spain", Population:1602000}, {City:"Munich", Country:"Germany", Population:1494000}, {City:"Milan", Country:"Italy", Population:1344000})
To copy and paste the text in the virtual environment, select the Commands button on the top left corner of the screen, select Type text, then select Type clipboard text. Paste the copied text in the window.
Select the Button control, and set its Text property to "Collect." Hold the Alt Key and press the Button control. (This will create your collection and store all the information).
Select the Gallery dropdown at the top and choose Blank vertical gallery and choose CityPopulations from the data source pop-up.
With the gallery selected, in the right pane, change the layout from blank to Title, subtitle, and body.
Select the last or third Label in the first item of the gallery, and change the Text property to ThisItem.Population.
Select the Insert tab, select Input button and add a checkbox, and set its Text property to "Add".
Select the Insert tab add a button, set its Text property to "ForAll Collect" and set its OnSelect property to this formula:
Clear(NewCity); ForAll(Gallery1.AllItems, If(Checkbox1.Value = true, Collect(NewCity, {City: City, Country: Country, Population: Population})))
Select the Insert tab add a Blank Vertical Gallery, and choose NewCity from the data source pop-up.
On the left Navigation Pane change the layout from blank to Title, subtitle, and body.
Select the Play button, check the checkbox, and then select the ForAll Collect button.
You have now used the For All command to add all checked items to a new gallery.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.