Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Experimental Features
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:
  • adedapo Profile Picture
    256 on at
    Re: Named Formulas Issues: Conditional record creation

    Tested and confirmed myself.

    Thanks

  • mvkr09552 Profile Picture
    Microsoft Employee on at
    Re: Named Formulas Issues: Conditional record creation

    @sopatte confirmed that this issue is resolved in version 2303.2

  • JorisdG Profile Picture
    on at
    Re: Named Formulas Issues: Conditional record creation

    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.

  • SoPatt Profile Picture
    Microsoft Employee on at
    Re: Named Formulas Issues: Conditional record creation

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

  • adedapo Profile Picture
    256 on at
    Re: Named Formulas Issues: Conditional record creation

    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
    Re: Named Formulas Issues: Conditional record creation

    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)

     

     

  • JorisdG Profile Picture
    on at
    Re: Named Formulas Issues: Conditional record creation

    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.

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics