cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Scott_P
Level 8

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
Level 8

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
Lisabel0
Level 8

Re: Create a collection from 2 SQL tables

Are you tring to combine 2 collections to one?

Scott_P
Level 8

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
Level 8

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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

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