cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sasrsc
Helper V
Helper V

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

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"

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

4 REPLIES 4
ansrikanth
Resolver III
Resolver III

@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
Super User
Super User

This should work. 

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

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
Resolver III
Resolver III

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.

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,022)