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 / Collection with condition
Power Apps
Unanswered

Collection with condition

(0) ShareShare
ReportReport
Posted on by 93

Hi,

 

I hope someone can push me in the right direction for this solution.

 

I want to do the following:

 

Create a collection of "Serial Numbers" (generated already created in a SQL table), based on a number that is inputted manually.

So for example, an input box of a quantity of '5', will collect 5 rows from a SQL table where the column "Used" = 'N'. 

Or another example:  an input box of a quantity of '10' will collect 10 rows from a SQL table where the column "Used" ='N'.

 

It's basically pulling a list of serial numbers that hasn't been used (based on the amount needed in the input box).

 

Thanks

 

Categories:
  • originalltd Profile Picture
    93 on at

    Never-mind, found the variable I was looking for!

    "FirstN" allowed me to pull the number of records from the table, along with a filter for it's condition.

  • AnneZC Profile Picture
    65 on at

    Hi @originalltd 

    You'll need something along these lines:

    Create a collection of the first x many (from input textbox) items from your data source that have "Used" = "N":

    ClearCollect(NextSerialNumbersColl,FirstN(Filter(SerialNumbersTable,Used="N"),Value(NoOfSerialNumbers_Input1.Text)))

     You might like to add a SortByColumns function in as well if there is a column that you want to order the Serial Numbers you are getting by. 

  • originalltd Profile Picture
    93 on at

    @AnneZC  Thanks for that, my condition looked very similar :).

     

    The next issue I have, is that it's filtering wrong. For example, "FirstN" is collecting 4 lines - but two of those have "Used" = 'Y', and therefore it only outputs 2 lines (Where "Used" ='N').

     

    I'm thinking the best way around that is a SQL view that is designed to show "Used" = 'N', unless there is an alternative condition I can use in PowerApps - but I can't think of anything on this Monday morning!!!

     

    Thanks!

     

     

  • AnneZC Profile Picture
    65 on at

    Hi @originalltd 

    What data type is your "Used" column? Is it Text or a Boolean type field?

     

    And do you have the Filter function inside the FirstN function?  It sounds like you could be doing the FirstN and then Filtering on that and you need to Filter first i.e. Filter is inside the FirstN function.

  • originalltd Profile Picture
    93 on at

    It is nvarchar(1), text. I've created a SQL view with the condition and it's collecting the correct amount now.

    But I am interested in your solution if PowerApps allows it.


    Thanks

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 360 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 325

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard