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

Load sreen finishes before the collection is finished loading

Hello everyone, 

 

Can someone share why my loading screen may be finishing before the data is finished being collected? This is my functions

 

Set(
    WBLoading,
    true
);
Set(
    VarSelecteduser,
    Office365Users.MyProfileV2().userPrincipalName
);
Concurrent(
    Set(
        VarSelecteduserphoto,
        Office365Users.UserPhoto(VarSelecteduser)
    ),
    Set(
        VarSelecteduserName,
        Office365Users.MyProfileV2().displayName
    ),
    Set(
        VarSelecteduserDeparment,
        Office365Users.MyProfileV2().department
    ),
    Set(
        VarSelecteduserLocation,
        Office365Users.MyProfileV2().city
    ),
    Set(
        VarSelecteduserEmail,
        Office365Users.MyProfileV2().mail
    );
    Concurrent(
        If(
            VarProfile.Access_Level.Value = "TM",
            ClearCollect(
                WelcomeBackData,
                Filter(
                    AbsenceData,
                    StartsWith(
                        MonthShort,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = ManagerEmail
                )
            ),
            ClearCollect(
                WelcomeBackData,
                Filter(
                    AbsenceData,
                    StartsWith(
                        MonthShort,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = SenoirManagerEmail
                )
            )
        ),
        If(
            VarProfile.Access_Level.Value = "TM",
            ClearCollect(
                CheckInData,
                Filter(
                    Check_in_Data,
                    StartsWith(
                        Short_Month,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = TM_Email
                )
            ),
            ClearCollect(
                CheckInData,
                Filter(
                    Check_in_Data,
                    StartsWith(
                        Short_Month,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = SM_Email
                )
            )
        ),
        If(
            VarProfile.Access_Level.Value = "TM",
            ClearCollect(
                Top_10_Data,
                Filter(
                    Top10Data,
                    StartsWith(
                        Short_Month,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = TM_Email
                )
            ),
            ClearCollect(
                Top_10_Data,
                Filter(
                    Top10Data,
                    StartsWith(
                        Short_Month,
                        REFVariShortMonth.Text
                    ),
                    Year = REFVariYear.Text,
                    VarSelecteduserEmail = SM_Email
                )
            )
        );
        Set(
            WBLoading,
            false
        )
    )
)

 

@smartin 

2 REPLIES 2
RandyHayes
Super User
Super User

@Willo 

So first, where is this formula?  Why so many variables?

You might consider simplifying your formula to the following:

Set(WBLoading, true);

Set(VarSelecteduser,
    With({lclUsr: Office365Users.MyProfileV2()},
        {PrincipalName: lclUsr.userPrincipalName,
         Photo: Office365Users.UserPhoto(User().Email),
         Name: lclUsr.displayName,
         Department: lclUser.department,
         City: lclUsr.city,
         Mail: lclUsr.mail
        }
    )
);

ClearCollect(
    WelcomeBackData,
    Filter(AbsenceData,
        StartsWith(MonthShort, REFVariShortMonth.Text),
        Year = REFVariYear.Text,
        VarSelecteduserEmail = If(VarProfile.Access_Level.Value = "TM", ManagerEmail, SenoirManagerEmail)
    )
);
           
ClearCollect(CheckInData,
    Filter(Check_in_Data,
        StartsWith(Short_Month, REFVariShortMonth.Text),
        Year = REFVariYear.Text,
        VarSelecteduserEmail = If(VarProfile.Access_Level.Value = "TM", TM_Email, SM_Email)
    )
);

ClearCollect(Top_10_Data,
    Filter(Top10Data,
        StartsWith(Short_Month, REFVariShortMonth.Text),
        Year = REFVariYear.Text,
        VarSelecteduserEmail = If(VarProfile.Access_Level.Value = "TM", TM_Email, SM_Email)
    )
);

Set(WBLoading, false)

 

What do some of these items refer to?  And actually this is more a question in context with the "Where is this" question.  If you are trying to do this in an OnStart or OnVisible, you might not have actual values in some of the things you are referencing. 

 

And finally in reference to the loading of data.  Check your advanced settings and see if you have Delayed Load on.  If so, you might want to consider turning that off.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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!
CarlosFigueira
Power Apps
Power Apps

This expression is setting the 'WBLoading' variable to false concurrently with the expressions that fetch data into the collection. Setting a variable is a very quick operation, so it will certainly complete before a network call is made. If you move the 'Set(WBLoading, false)' to outside the Concurrent call, it should wait until the collections are finished loading.

Another issue in this expression is that it is setting the 'VarSelecteduserEmail' variable concurrently with trying to use it, so it's possible that it will not be properly fetched before it is used. And yet another performance improvement that can be made is to call the 'Office365Users.MyProfileV2()' function only once. Take a look at the expression below with the suggested changes:

Set(WBLoading, true);
Set(VarSelecteduserProfile, Office365Users.MyProfileV2());
Set(VarSelecteduser, VarSelecteduserProfile.userPrincipalName);
Set(VarSelecteduserName, VarSelecteduserProfile.displayName);
Set(VarSelecteduserDeparment, VarSelecteduserProfile.department);
Set(VarSelecteduserLocation, VarSelecteduserProfile.city);
Set(VarSelecteduserEmail, VarSelecteduserProfile.mail);
Concurrent(
    Set(VarSelecteduserphoto, Office365Users.UserPhoto(VarSelecteduser)),
    If(
        VarProfile.Access_Level.Value = "TM",
        ClearCollect(
            WelcomeBackData,
            Filter(
                AbsenceData,
                StartsWith(MonthShort, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = ManagerEmail
            )
        ),
        ClearCollect(
            WelcomeBackData,
            Filter(
                AbsenceData,
                StartsWith(MonthShort, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = SenoirManagerEmail
            )
        )
    ),
    If(
        VarProfile.Access_Level.Value = "TM",
        ClearCollect(
            CheckInData,
            Filter(
                Check_in_Data,
                StartsWith(Short_Month, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = TM_Email
            )
        ),
        ClearCollect(
            CheckInData,
            Filter(
                Check_in_Data,
                StartsWith(Short_Month, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = SM_Email
            )
        )
    ),
    If(
        VarProfile.Access_Level.Value = "TM",
        ClearCollect(
            Top_10_Data,
            Filter(
                Top10Data,
                StartsWith(Short_Month, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = TM_Email
            )
        ),
        ClearCollect(
            Top_10_Data,
            Filter(
                Top10Data,
                StartsWith(Short_Month, REFVariShortMonth.Text),
                Year = REFVariYear.Text,
                VarSelecteduserEmail = SM_Email
            )
        )
    )
);
Set(WBLoading, false)

Hope this helps!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

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