cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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
Helper V
Helper V

Re: Create a collection from 2 SQL tables

Are you tring to combine 2 collections to one?

Highlighted
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

Highlighted
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

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,752)