cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
david_castillo
Helper III
Helper III

Conditional Statements Not Working

I have a PowerApps that checks if a field is blank:

 

If( 
    Sum( 
        ExpenseCollection, 
        LineCost 
    ) = 0 || (IsBlank(DataCardValue57) || IsBlank(DataCardValue59) || IsBlank(DataCardValue60) || IsBlank(DataCardValue64) || IsBlank(DataCardValue63)  || IsBlank(DataCardValue65) || IsBlank(DataCardValue66) || IsBlank(DataCardValue67)), 
    false, 
    true 
) 

One of these fields is the one below, which checks that if it's empty, the Submit icon should not be open. When I test the first time, the conditional statement is working. However, when I remove one of the required fields, the submit icon gets visible (see below):

 

GetImage.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These are the required fields:GetImage (1).png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Hope anyone can help.

 

Thanks!

3 REPLIES 3
CarlosFigueira
Power Apps
Power Apps

IsBlank checks whether its parameter is null / blank - which is not the case for a control (DataCardValueXX). For the combo box controls that I think you're using, you can use their SelectedItems property to see how many items are selected (using the CountRows function), like in the example below:

If( 
    Sum( 
        ExpenseCollection, 
        LineCost 
    ) = 0 ||
        Coalesce(CountRows(DataCardValue57.SelectedItems), 0) = 0 || 
        Coalesce(CountRows(DataCardValue59.SelectedItems), 0) = 0) ||
        ...
        Coalesce(CountRows(DataCardValue67.SelectedItems), 0) = 0), 
    false, 
    true 
) 

If the combo box doesn't have any item selected, its SelectedItems property may return either a blank value, or an empty table, which is why the example above uses the Coalesce function to account for both cases.

@CarlosFigueira thanks for the quick response! So for look-up items, I should only use Coalesce so the function will work?

I believe the fact that the combo box doesn't return an empty table (returning a blank result instead) is a bug (see screen capture below) that we can workaround by wrapping the CountRows in the Coalesce call to handle the blank case - I've notified the team responsible for that control to get it fixed.

 

For lookup columns, I'm not sure if it has the same behavior, but you can test it out in your app without the Coalesce function. If it works fine, then you don't need it.

 

ComboboxSelectedItemsNull.gif

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

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,039)