'Weird Bug / Mistake ? on a powerapps gallery

I'm trying to build a tool to filter data from a sharepoint list. But the thing is that, I'm using a collection to store data for my filters, like is the filter toggled etc...

Then I'm using a gallery of buttons to interact with it, I'm doing an if comparison, and it's works on the first one, but not on any other ones, it's like they are reversed.

Here on the onVisible Property of my page, I init my collection like this :

ClearCollect(Liste_Directions;
{Name: "DAF"; Toggled: false; DirectionID: 5; R: 255; G: 0; B: 0; A: 0,83};
{Name: "DCM"; Toggled: false; DirectionID: 23; R: 0; G: 121; B: 187; A: 1};
{Name: "DRCI"; Toggled: false; DirectionID: 12; R: 221; G: 79; B: 14; A: 1};
{Name: "DRE"; Toggled: false; DirectionID: 31; R: 127; G: 178; B: 57; A: 1};
{Name: "DST"; Toggled: false; DirectionID: 16; R: 0; G: 0; B: 0; A: 1};
{Name: "DG"; Toggled: false; DirectionID: 1; R: 255; G: 191; B: 0; A: 1}

Then to change the toggle state I do this :

Patch(Liste_Directions; LookUp(Liste_Directions; DirectionID = ThisItem.DirectionID);
    {Toggled: !ThisItem.Toggled}
);;
If(!ThisItem.Toggled;               
    Set(Action; "remove");;
    Set(Total; Total - CountIf(Collaborateurs; DirectionID = ThisItem.DirectionID));;
    Remove(Liste_Collaborateurs; Filter(Liste_Collaborateurs; DirectionID = ThisItem.DirectionID))
    ;
    Set(Action; "add");;
    Set(Total; Total + CountIf(Collaborateurs; DirectionID = ThisItem.DirectionID));;
    Collect(Liste_Collaborateurs; Filter(Collaborateurs; DirectionID = ThisItem.DirectionID))
);;

I'm printing the value of toggle for the button, then the last action that was made.

Here is what happens whenever I click any button but the first one :

enter image description here

It made the action remove when it's supposed to do add since toggled is true

Here is the result with the first one for comparison:

enter image description here

The value of toggled is true, so it will do the action add and actually show data

action is a global variable so it will show the same action for every component of the gallery.

Do you guys have any idea on What's wrong or what can I do ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source