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 Platform Community / Forums / Power Apps / Best uses for Named Fo...
Power Apps
Answered

Best uses for Named Formulas?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Named Formulas have been pretty cool so far and have helped me cut down on a lot of redundant code in apps. However, I'm still hesitant to convert certain processes into formulas because I'm worried about performance issues.

 

For example, I have an app that switches to night mode at 7pm and light mode at 7am. At the start of each minute, before it processes any of the other data, it checks to see what time range it falls under and sets the global color variable accordingly. All of the elements on the page that use the color variable automatically update their colors without having to run the time check themselves.

 

From what I understand, named formulas are beneficial because they are always current and only are calculate when they are referenced. However, if I moved the global color variable to a formula, it seems like it would cause *more* work to be done instead because each element referring to this formula would need to check the night mode status for themselves. Am I understanding this correctly, or am I misunderstanding the feature?

Categories:
I have the same question (0)
  • Verified answer
    JorisdG Profile Picture
    Microsoft Employee on at

    The named formula won't be recalculated every time it's accessed (only first access, and any subsequent recalcs would be triggered). So as far as elements accessing it, it's no different than using a global variable. But you get the benefit of the (possibly) delayed execution mode etc. - including startup if you're currently setting your variable in the OnStart.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Ok, thanks. How would I manually trigger the recalculation in other cases? For example, I have a formula that calculates the current time in seconds and uses that to help place a timeline marker in my app.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    As it turns out, I may need to return some of these items back to global variables, as

     

    f_IsDarkMode=(Hour(Now()) < 7 || Hour(Now()) >= 19);

     

    is returning true for me (I first opened the app before 7am, but it is now past that time), rather than becoming false.

  • JorisdG Profile Picture
    Microsoft Employee on at

    How/when do you recalculate the global variable?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I set it in the OnSelect of a data refresh timer that runs about once every minute (this is invoked by its own OnTimerEnd, to avoid any possibility of the timer failing to complete the task for too long). It uses the same logic as the above, but as an if statement that changes the values of gblColorValues based on the result (I tried doing the same in the named formula, but it did not remove the issue of the value not being recalculated when its logic should be providing a different result).

  • JorisdG Profile Picture
    Microsoft Employee on at

    I see. Yes a variable seems to make sense. However, given that formula I don't see why you would need to run a timer every minute? Since you know the current time and when you want to change it, can you not set the timer duration to match roughly when you want the dark mode setting to change? Duration allows up to 24 hours so covers your scenario of 7h/19h.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    true, i guess that would make a lot of sense since i would only have to calculate that once! thanks lol

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 525 Most Valuable Professional

#2
Haque Profile Picture

Haque 308

#3
Kalathiya Profile Picture

Kalathiya 234 Super User 2026 Season 1

Last 30 days Overall leaderboard