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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ClearCollect to pull d...
Power Apps
Unanswered

ClearCollect to pull data from sql filtered from a collection

(0) ShareShare
ReportReport
Posted on by 16

I hope you can help as I am stuck. I have an SQL database that I want to search and return rows, based on the selection of a separate collection. The difficulty I cannot figure out is that the collection has two columns, one of which shows the column in the sql database and the second is the unique number in that column that can pull the specific rows.

 

SelectedTrackingCodes (The collection)

TrackingCodeTypeTrackingCodeNb
GP123456
CDT654321
IT123789

 

AllData (On Prem SQL)

GpCdtIt 
123456   
 654321  
  123789 

 

I have tried this 

ClearCollect(SelectedData,LookUp(SelectedTrackingCodes, TrackingCodeType = "GP", Filter(AllData,Gp=TrackingCodeNb))); and multiple other versions with filter, but cannot figure out how to pull the row or rows for Gp 123456 using the collection as a reference for both the column lookup. Then it should pull Cdt 654321 and its row or rows of data, and so on until all the items in the collection have been pulled into the new collection.

 

I have tried to look for the answer myself through the community, but nothing seems to fit the requirement I have to select the column first.

 

Any help would be greatly appreciated. 

Categories:
I have the same question (0)
  • Verified answer
    SpongYe Profile Picture
    5,603 Super User 2025 Season 2 on at

    Hi @MattSmall 

     

    You can try: 

    Clear(SelectedData); // Clear the SelectedData collection before populating it
    ForAll(
     SelectedTrackingCodes,
     If(
     TrackingCodeType = "GP", Collect(SelectedData, Filter(AllData, Gp = TrackingCodeNb)),
     TrackingCodeType = "CDT", Collect(SelectedData, Filter(AllData, CDT = TrackingCodeNb)),
     TrackingCodeType = "IT", Collect(SelectedData, Filter(AllData, IT = TrackingCodeNb))
     )
    );

    If you have any questions or feedback, please let me know. Have a great day! 😊

    -----------------------
    PowerYsa Power Platform Enthusiast [LinkedIn] | [Youtube]

    I love to share my knowledge and learn from others. If you find my posts helpful, please give them a thumbs up 👍 or mark them as a solution ✔️. You can also check out my [@PowerYSA] for some cool solutions and insights. Feel free to connect with me on any of the platforms above. Cheers! 🍻

  • MattSmall Profile Picture
    16 on at

    Thanks @SpongYe for responding so promptly.

    Your code threw up some errors, but has giving me options which I am exploring. Will let you know if I am successful. 

  • MattSmall Profile Picture
    16 on at

    @SpongYe thanks this worked perfectly you are a star.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard