cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MichaGue
Resolver I
Resolver I

If statement within collection

Hello,

I have the following problem. In a gallery "gal_Datapoints" I have a list of pairs of values (voltage, current).

 

Example (voltage, current):

0, 1

2, 3

4, 5

6, 7

 

Based on the gallery I want to create a collection. I use the onselect of a button for this. All values of the collection are to be run through.

If the value of the voltage = 0, then A is to be written to the collection, otherwise B.

 

Clear(col_Datapoints);
ForAll(
    gal_Collection.AllItems,
    Collect(
        col_Datapoints,
        If(
            Voltage = 0,
            "A",
            "B"
        )
    )
);

 

The formula shown for this is not correct.

How do you implement something appropriate in Power Apps?

 

Many thanks for your tips,

Greetings Michael

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@MichaGue 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

Your formula should be the following:

ClearCollect(col_Datapoints,
    ForAll(gal_Collection.AllItems,
        {Value: If(Voltage = 0, "A", "B")}
    )
)

 

Not entirely sure of your purpose for the collection (as your Gallery already contains the data - a collection would be duplicating), and not entirely sure what you wanted in the collection, other than a value of A or B.  And finally, not entirely sure what Voltage is in your gallery context...is that a column value or a control?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

1 REPLY 1
RandyHayes
Super User
Super User

@MichaGue 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

Your formula should be the following:

ClearCollect(col_Datapoints,
    ForAll(gal_Collection.AllItems,
        {Value: If(Voltage = 0, "A", "B")}
    )
)

 

Not entirely sure of your purpose for the collection (as your Gallery already contains the data - a collection would be duplicating), and not entirely sure what you wanted in the collection, other than a value of A or B.  And finally, not entirely sure what Voltage is in your gallery context...is that a column value or a control?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,341)