cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AB4N
Frequent Visitor

Combine multiple If statements with different true/false

I'm pretty new to powerapps but learning as I go. Is there a way to write the following if statements as one statement? (that way it will only create one item on my sharepoint list, instead of seperate items for each if statement). I am struggling to do so as each If statement has a different 'if false' and 'if true' parts.

 

If(
    IsEmpty(MondayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Monday: DataCardValue82.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Monday: Concat(
                MondayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(
    IsEmpty(TuesdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Tuesday: DataCardValue83.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Tuesday: Concat(
                TuesdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(
    IsEmpty(WednesdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Wednesday: DataCardValue84.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Wednesday: Concat(
                WednesdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);

 

 Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User III
Super User III

@AB4N 

I would say "no" you cannot write code this as a single IF statement.  Why?

You must have 3 separate IF statements because your goal is to check each of these conditions independently.

 

IsEmpty(MondayCombo.SelectedItems)
IsEmpty(TuesdayCombo.SelectedItems)
IsEmpty(WednesdayCombo.SelectedItems)

 

Writing an IF statement to combine them like this would not work.  After the 1st true condition is found PowerApps does not continue checking the rest of the conditions.  For example if MondayCombo is empty some_code_here1  would execute and then PowerApps would quit the IF statement without evaluating the TuesdayCombo and WednesdayCombo.

 

If(
    IsEmpty(MondayCombo.SelectedItems),
    some_code_here1,
    IsEmpty(TuesdayCombo.SelectedItems),
    some_code_here2,
    IsEmpty(WednesdayCombo.SelectedItems),
    some_code_here3
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

2 REPLIES 2
DavidJennaway
Solution Supplier
Solution Supplier

You can combine multiple conditions in one If statement. The general structure is If( Condition1, ThenResult1 [, Condition2, ThenResult2, ... [ , DefaultResult ] ] ). However it's not clear what your overall logic is. Is it that you want to create one record, with values for Monday, Tuesday etc. ?

 

 

mdevaney
Super User III
Super User III

@AB4N 

I would say "no" you cannot write code this as a single IF statement.  Why?

You must have 3 separate IF statements because your goal is to check each of these conditions independently.

 

IsEmpty(MondayCombo.SelectedItems)
IsEmpty(TuesdayCombo.SelectedItems)
IsEmpty(WednesdayCombo.SelectedItems)

 

Writing an IF statement to combine them like this would not work.  After the 1st true condition is found PowerApps does not continue checking the rest of the conditions.  For example if MondayCombo is empty some_code_here1  would execute and then PowerApps would quit the IF statement without evaluating the TuesdayCombo and WednesdayCombo.

 

If(
    IsEmpty(MondayCombo.SelectedItems),
    some_code_here1,
    IsEmpty(TuesdayCombo.SelectedItems),
    some_code_here2,
    IsEmpty(WednesdayCombo.SelectedItems),
    some_code_here3
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (43,536)