web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Query on list with a o...
Power Apps
Unanswered

Query on list with a one to many structure

(0) ShareShare
ReportReport
Posted on by

Hello, i have a trivia app which makes questions based on certain topics. I made the following DB schema (i'm using sharepoint lists to store the data). Every topic can have several questions, one question instead is related only to one specific topic. Screenshot 2023-04-11 110329.png

 

once my user pick a topic, the id is stored in the variable ChosedTopicID... how can i have a collection which stores all the questions where their topicID is equal to ChosedTopicID. how can i do that? 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,119 Most Valuable Professional on at

    Hi @Antonioclk ,

    This should do it (but not Delegable)

    With(
     {
     wQList:
     Filter(
     TopicsHaveQuestions,
     topicID = YourChosenTopicID
     )
     },
     Filter(
     Questions,
     questionID in wQList.questionID
     )
    )

    however SharePoint is not a relational database and SQL-type "look-though" queries really should not be used. If you add the topicID as a field in the question list and you will have a Delegable simple query

    Filter(
     Questions,
     topicID = YourChosenTopicID
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

     

  • Antonioclk Profile Picture
    on at

    hi Warren, 

    i figured it was not the best approach to make a sql similar structure. how would it be the best way? (would it be good if using the dataverse?) 

     

    could you please explain me how to use your code? i have a button which sets the topicID, on that button i place the "with" code you wrote... but then if i add a table in the screen and link the question data source to it, it won't show the topic id...  

     

    i had tried to add a column with the topic id to the question table, but i can't understand how

     

  • Antonioclk Profile Picture
    on at

    I kinda found a solution...

    ClearCollect(
    ChosenTopicQuestions,
     Filter(
     AddColumns(
     Questions,
     "qTopicID",
     LookUp(
     TopicsHaveQuestions,
     questionID = Questions[@questionID]
     ).topicID
     ), 
     qTopicID=ChosenTopicID
     )
    )

     

    this actually works, it return a collection which stores all the Questions items, filtered by a newly added column qTopicID. the only issue is that all the fields name are messed up and gets called field1, field2 and so on... how can i fix this? and still, what would have been the correct data structure to use?

    Thanks

  • WarrenBelz Profile Picture
    156,119 Most Valuable Professional on at

    @Antonioclk ,

    Your last post is similar to my suggestion of putting the topicID in the Questions list, but you are doing it temporarily rather than permanently (which I always do as I practice "one degree of separation" between any two lists referring to the other. By the field names, I assume you created the list by importing from Excel (not a good idea).

    The code I posted can be used for a collection like this

    With(
     {
     wQList:
     Filter(
     TopicsHaveQuestions,
     topicID = YourChosenTopicID
     )
     },
     ClearCollect(
     ChosenTopicQuestions,
     Filter(
     Questions,
     questionID in wQList.questionID
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard