I am currently working on an app, where on the fron screen you have a very simple gallery showing a certain set of items, and when you click on one line, it takes you to another gallery containing the list that is related to the Title of the first gallery.
Now, this second gallery's Item property is determined by a collection I made from an SQL view. On the front screen "OnVisible" I have simply set the ClearCollect('CollectionName, 'SQL VIEW NAME').... And it seems like it collects the data.
However, I have done some manual checks, and it looks like the data in the new collection I made does not match the data in the SQL View. One line on the front page might say "12 new events", while when I click on the item it takes me to a list with only 8 events (I can manually check in SQL that there are 12 events).
I have attempted to have the list run directly off the view instead of the collections, but that will make it waaay too slow, and unable to work with.
I hope someone can explain to me, while the collection collects an incomplete set of data!
Thanks in advance!
This sounds very unusual. To diagnose this, I'd suggest that you count the rows in the collection immediately after your ClearCollect statement by modifying your formula like so.
ClearCollect(CollectionName, 'SQL VIEW NAME'); Set(CollectionNameCount, CountRows(CollectionName))
After you run your screen, if you inspect the value of CollectionNameCount under File>Variables, can you confirm what the row count is? If it's 12, that suggests that the problem lies elsewhere in your app.
Thanks for your response.
I tried to set the variable to count the rows in my collection, and the amount of rows is correct. Which is weird.
So here is the deal. I did some more testing:
My view in SQL has 58 rows total, and this is dynamic, so everytime an "Event" is added or solved, this number will go up or down by a couple. But generally, this will never exceed 100-200 rows, meaning that delegation is not an issue.
The variable showed that there was 58 rows in the collection, but through testing, I noticed a few specific rows were missing and the remaining number of rows were populated by copies of others. In other words, the same row was there two times in some cases.
The only filter that my gallery is using is filtering on a column called [Group] that identifies which group the events belong to, and this should filter the list to all events connected to that group. However, sometimes it excludes certain rows and includes one row two times.
The SQL View has been formatted correctly, and the left joins are also correct, I have had it doublechecked by several SQL experts. So the issue must be somewhere in the Collection.
Does this make any sense? Or do you need more information to answer.
Hi again @timl
Just as an addition, I incorporated a Distinct function into my CountRows variable. So that it counts distinct IDs from my view. This returns only 43 rows, while the view has a total of 58. So there is definately something wrong here.
I just cannot figure out what and where.
Are you certain that the SQL view is not returning duplicate rows ? This would seem the mostly likely cause of your issue. You could add a DISTINCT clause in the view definition to ensure the view does not return duplicates
My SQL view contains an ID for each row. So in my view in SQL there are 58 distinct rows, but the collection in PowerApps seems to only collect 43 distinct IDs for some reason. And I cannot see the logic in those it decides to exclude, and those it decides to create duplicates of.
This sounds very unusual. This formula will store the result of 'SQL VIEW NAME' into CollectionName.
ClearCollect(CollectionName, 'SQL VIEW NAME')
There shouldn't be any deviation between what you see in CollectionName, compared to what you would see if you were to do execute this directly in SQL.
SELECT * FROM 'SQL VIEW NAME'
I imagine there must be some other formula, or something else that's causing this discrepency.
I use Views and Collections for all galleries. For example when I add a Contact I need to refresh the View and Collection. ContactVGA is a view for Gallery that contains a few fields from Contact and Client tables. I have not seen any issues.
Refresh('[dbo].[ContactVGA]'); ClearCollect( colContactVGA, '[dbo].[ContactVGA]' );
ALTER VIEW [dbo].[ContactVGA] AS SELECT c.ContactID, c.Client, c.FullName, cl.ClientName, c.Company FROM dbo.Contact AS c LEFT JOIN dbo.Client AS cl ON c.Client = cl.ClientID
The only troubleshooting option I would take next is to throw a Gallery on a screen and set the Items to that view directly. See exactly what you are getting with that.
Then use the collection again and set the items property of the Gallery to the collection and see if there is a difference.
In other words, the focus seems to be around the collection as the issue. See if the issue exists with a direct connection to the view.