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 / Global variable will i...
Power Apps
Unanswered

Global variable will initialise onstart

(0) ShareShare
ReportReport
Posted on by

Hi All

Was hoping someone could help I have some code which runs on the "onstart" event of a PowerApps
and the variable "varStartDate" fails initialize. The "varUser" initializes but is null when ever called

Please note the loop work perfectly when a value for varStartDate is hard coded can anyone suggest what is wrong or how I might get pass it


-------------------- Code --------------------------------------------------------------

Set(varUser,User());
//get the date of last monday
Set(varStartDate,DateAdd(Today(),
If(Weekday(Today())=1,-6,
Weekday(Today())=2,0,
Weekday(Today())=3,-1,
Weekday(Today())=4,-2,
Weekday(Today())=5,-3,
Weekday(Today())=6,-4,
Weekday(Today())=7,-5
)
);

Clear(NextDates);
ClearCollect(Loop,{Index:0},{Index:1},{Index:2},{Index:3},{Index:4},{Index:5},{Index:6},{Index:7});
//load the NextDates Collection
ForAll(
Filter(Loop,Index<=6),
Collect(NextDates,
{
Date:DateAdd(DateTimeValue(varStartDate),Index,Days),
DaysSincePickedDate:Index,
DayOfWeek:Weekday(DateAdd(DateTimeValue(varStartDate),Index,Days))
}
));

//last week
ClearCollect(Mondays,{MDay:Text(DateAdd(DateTimeValue(varStartDate),-7),"dd-mm-yyyy")});
//This week
Collect(Mondays,{MDay:Text(DateTimeValue(varStartDate),"dd-mm-yyyy")});
//Next Week
Collect(Mondays,{MDay:Text(DateAdd(DateTimeValue(varStartDate),7),"dd-mm-yyyy")});


------------------------ Code End ----------------------------------------------------------------------------

Categories:

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

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard