web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Apps
Answered

With Function

(0) ShareShare
ReportReport
Posted on by

Hi all,

I'm looking into the With function and I'm wondering about it's purpose.

Is there a practical scenario where using it unavoidable?

The way I see it is that it's purely used to organize your code at the start and have a cleaner/shorter equation a the end.

Is that about right or is there something I'm missing?

Thanks!

Categories:
I have the same question (0)
  • BCLS776 Profile Picture
    8,994 Moderator on at

    It has some very useful purposes beyond code clarity. Check out Warren's blog on the topic.

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    With is one of the more powerful functions in PowerApps that you will use.  Once you start using it, you will find it invaluable.  Beyond the ability to simplify your formulas, it also reduces variables that are in your app.  In general, variables should be avoided as much as possible, but there are many times that you need (or want) to encapsulate something in a variable only for the purpose of a formula you are writing.  Using the With function allows you to have this type of variable while not incurring the cost of having the variable in your overall app (eases maintenance of your app as well).

     

    As a basic example, consider the following formula:

    {
     Record: 1,
     Title: LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today(), Title),
     ColA: LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today(), ColA),
     ColB: LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today(), ColB),
     ColC: LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today(), ColC),
     ColD: LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today(), ColD)
    }

    Using the With function, it becomes this:

    With(LookUp(someDataSource, someColumn = "SomeValue" && someOtherColum = "SomeOtherValue" && DateColumn >= DateAdd(Today(), -10, Days) && DateColumn <= Today()),
     {
     Record: 1,
     Title: Title,
     ColA: ColA,
     ColB: ColB,
     ColC: ColC,
     ColD: ColD
     }
    )

    Not only is the above cleaner to read, it also is more performant as we only do 1 lookup as opposed to 5.

     

    I could site a million examples of how great with is...the above is just one.

     

    I hope this is helpful for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard