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 / PowerApps, trying to u...
Power Apps
Unanswered

PowerApps, trying to use Collect , inside a If statement while the If statement is inside a ForAll iteration

(0) ShareShare
ReportReport
Posted on by 46
ForAll(
    ComboBox1_21.SelectedItems As a,
    If(
        IsBlank(
            LookUp(
                collectICSGBUBrands,
                ICSPeriod = Dropdown2_58.Selected.Name And
                ICSYear = Dropdown2_57.Selected.Name And
                Name = ComboBox1_45.Selected.Value And
                Entitiesmapping = Value(a.EntityCode)
            )
        ),
        // If the condition is true, execute the Patch function to update the data source:
       
        Patch(
            ICSGBUBrands,
            Defaults(ICSGBUBrands),
            {
                Name: Concatenate(ComboBox1_45.Selected.Value, "bhasker"),
                Entitiesmapping: Value(a.EntityCode),
                ICSYear: Dropdown2_57.Selected.Name,
                ICSPeriod: Dropdown2_58.Selected.Name
            }
        ),
        // If the condition is false, skip this iteration and move to the next element:
        Blank();
        Collect(test123,a.EntityCode)  // This line is giving error also tried Collect(test123,"Dummystring") , still same error
    )
);


I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    on at

    Hi @bkumar ,

     

    Is it invalid argument type error? If so, the reason is within If statement, true and false results need to be with the same structure and data type. Please try and use Switch function instead:

    ForAll(
     ComboBox1_21.SelectedItems As a,
     Switch(
     IsBlank(
     LookUp(
     collectICSGBUBrands,
     ICSPeriod = Dropdown2_58.Selected.Name And
     ICSYear = Dropdown2_57.Selected.Name And
     Name = ComboBox1_45.Selected.Value And
     Entitiesmapping = Value(a.EntityCode)
     )
     ),
     true,
     // If the condition is true, execute the Patch function to update the data source:
     Patch(
     ICSGBUBrands,
     Defaults(ICSGBUBrands),
     {
     Name: Concatenate(ComboBox1_45.Selected.Value, "bhasker"),
     Entitiesmapping: Value(a.EntityCode),
     ICSYear: Dropdown2_57.Selected.Name,
     ICSPeriod: Dropdown2_58.Selected.Name
     }
     ),
     false,
     // If the condition is false, skip this iteration and move to the next element:
     Collect(test123,a.EntityCode)
     )
    );

     

    Best regards,

  • bkumar Profile Picture
    46 on at

    Dear @v-jefferni , many thanks for your kind reply.
    yes the error was "there is a invalid argument in the ForAll" 
    It worked perfectly with your code

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 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard