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 Platform Community / Forums / Power Apps / Named Formulas Issues:...
Power Apps
Unanswered

Named Formulas Issues: Conditional record creation

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

App.Formulas:

MyProfile = Office365Users.MyProfile();
MyEmail = MyProfile.Mail;
MyData = Filter(
 UserData,
 'Created By'.Email = MyEmail
);
MyLocationFilterRecord = With({
 ExistingRecord: LookUp(
 MyData,
 Title = "LocationFilter"
 ),
 TargetOfficeLocation: "OfficeLocation|" & MyProfile.OfficeLocation
},
 If(IsBlank(ExistingRecord),
 Patch(
 Defaults(UserData),
 {
 Title: "LocationFilter",
 Value: LookUp(
 Metadata,
 Title=TargetOfficeLocation,
 Data
 )
 }
 ),
 ExistingRecord
 )
)

Then in my StartScreen .OnVisible:

Patch(
 UserData,
 MyLocationFilterRecord,
 {}
)

What I want is to create a new record unless a record already exists. What I get is a new record even when a record already exists.

All in all Named Formulas is a great concept that would simplify app code, but they don't seem to work. It seems like at times the named formulas are not evaluated when one would expect them to be. Any time there is a reference to a named formula, the promise is that it would be evaluated at that time. That does not seem to be the case. For now I have to keep using App.OnStart or a Loading Screen .OnVisible

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

    The named formula is evaluated any time anything in the formula is changed that would require it to be re-evaluated, or the first time the formula is referenced. I think you may be trying to use the named formula as a function, which it most certainly is not. The idea of the named formula and its relevance for performance is that it is only evaluated when it needs to.

    We do plan to add a feature for user defined functions in the not-too-distant future (very likely some kind of preview in the 2023 calendar year). We will also be coming out with updates to enhanced component properties (in the next month or two!) that lets you define behavior properties that can essentially be a workaround for creating your own behavior functions.

  • SoPatt Profile Picture
    Microsoft Employee on at

    I'm trying to use it in any way that will work. I suppose it's similar to a function but that doesn't tell me anything about how I can use it better. I suppose it's not necessary that they be evaluated every time they are referenced. I guess it would be more accurate to say any time they are referenced you would expect them to be evaluated if any of their dependencies have changed. I also tried just using it like this:

     

     

    MyProfile = Office365Users.MyProfile();
    MyEmail = MyProfile.Mail;
    MyData = Filter(
     UserData,
     'Created By'.Email = MyEmail
    );
    MyLocationFilterRecord = LookUp(
     MyData,
     Title = "LocationFilter"
    )

     

     

    My "if it's blank" logic was then in my loading screen's OnVisible. But that also didn't work any better.

     

     

    With({
     TargetOfficeLocation: "OfficeLocation|" & MyProfile.OfficeLocation
    },
     If(IsBlank(MyLocationFilterRecord),
     Patch(
     Defaults(UserData),
     {
     Title: "LocationFilter",
     Value: LookUp(
     Metadata,
     Title=TargetOfficeLocation,
     Data
     )
     }
     )
     )
    );
    Refresh(UserData)

     

     

  • adedapo Profile Picture
    256 on at

    The issue seems to be that Named Formulas that are referenced in imperative logic are evalutated for the first time after the calling function. This means they are essentially uninitialized variables at the time the calling function is evaluated.

  • SoPatt Profile Picture
    Microsoft Employee on at

    I agree. That seems to be the case. In my mind, it doesn't seem like that should ever be the case. 

  • JorisdG Profile Picture
    on at

    That should not be the case but this may have to do with delegation of the datasource here (which we know there's an issue). I'm working with the engineers to understand this.

  • mvkr09552 Profile Picture
    Microsoft Employee on at

    @sopatte confirmed that this issue is resolved in version 2303.2

  • adedapo Profile Picture
    256 on at

    Tested and confirmed myself.

    Thanks

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 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard