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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

With Function

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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,299 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

#2
11manish Profile Picture

11manish 224

#3
Valantis Profile Picture

Valantis 181

Last 30 days Overall leaderboard