cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Runner55552
Post Partisan
Post Partisan

oData query to filter column by a list of values

I have an SQL table with a list of Project IDs (23-029, 22-019, etc.). Due to large volume, I want to only pull records where Project ID matches a smaller list of these projects. So there may be 100 projects in the database, resulting in 6,000 total records, but I only need 3 or 4 of those projects. I want to do this directly in the SQL Get Rows action to limit the time required to pull the data from SQL to Power Automate (and to PowerApps).

How would I approach this? For example, I only want to pull records that match this list of projects: 22-019, 23-045, 22-123, 24-225.

oData does not seem to have an 'in list' or 'in' function. 

This list is variable with each run, and will be passed in by pulling from another data table in real time, so it cannot be hard-coded in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
DJ_Jamba
Resident Rockstar
Resident Rockstar

Yes of course. 
Initialise an array and then append to it when you find a match...

View solution in original post

9 REPLIES 9
DJ_Jamba
Resident Rockstar
Resident Rockstar

Hi @Runner55552 

You can't pass an array to an oData filter query.
Instead, you create an array of projects, loop through that array and call the SQL Get Rows action passing a single project to filter on.

Option 2. (Limit is 5000). Get up to 5000 rows and then you can use the Filter query action to filter those records by whatever is in your array.

Option 3. Use the above technique but inside a Do Until loop where the Do Until will keep pulling batches of 5000 using the skip token oData.NextLink. When oData.NextLink is empty there's no more records to fetch. Then you can use the Filter query action to filter all of those records by whatever is in your projects array

Runner55552
Post Partisan
Post Partisan

Options 2 and 3 will not help me. The biggest time component/delay for PowerApps users is waiting 10 to 15 seconds for the full data set to be pulled in from an SQL database. So I need to do the filtering during the Get Rows action. If I used Option 1 to loop through the array one project at a time, would there be a way to keep appending the results so that I would have all the collected rows together? Maybe an array variable inside the loop that gets appended?

DJ_Jamba
Resident Rockstar
Resident Rockstar

Yes of course. 
Initialise an array and then append to it when you find a match...

DJ_Jamba
Resident Rockstar
Resident Rockstar

Glad it's sorted!

P.S. @Runner55552 
When you do get SQL results, you're going to use an Apply to each action to append the results to the array.
Make sure you click on the 3 dots of the Apply to each action, enable concurrency and push it right up to the max (50). Results will be added to the array really, really fast.

 

d(-_-)b   

Runner55552
Post Partisan
Post Partisan

One other thought. If I end up needing a loop to get rows for each individual project, I think that will make an API call to the SQL database with each loop. When I tracked this previously, each call to connect to the database took as much as a second or sometimes more. This could potentially end up taking the same amount of time as making a single call without the filtering. Of course, it is better to only get the data I need. I cannot think of any other method to do the query without looping and making a call to the database, though.

DJ_Jamba
Resident Rockstar
Resident Rockstar

Absolutely correct.

Sadly, I think this is by design. It's a subscription service after all...

I can get 999 rows in one call using _api/$batch but I've only done it on a SP list and I think it's way overkill for what you're looking for

Runner55552
Post Partisan
Post Partisan

However, since you suggested the concurrency idea for the loops, if the concurrency is set to 50, and I only have 10 or 20 different projects to loop through, even if each loop makes an API call, the elapsed time should still be equivalent to a single call. I hope to test this today.

Runner55552
Post Partisan
Post Partisan

I have the loop set up that loops through the list of projects (only four right now, so loop repeats 4 times).  This all works well and the total time is only 2 seconds (longest of the 4 loops, larger amount of data). 

Do you have an example flow where you loop through data like this and append to an array (or string variable)? Append to array caused an error, so I am using a string variable and appending the output of each GetRows action to that string variable. This gets all the data, but there are extra square brackets ([]) around each set of data. I just want a single combined array as output. I can probably do this with a couple of replace statements to get rid of the internal extra square brackets, but perhaps there is a simpler solution.

Active Projects below contains the array of projects: ['Project1', 'Project2', etc.] and the variable is a string variable.

Thanks!

Runner55552_0-1713382987159.png

 

Although I agree with your solution, I ended up taking a different approach. I had trouble with the looping, due to my specific requirements to get a combined array of objects as the output from the SQL database. It was taking too many replace statements to insert/delete brackets, etc.

I ended up totally bypassing the loop idea, and creating a concatenated oData query consisting of Project eq 'Project1' or Project eq 'Project2' or Project eq 'Project 3', etc.  I just looped through my input array which comes from PowerApps in the format of ["Project1", "Project2", etc.], and inserted "Project eq' and ' or ' as part of the concat statement. Then the combined statement goes in a Compose statement, and I just referenced that compose statement in the oData query in the Get Rows action. Tests have worked, but will do a full test from PowerApps soon. PowerApps calls the flow, then returns the results of the GetRows back to PowerApps with a Response action.

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,038)