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

Improving formula.

(1) ShareShare
ReportReport
Posted on by 277

Hello guys, 

 

I have this formula, which is working fine, but I'm unsecure if this the best clear a professional code.

 

If(
 VarIsAssistant,
 Search(
 Filter(
 'matter engagement letters',
 'Engagement Letter Status' <> 'Engagement Letter Status Choice'.'Verified and complete',
 'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value || IsBlank(txtSearchAttorney_1.Selected),
 Assistant.'Primary Email' = User().Email
 ),
 txtSearchMatter_1.Value,
 'Matter Name',
 MatterNumber
 ),
 Search(
 Filter(
 'matter engagement letters',
 'Engagement Letter Status' in txtSearchStatus_1.SelectedItems || IsBlank(txtSearchStatus_1.Selected),
 'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value || IsBlank(txtSearchAttorney_1.Selected)
 ),
 txtSearchMatter_1.Value,
 'Matter Name',
 MatterNumber
 )
)

 

So, I wonder if you have an idea how to improve it.

 

Thank you, 

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @ADumith - in general I think your code looks fine to me (assume your data source is Dataverse).

     

    My preference would be to leverage the With function to avoid repeating any lines of code as much as possible. I would also clean up your OR operators.

     

    With(
     {
     filtered_data_one: Filter(
     'matter engagement letters',
     'Engagement Letter Status' <> 'Engagement Letter Status Choice'.'Verified and complete',
     Len(txtSearchAttorney_1.Selected.Value) = 0 || 'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value,
     Assistant.'Primary Email' = User().Email
     ),
     filtered_data_two: Filter(
     'matter engagement letters',
     CountRows(txtSearchStatus_1.SelectedItems) = 0 || IsBlank(txtSearchStatus_1.SelectedItems) || 'Engagement Letter Status' in txtSearchStatus_1.SelectedItems,
     Len(txtSearchAttorney_1.Selected.Value) = 0 || 'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value
     )
     },
     With(
     {
     select_data: If(
     VarIsAssistant,
     filtered_data_one,
     filtered_data_two
     )
     },
     Search(
     select_data,
     txtSearchMatter_1.Value,
     'Matter Name',
     MatterNumber
     )
     )
    )

     

  • Verified answer
    ADumith Profile Picture
    277 on at

    Hello, 

     

    Thank you for your reply.

     

    I tried to use your code, but is not working.

     

    The Len(txtSearchAttorney_1.Selected.'Full Name') is not working, actually it's returning the error:

    Name isn't valid. 'Full name' isn't recognized 

     

    However, this formula is working fine, but I like your idea. So, we can fix the error I would love use your formula.

     

    If(
     VarIsAssistant,
     Search(
     Filter(
     'matter engagement letters',
     'Engagement Letter Status' <> 'Engagement Letter Status Choice'.'Verified and complete',
     'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value || IsBlank(txtSearchAttorney_1.Selected),
     Assistant.'Primary Email' = User().Email
     ),
     txtSearchMatter_1.Value,
     'Matter Name',
     MatterNumber
     ),
     Search(
     Filter(
     'matter engagement letters',
     'Engagement Letter Status' in txtSearchStatus_1.SelectedItems || IsBlank(txtSearchStatus_1.Selected),
     'Billing Attorney'.'Full Name' = txtSearchAttorney_1.Selected.Value || IsBlank(txtSearchAttorney_1.Selected)
     ),
     txtSearchMatter_1.Value,
     'Matter Name',
     MatterNumber
     )
    )

     

    Thank you, 

     

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @ADumith 

     

    is there a reason why u want to change the code? If it works, i would not change anything to be honest 😉

     

     

  • ADumith Profile Picture
    277 on at

    Hello @mmbr1606 

     

    I really don't want @Amik to feel that I don't value the effort in rewriting the formula.

     

    It is a way of being grateful.

     

    Does it make sense to you?

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    Hey 

     

    No i was just asking in general nit about the answer of Amik, just wanted to know why u wamt to change tge exiating formula 😁

  • ADumith Profile Picture
    277 on at

    Hello @mmbr1606 

     

    If there's one thing I've learned is that it's always possible to improve something, and @Amik 's idea is great, it's just not clear to me why it doesn't work.

     

    I'm looking into it.

     

    Have the best day possible. 

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @ADumith - that is a good attitude to have. Just because something works does not mean it works in the most efficient way (and repeating lines of code is not efficient!).


    I edited my code a few seconds after posting it yesterday, but it seems your browser caught the old version. Note in my code I have Len(txtSearchAttorney_1.Selected.Value)

  • ADumith Profile Picture
    277 on at

    Hello @Amik ,

     

    I was testing the formula and I realized something, when I apply it in the table something strange happens, it turns out that the column of the assistants is blank, no record is shown, but when I return to place the previous formula everything works again.

     

    Do you have any idea why this behavior?

     

    Thank you,

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @ADumith - when you say the "assistants" is blank, does that mean the rest of the columns in the record are still returned?

  • ADumith Profile Picture
    277 on at

    @Amik 

     

    Let me show.

     

    With my formula:

    ADumith_0-1715278541817.png

     

     

    With your formula:

    ADumith_1-1715278673526.png

     

     

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard