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

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
    Microsoft Employee 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,074

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 606

Last 30 days Overall leaderboard