web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / how to use ForAll to c...
Power Apps
Suggested Answer

how to use ForAll to check the condition for each record from two different tables

(2) ShareShare
ReportReport
Posted on by 7
Hi there,
I am new to Power Apps and I need to make a code change on the existing Canvas App using the formula (Power Fx).
Since the developer who worked on this has retired and we have tight deadline to work on adding new features to old code base which was never released.
The lead of the project suggested I post a question on the power app forum. 
 
The purpose of this Canvas app is to recognize employees' good work by awarding them a gift card. This task is to check if the employee already has an award in a pending state.
Then comparing the "Employee_Email" column from award table with "employee_email" in the employeeList. I believe powerFx is case sensitive. 
 
With my lead's help, I got it to work when only one employee checked. But if there are more than one employee is selected for awards, I have to loop through
the collection "colEmpInfo" which is a collection of Employee. I added my question in the code comment as TODO. I also attached the code to submit the award form for one and multiple employee
If(
 
        CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = First(colEmpInfo).employee_email ) ) < 1,
 
Below is the completed code for "OnSelect"
 
Switch(
 
    CountRows(colEmpInfo),
 
    0,
 
    UpdateContext({varPopupPendMsgFlag: true});
 
    UpdateContext({varPopupPendTitle: "Attention"});
 
    UpdateContext({varPopupPendMsg: "You have not selected any employee for requesting award"});
 
    UpdateContext({varPopupPendMsgColor: RGBA(255,0,0,1)}),
 
    1,
 
    If(
 
        CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = First(colEmpInfo).employee_email ) ) < 1,
 
        //ThisItem.employee_email
 
        Navigate(
 
            'Award New Form',
 
            ScreenTransition.Cover,
 
            {varAccountNo: drpReqEmpAwdAccNum.SelectedText.Value}
 
        ),
 
        UpdateContext({varPopupPendMsgFlag: true});
 
        UpdateContext({varPopupPendTitle: "Attention"});
 
        UpdateContext({varPopupPendMsg: "You have a pending award request for the selected employee : " & First(colEmpInfo).employee_email });
 
        UpdateContext({varPopupPendMsgColor: RGBA(255,0,0,1)});
        Clear(colEmpInfo);
 
    ), //selected one employee based on Award count
 
    // if there are more than one employee selected, we
    // need to loop through the collection colEmpInfo
    ForAll( colEmpInfo,
    If( CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = First(colEmpInfo).employee_email ) ) < 1,
    {
       //TODO, we cannot use the First(colEmpInfo) because we need to iterate through the collection of employee Info
       // but I am not sure the syntax of powerFx. In Java, there is enhanced for loop which I can just declare an element
       // I was trying to follow the below example but I noticed in this documentation, the collection was created using Product
       /**
       ClearCollect( Products,
        Table(
            { Product: "Widget", 'Quantity Requested': 6, 'Quantity Available': 3 },
            { Product: "Gadget", 'Quantity Requested': 10, 'Quantity Available': 20 },
            { Product: "Gizmo", 'Quantity Requested': 4, 'Quantity Available': 11 },
            { Product: "Apparatus", 'Quantity Requested': 7, 'Quantity Available': 6 }
         )
        )
       ForAll( Products,
       If( 'Quantity Requested' > 'Quantity Available',
         {
            Product: Product,
            'Quantity To Order': 'Quantity Requested' - 'Quantity Available'
          }
         )
       )
       */
    }
 )
);
 
    Navigate(
 
        'Multiple Awards New Form',
 
        ScreenTransition.Cover,
 
        {varAwdType: "emp"}
 
    ) //selected multiple employees
 
);
 
UpdateContext({resetChkEmpAwdBody: true});
 
UpdateContext({resetChkEmpAwdBody: false});
 
UpdateContext({resetNameSearch: true});
 
UpdateContext({resetNameSearch: false});
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
    Hi
     
    Change it to this
     
    If( CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = First(colEmpInfo).employee_email ) ) < 1,
     
    If( CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = ThisRecord.employee_email ) ) < 1,
     
    Since you want to access the current for all iteration use ThisRecord inplace of the Collection First etc

    Please mark as the answer
  • ZL-11092118-0 Profile Picture
    7 on at
    Thanks for the suggestion. But unfortunately, I cannot use ThisRecord.
     
    The collection "colEmpInfo" is for the selected employee which I want to give award. Not the entire employee list.
    So when I selected only one employee based on Award count, "colEmpInfo" will only have one element which is always First(colEmpInfo).employee_email. I know this is not ideal. But I worked with my team lead, but we could not figure out how to the current record. You suggested to use ThisRecord but he was trying to use ThisItem.
    However, ThisItem is not available in the context, even though he did show me ThisItem in the power app studio.
    The challenge is the code was written a couple of years ago by someone who is retired. 
     
    The reason I have to use First(colEmpInfo).employee_email is because I am comparing 
    award.Employee_Email with employee.employee_email from two different collections.
     
    In the below logic, Filter(Award, Lower(Status.Value)="pending" is to filter from the Award table
    which status = "pending" and the Employee_Email column needs to match the "employee_email"
    column from the employeeList table. Our data source is using the sharepoint. 
    I think Power Fx is case sensitive.
     
    CountRows(Filter(Award, Lower(Status.Value)="pending" && Employee_Email = First(colEmpInfo).employee_email ) ) < 1,
     
    I do see some strange behavior that the colEmpInfo is being cached 
    which means after I uncheck the previous employee I selected, the collection was cleared.
    So I added "Clear(colEmpInfo)" but it seems to mess up the logic and now all the employee seems to
    have pending request and gave me the warning message You have a pending award request for the selected employee
     
            UpdateContext({varPopupPendMsgFlag: true});
            UpdateContext({varPopupPendTitle: "Attention"});
            UpdateContext({varPopupPendMsg: "You have a pending award request for the selected employee : " & First(colEmpInfo).employee_email });
            UpdateContext({varPopupPendMsgColor: RGBA(255,0,0,1)});
            Clear(colEmpInfo)

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard