Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Explanation line of code Power Apps

(0) ShareShare
ReportReport
Posted on by 691

Hello, I am resuming an old Power Apps project that I had left aside. Being a beginner, I have a little trouble understanding some lines of code.

Can you please explain to me what this line of code does exactly (by detailing me each step of the line of code)? Thanks in advance !

If(varFilter = false ; Filter('Notes de frais'; StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text) && 'Créé par'.Email=User().Email); Filter('Notes de frais'; StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text)))

s44_0-1643575463107.png

 

  • Verified answer
    CarlosFigueira Profile Picture
    on at
    Re: Explanation line of code Power Apps

    Hello @s44 , let me first format the expression in multiple lines:

    1. If(
    2. varFilter = false;
    3. Filter(
    3.1. 'Notes de frais';
    3.2. StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text) &&
    3.3. 'Créé par'.Email=User().Email);
    4. Filter(
    4.1. 'Notes de frais';
    4.2. StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text))) 

    This is, line-by-line, what this expression is doing:

    1. It is a condition - it can have different results depending on...
    2. the condition 'varFilter = false' (the first argument to the If function). If the condition is true (i.e., the value of the variable called 'varFilter' is false), then
    3. The result of the operation will be the result of filtering...
      1. ...the data source 'Notes de frais', for all the records where the following conditions are true:
      2. The 'DisplayName' property of the 'Nom Prenom' field in the data source starts with whatever is in the TextSearchBox1 AND
      3. The property 'Email' of the field 'Créé par' is equal to the value of User().Email (the e-mail of the app user)
    4. If the condition 'varFilter = false' is false (i.e., the value of the variable called 'varFilter' is true), then the result of the operation will be the result of filtering...
      1. ...the data source 'Notes de frais', for all the records where the following conditions are true:
      2. The 'DisplayName' property of the 'Nom Prenom' field in the data source starts with whatever is in the TextSearchBox1

    Another way to describe it: the expression will be all the records in the 'Notes de frais' data source, where the 'DisplayName' property of the 'Nom Prenom' field starts with the value in the TextSearchBox1; if the value of the 'varFilter' is set to false, then the result will have an additional filter where only the records created by the current user are returned.

    Notice that the expression could be simplified, as pointed out by @WarrenBelz .

    Hope this helps!

  • WarrenBelz Profile Picture
    146,660 Most Valuable Professional on at
    Re: Explanation line of code Power Apps

    Hi @s44 ,

    The logic seems backwards

    If(
     varFilter = false; 
     Filter(
     'Notes de frais'; 
     StartsWith(
     'Nom Prénom'.DisplayName; 
     TextSearchBoxl.Text
     ) && 
     'Créé par'.Email = User().Email
     );
     Filter(
     'Notes de frais'; 
     StartsWith(
     'Nom Prénom'.DisplayName; 
     TextSearchBoxl.Text
     )
     )
    )

    and could be better written as

    Filter(
     'Notes de frais'; 
     StartsWith(
     'Nom Prénom'.DisplayName; 
     TextSearchBoxl.Text
     ) && 
     (varFilter || 'Créé par'.Email = User().Email)
    )

    but you have a Data Source 'Notes de frais' which has a Person field 'Nom Prénom' that is filtered by TextSearchBox1 where the person's name needs to start with what is entered in there AND if a Variable called varFilter is false (this seems the reverse bit), then also filter on the Person field 'Créé par' where their email address matches that of the logged-in user.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard