Useful Scenarios To Help Build PowerApps Canvas Apps

Introduction

 
There are numerous functions that we use in PowerApps canvas apps. To structure the data source in a meaningful manner and to obtain the desired end result these functions need to be polished as per our business requirements. In this blog post, let’s use some of these functions to help build PowerApps canvas apps in our day-to-day scenarios.
 
Useful Scenarios To Help Build PowerApps Canvas Apps
 

Scenario 1 - Show & Hide column values in a dropdown

 
A use case where you want to show or hide users in a dropdown control only if the users are active in the system or vice versa. Below is a data source stored in a SharePoint list named Users List where Title = Text field and Active = Yes/No field.
 
Useful Scenarios To Help Build PowerApps Canvas Apps
 
To see active users in a dropdown control, paste the below code on the items property of dropdown control. 
  1. Filter(       
  2. AddColumns(   
  3.         Users List,   
  4.         "hideVal",           
  5.          Active       
  6.         ),       
  7.          hideVal   
  8. ).Title  
Useful Scenarios To Help Build PowerApps Canvas Apps
 
And to see the Inactive users replace the above code with,
  1. Filter(       
  2. AddColumns(   
  3.         Users List,   
  4.         "hideVal",           
  5.          Active       
  6.         ),       
  7.          !hideVal   
  8. ).Title   
Useful Scenarios To Help Build PowerApps Canvas Apps
 

Scenario 2 - Get distinct items from a SharePoint list

 
In a SharePoint list you store values as below and want to extract distinct items based on the latest items created,
 
Useful Scenarios To Help Build PowerApps Canvas Apps
 
Add a gallery to test this scenario and paste the below code to items property of this control,
  1. ForAll(  
  2.    Distinct(  
  3.       VehicleData_Demo,  
  4.       Title ),  
  5.       LookUp(  
  6.          Sort(  
  7.          VehicleData_Demo,  
  8.                 Date,  
  9.                 Descending ),  
  10.       Title = Result  
  11.           )  
  12. )   
The result,
 
Useful Scenarios To Help Build PowerApps Canvas Apps
 

Scenario 3 - Get current canvas apps GUID within the App

 
Using a premium connector in PowerApps “PowerAppsForAdmins” we can determine the canvas apps GUID within the app. To test the below function in your app, add a label control, and on the text property paste the below code: DefaultTenant = Your default tenant name, yourAppName = Your current working app name.
  1. LookUp(PowerAppsforAdmins.GetAdminApp(  
  2.    LookUp(PowerplatformforAdmins.GetAdminEnvironment().value,  
  3.       properties.creationType="DefaultTenant").name).value,  
  4. properties.displayName="yourAppName").name   

Scenario 4 - Different solutions to “App not working please refresh your browser: Error”

 
Sometimes while loading an application for different users in their respective machines we get the following error “App not working please refresh your browser: Error”. This can happen to anyone and to solve this issue we can try few solutions on our own:
  • Clearing browser cache
  • Reinstalling your browser
  • Trying different browsers
  • Add the app to Teams and check if it loads fine
There can be a situation where you try all the above points and still the app doesn’t load. In this case, check your computer’s date is most recent date and timezone – update it from the time settings using online synchronization method.
 

Scenario 5 - Load all items in a Gallery control by default on App load

 
A scenario where you have two gallery controls Gallery1 and Gallery2.
 
Gallery1 controls item property has the value [“All”, “In progress”, “Completed”]
 
Gallery2 control is connected to a SharePoint list which should load all items by default on the app load and should filter items based on the status selected from Gallery1.
 
Use the below code on Gallery2 controls item property as follows: Status.Value is the status field in your SharePoint list.
  1. If(Gallery1.Selected.Value = "All",  
  2. 'SharePoint List',  
  3.    Filter(  
  4.    'SharePoint List', Status.Value = Gallery1.Selected.Value  
  5.    )  
  6. )  

Summary

 
We have seen the use of AddColumns, Distinct, LookUp and Filter functions and PowerAppsforAdmin connectors in this blog post.