Skip to content

Power Apps

Power Apps Guidelines For Improving Code Readability

Power Apps Guidelines For Improving Code Readability Table of Contents Apply Automatic Formatting Use The WITH Function Flatten Nested IF Functions Have A Co...

Matthew Devaney
Published
Reading time
3 min read

Before you start

Is this guide for you?

Best entry point
Power Apps
Time investment
3 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-coding-standards-for-canvas-apps/power-apps-guidelines-for-improving-code-readability/. Author: Matthew Devaney.

Power Apps Guidelines For Improving Code Readability Table of Contents Apply Automatic Formatting Use The WITH Function Flatten Nested IF Functions

Have A Consistent Naming Convention For Controls & Variables Join Text Strings And Variables Choose Consistent Logical Operators

Remove IF Statements When The Result Is A True Or False Value

Simplify Logical Comparisons When Evaluating A Boolean

Substitute The Self Operator For The Current Control Name

Alphabetize Patch & UpdateContext Function Arguments 1. Apply Automatic Formatting The formula bar’s

format text command applies indentation, spacing and line-breaks to Power Apps code.   Well-formatted code has two benefits.  It is easier to read and quicker to spot mistakes. Use the format text command to achieve a consistent coding style throughout a canvas app. A consistent coding style makes it easier for developers to work together on an app. 2. Use The WITH Function

Power Apps With function makes long formulas more readable.  For example, this formula which does not use the With function calculates the monthly mortgage payment for a house:

The mortgage calculation formula cannot be interpreted at-a-glance. It takes effort to parse. Compare it to the Power Apps code example using the With function. The formula is now human-readable because any complexity moved into one-time variables. 3. Flatten Nested IF Functions

Nested IFs are when multiple IF functions are placed inside one other. The more levels a nested IF contains the harder it becomes to understand.  Use a flat structure whenever possible to improve code readability.

4. Have A Consistent Naming Convention For Controls & Variables

Every control should follow a naming convention that includes the control type, the screen it is located on and the purpose of the control. Variables should also have a standard format that includes their scope and purpose. 5. Join Text Strings And Variables

Combining text can be done multiple ways in Power Apps: the & operator, the Concatenate function or $-String notation .  Choose one way of doing it and be consistent. 6. Choose Consistent Logical Operators The logical operator And

can be written 3 different ways: And, And(), &&.  There are often many ways to do the same thing in Power Apps code.  It’s OK to choose any option from the Power Apps code examples below but be consistent.

7. Remove IF Statements When The Result Is A True Or False Value

An IF statement that results in true or false is not necessary to write. Get rid of the IF statement and only write the logical comparison

8. Simplify Logical Comparisons When Evaluating A Boolean

A boolean value itself can be used as an argument to the IF function.  It is not necessary to write a logical comparison.

9. Substitute The Self Operator For The Current Control Name

The Self operator is a concise way to access properties of the current control. Use Self instead of the full control name to make code quicker to understand.

10. Alphabetize Patch & UpdateContext Function Arguments

When the Patch function have a large number of fields it takes more time to find and update them.  Use alphabetical order so the desired field can be quickly located.  This technique can also be applied to the UpdateContext function . Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions about Power Apps Guidelines For Improving Code Readability please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Share this

Tagged

Power Apps

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →