cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Return data within PowerApps while using Collection, ForAll and IF condition.

Hi all, 

 

I'm having troubling with returning data from my collection. I'm not sure why I can't figure it out, but its pretty straight forward. 

 

I have two Collection named as Collection1 and Collection2.

 

Where My Collection1 stores Date values in Date1 column. for eg:

Date1

10/09/2020

11/09/2020

12/09/2020

13/09/2020

 

and My Collection2 stores multiple dates columns. for eg:

Date1                       Date2 

10/09/2020        11/09/2020

11/09/2020        12/09/2020

12/09/2020        13/09/2020

14/09/2020        15/09/2020

 

My Date1 and Date2 of Collection2 is related via row by row.

 

Where my ForAll and If condition returns true and false value for if my Collection1.Date1 values exists in any of the Collection2. Date1 or Collection2.Date2. 

 

So I got result such as :

true

true

true

False

 

And this result is correct. 

 

Now my only problem is to get the either true or false value collected into a New_Collection or Set to any variable. I don't want to use Instant flow for this, are there any possibility to get this within PowerApps ?

 

Expected result is either:

Date1

10/09/2020

11/09/2020

12/09/2020

 

OR

 

Date1

13/09/2020

 

 

Do let me know if there is any issues with understanding the problem. 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

I think I didn't understand what you mean before.My previous plan was to compare row by row, for example: the first record of count1 corresponds to the first record of count2.

Looking at it now, it seems that you only need to find out the date that exists in count2 in count1.

If so,please try:

UpdateContext({Blocked:true});
If(
    true in ForAll(
        active_booking_dates,
        If(
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 1',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 2',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 3',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 4 ',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 5',
            true,
            false
        )
    ),
    UpdateContext({seat_booked: true});
    ClearCollect(
        available_dates,
        ForAll(
            active_booking_dates,
            If(
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 1' || 
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 2' ||
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 3' || 
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 4' ||
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 5',
                {Date: _Date}
            )
        )
    );
    UpdateContext({booking_confirm: false}),
    UpdateContext({seat_booked: false});
    UpdateContext({booking_confirm: true}) 
)

Best Regards,

Bof

View solution in original post

10 REPLIES 10
Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

The point is using FirstN() function.I'v made a test for your reference:

1\Add a timer control:

Duration

100 /*loop in 0.1s*/

OnSelect

Clear(TheResult); /*TheResult is a custom collection that I use to store results*/
Set(var,1) /*var is a custom variable*/

OnTimerEnd

If(
  Last(FirstN(Collection1,var)).Date1=Last(FirstN(Collection2,var)).Date1||Last(FirstN(Collection1,var)).Date1=Last(FirstN(Collection2,var)).Date2,
  Collect(TheResult,{Date:Last(FirstN(Collection1,var)).Date1}));
Set(var,var+1)

Repeat

var<CountRows(Collection1) /*End the loop after traversing Collection1*/

16.gif

 Best Regards,

 Bof

Highlighted
Helper II
Helper II

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @v-bofeng-msft ,

 

Apologies it took a while to get it tested in actual system. To seems the logic seems good. Here are two Issues that I came across while testing. 

 

1. I need to put the logic on the check boxes that I have , so I won't be accessing the features of Timer Control. 

I need to put the logic on Check properties on check box, as this needs to perform when checkbox is clicked.

 

2.  I don't know why but I'm getting only Last Value of Collection called TheResult. For your shared case it would be only September 12, 2020 that I'm getting. I did putted all the logics in correct place and even my timer is running correctly for the var loop (number of times)

 

ashwnaidv100_0-1600696552387.png

 

The above result is from one of my test case, where condition was true for 

9/19/2020

 

and false for 

 

9/20/2020

9/21/2020

9/22/2020

9/23/2020

 

I think it could possibly work if loop traverse correctly in some way. And to use this formula within Checkbox and try to ignore the Timer control. 

Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

There is also a way without using timer control.I'v made a test for your reference:

1\Add a check box and set it's OnCheck Property to:

Clear(Var1); 
Clear(Var2);/*Var1/Var2 are my custom collections*/
ForAll(
    Collection1,
    Collect(
        Var1,
        {
            TheID: CountRows(Var1) + 1,
            Date1: Date1
        }
    )
);
ForAll(
    Collection2,
    Collect(
        Var2,
        {
            ID: CountRows(Var2) + 1,
            Date1: Date1,
            Date2: Date2
        }
    )
);
ClearCollect(
    TheResult,
    ForAll(
        Var1,
        If(
            Date1 = LookUp(
                Var2,
                ID = TheID
            ).Date1 || Date1 = LookUp(
                Var2,
                ID = TheID
            ).Date2,
            {Date: Date1}
        )
    )
)

24.gif

Best Regards,

Bof

Highlighted
Helper II
Helper II

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @v-bofeng-msft 
Still facing the same issues as above as its not working. I'm using your shared logic in true part of my if condition. I tried to incorporate with changing the names. so for Var1 and Var2 you will find counting1 and counting2 respectively in my shared code. 

 

This is my actual code on OnCheck property of my checkbox named as Checkbox3_16.  I wanted the action to be performed once my main logic is true. And its very close to get the result as, I'm getting the same result as my previous post shows. Which is only the last value. 

 

I thought just to share the code here, would give a quick understanding what and where I'm trying to implement this logic. 

All code is working perfectly, But only the last part is not working , which is TheResult collection. 

 

 

 

UpdateContext({Blocked:true});
If(
    true in ForAll(
        active_booking_dates,
        If(
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 1',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 2',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 3',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 4 ',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 5',
            true,
            false
        )
    ),
    UpdateContext({seat_booked: true});
    Clear(counting1); 
    Clear(counting2);
    ForAll(
        active_booking_dates,
        Collect(
            counting1,
            {
                TheID: CountRows(counting1) + 1,
                Dates: _Date
            }
        )
    );
    ForAll(
        Filter(
                    abu_dhabi_7,
                    Checkbox3_16.Text = 'Chosen Seat'
                ),
        Collect(
            counting2,
            {
                ID: CountRows(counting2) + 1,
                Date1: 'Date 1',
                Date2: 'Date 2',
                Date3: 'Date 3',
                Date4: 'Date 4 ',
                Date5: 'Date 5'
            }
        )
    );
    ClearCollect(
        available_dates,
        ForAll(
            counting1,
            If(
                Dates = LookUp(
                    counting2,
                    ID = TheID
                ).Date1 || Dates = LookUp(
                    counting2,
                    ID = TheID 
                ).Date2 || Dates = LookUp(
                    counting2,
                    ID = TheID
                ).Date3 || Dates = LookUp(
                    counting2,
                    ID = TheID
                ).Date4 || Dates = LookUp(
                    counting2,
                    ID = TheID
                ).Date5,
                {Date: Dates}
            )
        )
    );
    UpdateContext({booking_confirm: false}),
    UpdateContext({seat_booked: false});
    UpdateContext({booking_confirm: true}) 
)

 

 

 

 

Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

I think there should be no problem with the logic of the formula, and it worked very well in my tests.
Please check the 'count1' and 'count2'.

Best Regards,

Bof

Highlighted
Helper II
Helper II

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @v-bofeng-msft , 

 

My Counting1 and Counting2 are working as intended and getting the right result. 

 

But I'm not getting any output in the TheResult collection from your code. Even logic seems to be right to me and it suppose to give me the result . but no luck. 

 

 

Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

Could you show me some screenshots?

By the way,In the code you provided, the collection you are using seems to be "available_dates" instead of "TheResult".

Best Regards,

Bof

Highlighted
Helper II
Helper II

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @v-bofeng-msft ,

Yeah i was referring that for your code.

 

Here my checkbox looks like with my date control, which creates the collection1. Red tick marked is my checkbox.

 

ashwnaidv100_0-1600854616457.png

 

 

Collection1

 

ashwnaidv100_2-1600856283501.png

 

 

Here's the collection2 

 

ashwnaidv100_3-1600856321026.png

 

So if see closely to my Collection2.Date1 , I have a date 9/20/2020. Which does exist in my collection1.Dates, So its does not return the date and same goes for all the columns for collection2. So I should have only 09/19/2020 in return in this case.

 

But it just don't return the result.

 

Highlighted
Community Support
Community Support

Re: Return data within PowerApps while using Collection, ForAll and IF condition.

Hi @ashwnaidv100 :

I think I didn't understand what you mean before.My previous plan was to compare row by row, for example: the first record of count1 corresponds to the first record of count2.

Looking at it now, it seems that you only need to find out the date that exists in count2 in count1.

If so,please try:

UpdateContext({Blocked:true});
If(
    true in ForAll(
        active_booking_dates,
        If(
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 1',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 2',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 3',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 4 ',
            true,
            Dates in Filter(
                abu_dhabi_7,
                Checkbox3_16.Text = 'Chosen Seat'
            ).'Date 5',
            true,
            false
        )
    ),
    UpdateContext({seat_booked: true});
    ClearCollect(
        available_dates,
        ForAll(
            active_booking_dates,
            If(
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 1' || 
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 2' ||
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 3' || 
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 4' ||
                _Date in Filter(abu_dhabi_7,Checkbox3_16.Text = 'Chosen Seat').'Date 5',
                {Date: _Date}
            )
        )
    );
    UpdateContext({booking_confirm: false}),
    UpdateContext({seat_booked: false});
    UpdateContext({booking_confirm: true}) 
)

Best Regards,

Bof

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,040)