Aggregate functions in a Canvas Power App | Using on SharePoint Lists

Aggregate functions have one of the most common applications while building your Canvas Power App.

In this simple example, we’ll try to make common Aggregate Functions like Max, Min, Sum & Average work.

There are 2 more advanced Aggregate Functions, StdevP for Standard Deviation and VarP for Variance. (It might not make full sense in this post, but I added them anyway to see how we can apply for formula 😊 I’m sure your use-case will make more sense!)

SharePoint List

Let’s say, my SharePoint list looks like this. Scores of some people and their ranks

And I’m using Data Table to populate this into my Canvas Power App

Formulas

Here’s how I used for Formulas to use the Aggregate functions on the SharePoint list data I populated in my Canvas Power App

For all the Formulas above, I’ve written them inside a Concatenate function just so I could add some Text and then use the formulas. You may use differently.

In my case, the Formula goes like this –
Function(SharePointListName, ColumnName)

“Max” – Maximum Number in Score column of Scoreboard list


“Min” – Smallest Number in Score column of Scoreboard list

“Sum” = Total of all values in Score column of Scoreboard list

“Average” – Average of all values in Score column of Scoreboard list

“StdevP” – Standard Deviation arguments passed. Score column in this case

“VarP”-Variance of the arguments passed. Score column in this case

And that’s it! I tried to simply the explanation. However’s there much more to consider as well. Here’s the full documentation by Microsoft – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-aggregates

You might want to check some posts on Canvas Power Apps as well –

  1. Count of total CDS records returned in a Canvas Power App connection [Quick Tip]
  2. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  3. Restore older version of a Canvas Power App | Power Platform
  4. Implement character length validation in a Canvas Power App | Power Platform
  5. Logged In User details in a Canvas Power App
  6. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  7. Variables in Canvas Power Apps | Global and Context
  8. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  9. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows
  10. Correctly connect to an Excel file in a Canvas PowerApp

Hope this was helpful!

Count of total CDS records returned in a Canvas Power App connection [Quick Tip]

Like in Dynamics 365, you see a total number of records under a view. And you want similar in a Canvas PowerApp too.
undefined

Here’s a simple tip to do so –

CountRows() method

It’s pretty simple. Using CountRows(source) method, you can get the count of records in the Source. In this case, it’s the CDS entity Accounts.
undefined

To flourish how I display the count, I use the Concatenate() method and then use CountRows() inside it first show the text and then the actual count.

Please note that this goes without filtering out any criteria and straight count of how many records the connection has. Your gallery could use more filtering to display lesser records if specified that way.

Handle Delegation

However, you need to handle a few things if you’re aware that your dataset is large.

Using this formula will give a warning:
undefined

And the general help offered is this –
undefined

Refer this article to understand more: https://powerapps.microsoft.com/en-us/blog/powerapps-data-row-limit-for-non-delegable-queries/

Hope this quick tip helps!

Here are some more Canvas PowerApp / Power Automate posts you might want to look at –

  1. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  2. Restore older version of a Canvas Power App | Power Platform
  3. Implement character length validation in a Canvas Power App | Power Platform
  4. Logged In User details in a Canvas Power App
  5. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  6. Variables in Canvas Power Apps | Global and Context
  7. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  8. Get Count of records retrieved in CDS connector in a Flow | Power Automate

Thank you!

Restore older version of a Canvas Power App | Power Platform

When you users report of an issue and you need some time to look into it but can’t hold the users, you just want to restore to a previous version for the time being.

Here’s how you can restore/revert to an older version of the Canvas App you’ve deployed.

Current Version

Let’s say my current version had a button called Profile under the label Accounts. But in the new version, I had moved it and now want to restore the previous one for some reason.

undefined

This previous version is what I want to restore to.

undefined

Restore & Publish

Here’s how you can Restore it.

  1. Navigate to Save, and go to See All Versions
    undefined

  2. Now, you’ll come to all the versions of the App existing. The current one will have the status of Live. Click on the three ellipses of the old version of App you wish to restore and you’ll see an option to Restore
    undefined

  3. It’ll ask for a confirmation. Remember, the new version will be 1 version higher that the current Live version. In this case, it’ll be version 18 to be created from version 16 (version 17 is the current Live version)
    undefined

  4. Once you confirm, a new version will be created. This is not yet in Published stage. This is because you might want to go back and change something and then Publish
    undefined

  5. Now, let’s say you are ready to Publish, simply select it. And then either from the options in ellipses or on the top ribbon, you can Publish this version
    undefined

Update on App

Upon opening the App, the user will see a message like this
undefined

And when you tap on it, the previous version is restored
undefined

Pretty easy!!

Here are some more Canvas Power App posts you might want to check –

  1. Implement character length validation in a Canvas Power App | Power Platform
  2. Logged In User details in a Canvas Power App
  3. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  4. Variables in Canvas Power Apps | Global and Context
  5. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  6. Adding a Canvas PowerApp to Teams

Hope this helps!

Implement character length validation in a Canvas Power App | Power Platform

Often times, you want to know the size of text entered in a field and want to indicate a user that they need to restrict the text to your specific size, like Twitter. And make sure the user is restricted within the limits. So, I’ve added a button to show that validation –


undefined

And you want to dynamically check the length as you type to see how much is remaining
undefined
And maybe also add some validation like disabling the button if the limit is reached
undefined

Let’s look at how we can implement this in Canvas Power App!

Setup

Let’s get to building this out!

  1. Let’s say you have a Text Input. I’ve simply called it “Message
    undefined
    undefined

  2. Then, I have the Label field called as “CharLength“. This will be a place holder for our counter of characters in the Message textbox.
    undefined
    undefined

  3. And finally, a Submit button which will be disabled if the Text size exceeds the limit.
    undefined
    undefined

Setting Properties

Now, let’s get the properties set to these components so as to validate the character limit

  1. Nothing to set on the Text Input ‘Message’ for this example.
  2. Let’s move to the label CharLength itself. Set the Text handler of the CharLength label control to the following (You can have your own limit)
    undefined
    In the above example, I’ve set the length 60 and then I’m subtracting the length of the Text of the Message.Text (Text entered in Message box) so that as we type on, the remaining value will be shown as below –
    undefined
  3. Now, let’s see the Color property of the text field. It’ll be a visual cue indicating the user that they’ve exceeded the character limit
    undefined
    In the above example, I’ve added a condition to set the color as Red, if the length is exceeded or Black is the length is under the limit and will look something like below –
    undefined

  4. Finally, we’ll go to the Submit button and set the Display Mode property of it to the below
    undefined
    I’ve added a condition, that if the Length of the Message box’s Text goes above the limit, set the Display Mode to Edit i.e. Active or else, Disable. And it will look like below when disabled
    undefined


Execution

This is how it will work when you put this in execution

And that’s it. So you can use this validation as you want. In place of the button, you could have something else put up.

Hope this helps!

Here are some posts on Canvas Power Apps you might want to check –

  1. Logged In User details in a Canvas Power App
  2. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  3. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  4. Variables in Canvas Power Apps | Global and Context
  5. Correctly connect to an Excel file in a Canvas PowerApp
  6. Adding a Canvas PowerApp to Teams
  7. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Thanks!!

Logged In User details in a Canvas Power App

You do get some details of the logged in user in a Canvas Power App. Let’s look at what all is available –

undefined

User() Function

User() function provides 3 pieces of information you can retrieve at this point in terms of logged in user.

undefined

Email

Use User().Email to populate a Text field with the Email address of the logged in user.
undefined

Full Name

Use User().FullName to fetch the logged in user’s Full Name and maybe, populate it in a Text/Label field as well
undefined

Image

Use User().Image to be able to populate the Picture control with the logged in User’s Picture. Remember, user needs to add this in their respective Office 365 account in order to appear here
undefined
undefined

User Details

Now, whenever a logged in user comes across these controls which we set above, the User details will vary for each user respectively. Below is how it looks for me.

undefined

You can obviously use it as and where it suits you.

Here are some more Canvas Power Apps posts you might want to look at –

  1. Variables in Canvas Power Apps | Global and Context
  2. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  3. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  4. Adding a Canvas PowerApp to Teams
  5. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Hope this was easy and helpful!

Variables in Canvas Power Apps | Global and Context

For all newbies, being able to use Variables is one the most curious questions put out immediately. Here’s a simplistic example of using Variables, both Global and Contextual in this post.

headerImg

Global Variable

Global Variables as the name suggest, run through the entire App itself and can be changed and altered when needed.
Global variables can hold boolean, string, number etc.

  1. Let’s say, I have a Text field called GuestNameField
    guestFieldAdded
    guestNameFieldView
  2. Global Variables are created and set by using Set(variable, value) function.

    Now, on the OnChange event of the GuestNameField above, I’m setting the variable by the formula Set(guestName, GuestNameField.Text). Where, guestName is the field I created on the fly and I’m setting the text from the GuestNameField textbox whenever the Textbox will trigger OnChange Event.
    formulaWritten

  3. And I have a Label called as DisplayValue which will read from the variable and set it’s text.
    readFromVar
  4. Now, when I run the app and type the name, and when I release the focus on the text box, the
    typeName
    And when the focus from the TextBox is released, OnChange of the TextBox will trigger and the Label will display the text written since it’s reading the value from the variable
    appear

Context Variable

Now, a variation to the Context Variable from the Global Variable is that the Context variable have the scope of the only the current screen they are declared in. Navigate function is also a form of Context variable in which case, you can pass values to other screens.

Context variables can hold strings, numbers, records and tables.

  1. Now, in case of Context Variables, you use UpdateContext({variable: value}) in the formula.
    contextVar
  2. And is accessed/read by simply writing the name of the variable directly
    directContextVarName
  3. And it behaves in the same way, you write something and it can be read
    typeName
    And displayed below as seen in the above Global Variable example
    appear

Checking your Variables

In case you’re wondering you’ll lose track of your variables, you can check the File menu and access the Variables section as shown below
menuItem

Global Variables as marked above can be accessed in their own section
globalStored
And if you open any of those, you can see and even navigate to where they are used.
globalUsage

Similarly, for Context Variables are denoted by the Screen names they are in.
contextStored

I tried to summarize this on a high level. You can refer this Microsoft Documentation for details Understand canvas-app variables in Power Apps.

Hope this was easy!

In case you are looking for more post related to Canvas PowerApps, here you go –

  1. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  2. Adding a Canvas PowerApp to Teams
  3. Correctly connect to an Excel file in a Canvas PowerApp
  4. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Thank you!

Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform

One of the most common asks when using CDS as Data Source in a Canvas Power Apps is – How do I get the data from N:N entities?

Well, I’m attempting to explain this in the easiest way possible.

Scenario

Let’s assume Account entity has an N:N relationship with Account Plans entity

Account <–N:N–> Account Plans.

And in Dynamics 365, you simply add these records by going into related records and adding them using Add Existing button
addExistingInD365

And now, you want to access this data for a record in a Canvas Power App? Correct? Let’s get going with it.

Enable the Entities involved

In this example, the entities involved are Account and Account Plans

  1. Accessing data for N:N entities require the entities to be enabled for Change Tracking. Let’s check that in CDS
    settingsOfAccount
    changeTrackingEnabled
  2. And also the same thing for Account Plan entity as well
    settingsOfPlans
    changeTrackingEnabled

Reading Data in a Canvas Power App

I’ve kept the presentation of my Canvas Power App very crude, please excuse me for that.

Scenario: Now, let’s say you want to see the N:N data on selection of a record i.e. on selection of Account, you want to see what all Account Plans are added to that Account.

  1. Now, to demonstrate this, I’ve taken 2 galleries i.e. AccountGallery to show list of Accounts
    accountGallery
  2. And probably a list to just display what Account Plans are added (You can have any other control depending on what you want to do with these records). I’ll call the table AccountPlansTable
    accountPlansTable
  3. And my formula to display the N:N records will be –
    AccountGallery.Selected.’Account Plans’
    aboutToSelect
    finalFormula
  4. Now, you’ll need to add what fields should be shown from Account Plans entity to identify the records. Well, obviously, Name field is the most relevant here.
    I’ll click on Edit Fields for the AccountPlansTable
    editFields
  5. And add the name field from that entity
    nameAndAdd
  6. Once this is set, my App is ready to run
    preparedApp

Accessing the N:N records

Let’s run the app and see how we can read these N:N records
Once I click on ABC/1/2&3, I can see the related N:N records in the DataTable below
working
Simple enough!

Here are some more posts you might like –

  1. Create your first PowerApp! Connect to SharePoint Online List
  2. Dynamics 365 Solutions’ New Experience in Power Apps, Solution Checker and more
  3. AutoNumber field in CDS | PowerApps
  4. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Hope this helps!!

Adding a Canvas PowerApp to Teams

Let’s take a look at how you can simply export the Canvas App from your Organization and import it to Teams. And you should be good to go!

Exporting Canvas App

  1. Assuming you are an Admin and you have Owner/Co-Owner rights to the App, you can click the ellipses part on the App and look for Add to Teams option.
    addToTeams
  2. Once done, you can check on the right hand-side to see some details and Download the zip file of the Canvas App when ready
    downloadApp
  3. And that’s it, it gets downloaded like any other Model Driven/Canvas App solution file.
    downloaded

 

Importing App to Teams

  1. Now, you can import the same as a custom App in Teams. Navigate to the Apps section and look for Upload a custom app in menu as shown below.
    uploadACustomApp
  2. Now, chose the Org you want to import the solution file to. In my case, it’s just one organization, you may have multiple.
    selectOrg
  3. A dialog box will pop up to ask you to select the solution file, navigate to the saved location and pick the file.
    selectSolution
  4. And you’re ready. The App has been imported. You can see it in the Apps section under Built for CFT 146.
    findAppOnTeams

 

Adding App Per User

Each user needs to add the App themselves in order to be able to access it.

Also, remember that the user who is adding the App should have rights to access the App itself i.e. the App should be shared with those users.

Let’s say Kuldeep is another user in the CFT 146 Organization. He can explicitly search for the App and add it as below –

  1. Go to Apps, then look for the area, Build For <Org Name> and then look for the App that was imported.
    Attendees AppfindAppOnTeams
  2. Click on the App, and the dialog box will provide with a button to Add to Teams, along with other details mentioned alongside.
    clickAdd
  3. Once added, it will appear next in the left navigation menu and you can simply run it by clicking on it.
    appRunning
  4. In case the user doesn’t have appropriate rights on the App, they will see this message when trying to open the App in Teams.
    errorInAccessing

Hope this helps!! Happy 365ing!