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 / Creating a Collection ...
Power Apps
Answered

Creating a Collection with If statement

(0) ShareShare
ReportReport
Posted on by 14

I'm trying to create a collection based on user input. The user input string is manipulated and stored inside the SearchText variable.

Currently, I've set two different conditions in the OnChange event of the input text box:

  1. if the user types "," the string is split in n+1 strings, where n is equal to the number of occurrences of the "," character.
  2. if the user types ".." the collections stores a range of numbers with a certain criteria (keep in mind that in this case the input will always be in the form of a 7-digit number, with the last digit being 0).

These are the two blocks of codes that are working flawlessly:

If(Find(",",SearchText)>0,
 ClearCollect(
 FilterRange,
 ForAll(
 Split(SearchText, ","),
 { Value: Value(ThisRecord.Value) }
 ) 
 )
),

 and

If(Find("..",SearchText)>0,
 ClearCollect(
 FilterRange,
 Sequence(
 (Value(Last(Split(SearchText,"..")).Value)-Value(First(Split(SearchText,"..")).Value))/10 + 1,
 Value(First(Split(SearchText,"..")).Value),
 10
 )
 )
);

When I check in the variables panel, the FilterRange collection is storing correctly the input values, as shown in the following screenshots:

 

  • Input: 8310040..8310080

2024-01-05 17_11_30-Window.png

  • Input: 8310040,8310080

2024-01-05 17_11_44-Window.png

Now, I'm trying to implement the possibility to use both "," and ".." at the same time in a single user input. To do this, I've merged the two chunk of codes in the following one:

If(Find(",",SearchText)>0,
 ClearCollect(
 FilterRange,
 ForAll(
 Split(SearchText, ","),
 If(Find("..",ThisRecord.Value)>0,			
 Sequence(
 (Value(Last(Split(ThisRecord.Value,"..")).Value)-Value(First(Split(ThisRecord.Value,"..")).Value))/10 + 1,
 Value(First(Split(ThisRecord.Value,"..")).Value),
 10
 ),
 	 { Value: Value(ThisRecord.Value) }
 )
 )
 )
),

However, with this code I'm facing a big issue: the FilterRange collection is not being created correctly: if I check it in the variables tab, I can see that it is storing n+1 tables, where n is equal to the number of occurrences of the "," typed in by the user (see image below). Each of these tables contain the input values (or the range of input values if ".." is found at each occurrence).

2024-01-05 17_21_47-Window.png

How can I manage to store correctly only the string values inside the collection? Probably what is causing the issue is the If statement inside the ForAll() function.


Thank you in advance.

Categories:
  • Verified answer
    QuentinDURIEZ Profile Picture
    577 Moderator on at

    Hi,

    I achieve this with this formula

     

     

    ClearCollect(FilterRange , ForAll(Split( txt_input_test.Value, ",") As comma,
     
     If(
     !(".." in comma.Value), 
     comma.Value 
     )
    )
    )
    ;
    ForAll(
     Filter(Split( txt_input_test.Value, ","), ".." in Value) As point,
     ForAll( 
     Sequence(
     (Value(Last(Split(point.Value,"..")).Value)-Value(First(Split(point.Value,"..")).Value))/10 + 1,
     Value(First(Split(point.Value,"..")).Value),
     10
     ) As seq, Collect(FilterRange , Text(seq.Value) )
     )
     )
     ,,
    RemoveIf(FilterRange , IsBlank(Value) )

     

     

    This idea is to manager "," splitted values and ".." splitted values seperately

    Regards,

  • DavideMitidieri Profile Picture
    14 on at

    That made the trick! Many thanks for the help!

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 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard