It is Friday and I thought I will try out Copilot to generate an expression for me. When using Copilot it is so easy to switch your brain off.
Copilot use, is it good or bad?
First of all I’m not against getting some help. And Copilot can be a good assistant for some people. So I’ve put that to the test by asking for an expression that calculates the first working day in the next month.
Then I asked Copilot to generate a comment as well. First of all the formatting is horrible so I reformatted the code first. This is just a single press of a button so not too much of a problem.
//This expression sets the variable `myvar` to a date value that is determined based on the day of the week of the first day of the next month. If that day is a Sunday (1), it adds two days to the end of the current month; if it is a Saturday (7), it adds three days; otherwise, it adds one day to the end of the current month.
Set(myvar,If(Weekday(DateAdd(EOMonth(Today(),0),1,TimeUnit.Days))=1,DateAdd(EOMonth(Today(),0),2,TimeUnit.Days),If(Weekday(DateAdd(EOMonth(Today(),0),1,TimeUnit.Days))=7,DateAdd(EOMonth(Today(),0),3,TimeUnit.Days),DateAdd(EOMonth(Today(),0),1,TimeUnit.Days))))
After formatting the code I’m getting the following code.

Set(
myvar,
If(
Weekday(
DateAdd(
EOMonth(
Today(),
0
),
1,
TimeUnit.Days
)
) = 1,
DateAdd(
EOMonth(
Today(),
0
),
2,
TimeUnit.Days
),
If(
Weekday(
DateAdd(
EOMonth(
Today(),
0
),
1,
TimeUnit.Days
)
) = 7,
DateAdd(
EOMonth(
Today(),
0
),
3,
TimeUnit.Days
),
DateAdd(
EOMonth(
Today(),
0
),
1,
TimeUnit.Days
)
)
)
)
After the reformatting exercise we can see straight away that the code isn’t very well optimized.
Coding without Copilot
Now recoding the above gives me the following code.

Set(EndOfMonth, EOMonth(Today(), 0 ));
Set(
myvar, DateAdd(EndOfMonth,
Switch( Weekday(EndOfMonth) ,
7, // Saturday
2, //Add 2 days
6, // Friday
3, //Add 3 days
//Default
1 //Next day
)
,TimeUnit.Days)
)
Which code is more efficient?
We should look at a couple of factors here. Time to develop and size of the code.
The Copilot option took me 30 seconds to develop while the optimized version took me 15 minutes. Do you accept poorer code so that you can gain only 14.5 minutes?
What are your experiences with Copilot in Power Apps? Please let me know in the comments below.

Leave a Reply
You must be logged in to post a comment.