Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
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
    )
);


  • bkumar Profile Picture
    46 on at
    Re: PowerApps, trying to use Collect , inside a If statement while the If statement is inside a ForAll iteration

    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

  • Verified answer
    v-jefferni Profile Picture
    on at
    Re: PowerApps, trying to use Collect , inside a If statement while the If statement is inside a ForAll iteration

    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,

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 Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 55 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 42 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 31 Super User 2025 Season 1

Overall leaderboard