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 / Don't repeat yourself....
Power Apps
Answered

Don't repeat yourself...in a label text

(0) ShareShare
ReportReport
Posted on by 678

I am doing this... in the label text value...

If(CountRows(Filter(Customers,TicketRequestId=selectedTicketRequestEventID))>0,"View/Edit the " & CountRows(Filter(Customers,TicketRequestId=selectedTicketRequestEventID)) & " Customers","Add Customers")

I'm repeating some code with the countrows twice...
How could I do with once only so I don't repeat myself. I assume I can do a "with" here somehow...

Still getting comfortable with "withs"

 

Categories:
  • ansrikanth Profile Picture
    329 on at

    @sasrsc why dont you set it to a context variable or variable and use it? something like 

    Set(RowCount,CountRows(Filter(Customers,TicketRequestId=selectedTicketRequestEventID))>0);
    If(RowCount>0,"View/Edit the " & RowCount & " Customers","Add Customers")

    Thank you

    -Srikanth

  • cwebb365 Profile Picture
    3,334 Most Valuable Professional on at

    This should work. 

    WITH(
    {CountedCustomers: CountRows(Filter(Customers,TicketRequestId=selectedTicketRequestEventID))}
    )
    If(CountedCustomers >0,"View/Edit the " & CountedCustomers & " Customers","Add Customers")
    
  • Verified answer
    sasrsc Profile Picture
    678 on at

    Thank you both of you.... 

     

    FWIW I had to make a slight tweak with parenthesis to @cwebb365 solution for that to work. 

    With(
     {
     CountedCustomers: CountRows(
     Filter(
     Customers,
     TicketRequestId = selectedTicketRequestEventID
     )
     )
     },
     If(
     CountedCustomers > 0,
     "View/Edit the " & CountedCustomers & " Customers",
     "Add Customers"
     )
    )

     In the end I had multiple places where I needed the calculation so that logically took me to the @ansrikanth 's solution, although I'll use a context Variable.

    My follow up question is - if there was only one place where I needed this then which is the "most efficient" method. 
    A context variable or the with idea?
    Is there actually any difference behind the scenes in performance. I realize it's so insignificant but I'm just curious.

  • ansrikanth Profile Picture
    329 on at

    Honestly, AFAIK the performance difference what you are talking about is so insignificant that it is not worth to discuss also especially when you are talking about a single valued text 🙂..

    Behind the screen MS must be defining some variables to bind the values, it may just vary the life time of it.

     

    Thank you-

    Srikanth

    Please mark the correct answer for the question to help others as well.

     

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 337 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 250

#3
Mohsin Ali Profile Picture

Mohsin Ali 225

Last 30 days Overall leaderboard