cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Scott_P Advocate II
Advocate II

Create a collection from 2 SQL tables

I am having an issue with this syntax:

 

ForAll(Filter('[dbo].[FormCQ_Answers]', FormID = Gallery1.Selected.FormID),Collect(FilteredAnswers4,{id:id,FormID:FormID,Question:Question,Answer:Answer,Evidence:Evidence,MarksAvailable:LookUp(FilteredQuestions, Question = LookUp('[dbo].[FormCQ_Answers]',id=id,Question),MarksAvailable)}))

 

 

Everything else in the table is fine with the exception of MarksAvailable, where it is returning only the first row which is 1 and then duplicating this across the rest of the rows.

Example.jpg

It should be a fairly simple lookup, but it just returns the first row of the table rather than it matching the id that we have matched the row to…

 

The strange thing is that it will pull through the correct records for other fields just not this one and we’ve tried various different ways to see if we can fix the issue to no avail.

 

 

What I have found is that this sort of works, but the issue I have with it is that we're storing multiple collections, which is inefficient and doesn't work in its enirity:

Concurrent(ClearCollect(Test, Filter('[dbo].[FormCQ_Sections]', FormType = Gallery1.Selected.FormType)), 

ClearCollect(Test2, Filter('[dbo].[FormCQ_Questions]', FormType = Gallery1.Selected.FormType)));

ClearCollect(FilteredAnswers, Filter('[dbo].[FormCQ_Answers]', FormID = Gallery1.Selected.FormID), AddColumns('[dbo].[FormCQ_Answers]', "MarksAvailable", LookUp(QuestionScores, id = '[dbo].[FormCQ_Answers]'[@Question], MarksAvailable),"Section", LookUp(QuestionScores, id = '[dbo].[FormCQ_Answers]'[@Question], Section), "SectionName", LookUp(Test, id = LookUp(QuestionScores, id = '[dbo].[FormCQ_Answers]'[@Question], Section), name), "QuestionText", LookUp(QuestionScores, id = '[dbo].[FormCQ_Answers]'[@Question], QuestionText)));


Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_P Advocate II
Advocate II

Re: Create a collection from 2 SQL tables

This is how I resolved the issue:

Concurrent(ClearCollect(Test, Filter('[dbo].[FormCQ_Sections]', FormType = Gallery1.Selected.FormType)),

ClearCollect(FilteredQuestions, Filter('[dbo].[FormCQ_Questions]', FormType = Gallery1.Selected.FormType)));

ClearCollect(FiltAnsw,Filter('[dbo].[FormCQ_Answers]', FormID = Gallery1.Selected.FormID));

ClearCollect(FilteredAnswers, AddColumns(FiltAnsw, "MarksAvailable", LookUp(QuestionScores, id = FiltAnsw[@Question], MarksAvailable),
"Section",LookUp(FilteredQuestions, id = FiltAnsw[@Question], Section),
"SectionName", LookUp(Test, id = LookUp(QuestionScores, id = FiltAnsw[@Question], Section), name),
"QuestionText", LookUp(QuestionScores, id = FiltAnsw[@Question], QuestionText)));

Created a seperate collection called FiltAnsw then called from there for the LookUp.

 

View solution in original post

3 REPLIES 3
Highlighted
Lisabel0 Helper V
Helper V

Re: Create a collection from 2 SQL tables

Are you tring to combine 2 collections to one?

Scott_P Advocate II
Advocate II

Re: Create a collection from 2 SQL tables

ideally, I may have found a  solution, but it's not quite working as it should be. The data structure was also incorrect on the SQL table so it may be a combination of different issues that is preventing the 2 collections matching up correctly

Scott_P Advocate II
Advocate II

Re: Create a collection from 2 SQL tables

This is how I resolved the issue:

Concurrent(ClearCollect(Test, Filter('[dbo].[FormCQ_Sections]', FormType = Gallery1.Selected.FormType)),

ClearCollect(FilteredQuestions, Filter('[dbo].[FormCQ_Questions]', FormType = Gallery1.Selected.FormType)));

ClearCollect(FiltAnsw,Filter('[dbo].[FormCQ_Answers]', FormID = Gallery1.Selected.FormID));

ClearCollect(FilteredAnswers, AddColumns(FiltAnsw, "MarksAvailable", LookUp(QuestionScores, id = FiltAnsw[@Question], MarksAvailable),
"Section",LookUp(FilteredQuestions, id = FiltAnsw[@Question], Section),
"SectionName", LookUp(Test, id = LookUp(QuestionScores, id = FiltAnsw[@Question], Section), name),
"QuestionText", LookUp(QuestionScores, id = FiltAnsw[@Question], QuestionText)));

Created a seperate collection called FiltAnsw then called from there for the LookUp.

 

View solution in original post

Helpful resources

Announcements
secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (8,454)