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 / Set Toggle Control to ...
Power Apps
Answered

Set Toggle Control to true in form if all items in Gallery have same value

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

 

I have a toggle control in my master form to show if all items have been delivered; i want to toggle this to 'True' (else false) if all items in a SharePoint list have their value set to 'Yes' in the Delivered? column i.e. if only one item is set to 'No' then the Toggle value will remain 'False' in the form.  The common value for each item is PONumber.

 

Any help much appreciated,

 

kind regards,

 

Mike

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    Try this for your Default property:

     

       CountRows(Filter(SPList, Delivered<>false))>0

     

    BTW: There is a glitch/bug with filters on "Yes/No" SharePoint columns.  I have found the workaround to be to use the <> operator rather than the = will be something to keep in mind.  So, re-reading the filter above, I am filtering on "Delivered=true".  However, using that exact wording will yield improper results.  So, looking for the inverse of it will work "<> false" means "= true".

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Randy,

     

    Thanks for your response although i tried it and the toggel value is not changing as expected. I think the problem is that i could have mutliple values with the same PO Order number. I guess the forumla you have posted should bring back a true value even if just one of these values is set to true, however, it still does not seem to work.

     

    What i want is for the toggle value to only show true if all items have delivered set to true (or yes) . Hope attached screenshot better explains what i'm trying to achieve. The two rows in the gallery show two items from the POOrderDetails list and the Item Delivered toggle in the Form updates the POLog form.

     

    Any further help much appreciated. 

     

    thanks,

     

    Mike

    Powerapps_delivered.PNG
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    So you probably need to look at your filters a bit more and wrap your head around what is going on.

    It seems that you have a PO Items List, which is a filtered list of items that match the PO number you have in the master form (the top part of your screen).

    I don't know if POOrderDetails is a filtered collection or if it is a datasource of your Add/Edit PO Items list.

     

    So, one of the things you can use to shortcut all the filters is to use the data of the gallery as it is shown.  I personally do this often when filtering - filter once and then derive everywhere from that.  The reason I mention it is for my next suggestion, which is to change your toggle default logic to this:

     

       CountRows(Filter(POItemGalleryName.AllItems, ItemDelivered<>true))=0

     

    Notice in this case (not sure what your Gallery name is, but substitute it in there) that we're cunting the rows where the value is false ("No").  If it is 0 then we can say they are all true and our toggle should go to true.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks Randy!

    I tweaked your formula and it worked:

    If(CountRows(Filter(POOrderDetails,PONumber=Gallery1.Selected.PONumber, ItemDelivered=false))=0,"Yes","No")

     

    I replaced the toggle datacard with a text input one as i only needed Yes/No to be in View mode. The gallery was showing submitted values in the POOrderDetails list so pointed to that instead.

     

    Thanks again - much appreciated

     

    Mike

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Facing a similar issue here but with "super-nested JSON" response from a Custom Connector. Any insights are appreciated!

    Scenario: 

    • Gallery with items set to:
    First(
     First(
     colCustomConnectorResponse.level1
     ).level1.level2
    ).level2
    • Small toggles within the Gallery set to:
    If(
     ThisItem.level3.level4 = "Y",
     true,
     false
    )
    • Big toggle outside the Gallery to act as "master" toggle. BUT, if all small toggles = "Y" (true), the big toggle should be true also.
    • The code i'm trying is ridiculously long BUT only applies to the first, 4-nested toggle.
    • I need the code to check and see if all, 4-nested toggles are set to "Y"
    If(
     First(
    First(
    First(
    colCustomConnectorResponse.level1
    ).level1.level2
    ).level2.level3
    ).level3.level4= "Y", true, false )

    Visual aid:

    image.png

    Thoughts?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ericonline 

    That's a lot of levels!!

    You might want to consider putting some "AddColumns" to your Items in the Gallery that will contain the status value (and the nasty formula needed to get to it).  That way you'll have an easier view of it as your create other formulas.  If you make the Added Column a numeric condition (0 = "off", 1 = "on"), then perhaps you could use a formula on your Big Toggle like this:

       Sum(Gallery1.AllItems, myAddedColumn) = CountRows(Gallery1.AllItems)

    That way if all toggles are on in the gallery the sum will equal the count and thus your BIG toggle should be "On".

     

    Hope that helps some.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @RandyHayes , thanks for the insights. I'm trying to get this going, not used AddColumns before. 
    Here's where I'm at:

     

    AddColumns(colCustomConnectorResponse, "myNewColumn",
    If(
    First(
    First(
    First(
    colCustomConnectorResponse.level1
    ).level1.level2,
    ).level3.level4 = "Y",
    1,0
    )
    )

    The formula is not flagged by intellisense, appears to be "working", but I don't see "myNewColumn" in anywhere in the collection.

    Wonder if I need to add all those "First()'s" to the AddColumn(source, ?

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ericonline 

    AddColumns, RemoveColumns, and ShowColumns are all "chain" formulas.  In other words, they *return* the results of the actions that they take, they don't alter the paramters given.

    So, in this case, the AddColumns is working, but it is going nowhere.

    Typically I would user Add/Remove/Show at the point that I gather the information and assign it to a collection if needed, but in this case the only thing you're going to need is to put this result in a collection.

     

    So - wrap this formula you have with a ClearCollect(colCustomConectorResponse, AddColumns....<the rest of your formula>...)

    This will put the results of the AddColumns into the collection.

    Also, since you are actually doing this "Post Collection", you might want to designate another collection name as PowerApps might get a little freaky about the change of structure.

    Again, it is better if you can, to use the AddColumns at the point in which you initially create your colCustomConnectorResponse collection.

     

    Hope that makes sense.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hm. Interesting. 

    • AddColumns wrapped around the Gallery Items Property works well.
      • The new column is at the appropriate level of the response (level4)
    • AddColumns as part of the ClearCollect Function adds new column to the TOP LEVEL of the collection. 
      • I'm unable to get the AddColumns to work at this point. PowerApps is not "seeing" the collection name when I try to "embed" the AddColumns into further layers.

    More experimentation to come! 

    FUN!

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Just to share some of the insights I've had on this (again, thanks @RandyHayes😞

    The AddColumns() Function I was able to get working is as follows:

    • Instantiated: At the Gallery-Items-Property-level, not at ClearCollect
    AddColumns(
     First(
     First(
     colCustomConnectorResponse.level1
     ).level1.level2
     ).level2,
     "myNewColumn",
     If(
     level3.level4 = "Y", //<--This is a SUBSTANTIAL piece. Notice how the dot notation just picks up at .level3, where the above "digging" left off (at .level2)!!
     1,0
    ) )
    • Now, just like Randy said, I have something to pivot off of:
    • Sum(Gallery.AllItems, myNewColumn)

    So creative! Hope this helps others too!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard