cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JasonWS
Resolver II
Resolver II

Gallery: Can't CountRows on attachments w/ If/Then as data source

I have an odd problem with a gallery. I have an If/then function to change the data source of a gallery. Both are the same source, one with, and one without a filter. The If function checks the value of a toggle. I'm doing this to avoid the delegation warning that occurs when I place the if/then function directly inside the the filter function. What's happening, is when both the true and false statements are provided, my CountRows(ThisItem.Attachments) function within the gallery returns no value. ThisItem.'Has Attachments' is functioning as normal. If I remove the false portion of the data source formula, it magically starts working. This is the only thing not working, and there is no error or warning.

 

Here is the result with both the true and false portions in the formula. (The If function is currently true). See arrow at the bottom.

JasonWS_0-1665673084445.png

 

And here is the exact same thing, but with the false portion omitted (The statement is still true, meaning the gallery contains the same items from above): See arrow at bottom.

JasonWS_1-1665673542188.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@JasonWS 

In general it is bad practice to use If statements in your Items property.  There ais only one condition that I know of where it is acceptable to use.

 

Not only are you seeing the issue you are, but you are also repetitively duplicating your formulas in the Items property.

 

Please consider changing your Formula to the following:

SortByColumns(
    Filter('Receiving Log',
        StartsWith(Title, txt_SearchContainers_1.Text),
        !Toggle1.Value || Status.Value = "Staged" || Status.Value = "In Progress"
    ),
    "ReceivingDateTime"
)

This is equivalent to your prior formula but excludes the If statement and duplication.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@JasonWS 

In general it is bad practice to use If statements in your Items property.  There ais only one condition that I know of where it is acceptable to use.

 

Not only are you seeing the issue you are, but you are also repetitively duplicating your formulas in the Items property.

 

Please consider changing your Formula to the following:

SortByColumns(
    Filter('Receiving Log',
        StartsWith(Title, txt_SearchContainers_1.Text),
        !Toggle1.Value || Status.Value = "Staged" || Status.Value = "In Progress"
    ),
    "ReceivingDateTime"
)

This is equivalent to your prior formula but excludes the If statement and duplication.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you for the enlightenment regarding If statements in the items property. How is this able to work properly? I thought the filter continues to evaluate through each of the OR || items? Regardless, thank you so much, it is working beautifully!

RandyHayes
Super User
Super User

@JasonWS 

The primary motive in the Filter function is to return a true or false.  Filter iterates through every row of your datasource (delegated if it can delegate, locally if not).  During that iteration, it will evaluate the formula in the criteria.  The formula evaluates to either true or false.  If it is true, the current iterated row is included in the results table.  If false, it is not.  

So, the formula I provided just uses plain old Boolean logic to evaluate to either true or false.

If the Toggle is not on, then !Toggle1.Value will return true.  Since it is OR'ed with all the other values, it doesn't make a difference what they return because true OR'ed with anything else will always be true.

With toggle turned on, !Toggle1.Value will be false.  So, the rest of the formula is evaluated.  If either of the other two conditions are true, then the result is true and the record included.  If not, then the record is ignored.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Now I understand. Thank you so much! I think I've had delegation issues elsewhere in my app that you may have just solved with this 🙂

RandyHayes
Super User
Super User

@JasonWS 

Excellent!

 

Yes...if you use IF statements in the Criteria that should evaluate to true or false, this often leads to delegation issues.  Always thrive for straight Boolean logic.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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