cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
mikiepat
Level: Powered On

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

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

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.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
13 REPLIES 13
Super User
Super User

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

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".

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
mikiepat
Level: Powered On

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

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

Super User
Super User

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

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.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
mikiepat
Level: Powered On

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

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

Super User
Super User

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

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?

Super User
Super User

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

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Super User
Super User

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

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, ?

 

Super User
Super User

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

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Super User
Super User

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

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!

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 46 members 4,666 guests
Please welcome our newest community members: