I have encountered several occasions inside a PowerApp where Lookup (even First(Filter())) does not work as intended.
So I created a very simple App to demonstrate.
3 Collections are created, and displayed via Gallery. The original App is way more complex, but this explains the basic issue.
The First Collection is the Index Collection, that consist of a Field used as ID for Lookup and an Index field.
ClearCollect(
IndexCollection,
{
Title: "Title1",
Index: "1"
},
{
Title: "Title2",
Index: "2"
},
{
Title: "Title3",
Index: "3"
}
)
The second Collection represents the Data that needs the Index reference:
ClearCollect(
MyData,
{
Title: "Title1",
Text: "Additional Column"
},
{
Title: "Title2",
Text: "Additional Column2"
},
{
Title: "Title3",
Text: "Additional Column3"
}
)
The Idea now is to do a ForAll on the Gallery, displaying the MyData (again, the real life scenario is a bit more complex) and creating a new Collection with Lookup information from the the Index Collection
ForAll(
Gallery2.AllItems,
Collect(
myResults,
{
Title: ThisRecord.Title,
Index: LookUp(
IndexCollection,
Title = ThisRecord.Title
).Index
}
);
);
This now creates a new Collection "myResults", but it has the Value "1" for every single Index.

If instead of doing it inside of the ForAll, I use the same Code (without the This.Record Part), it works as intended.
LookUp(
IndexCollection,
Title = "Title1"
).Index
And just out of curiosity I added another Collection inside the ForAll, to Capture Each Value
Collect(
StatusMessage,
"Title: "& ThisRecord.Title & " Value for Lookup: " & LookUp(
IndexCollection,
Title = ThisRecord.Title
).Index
);
The Result is the same:
