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?
Table of Contents
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.
Discover more from SharePains
Subscribe to get the latest posts sent to your email.
Hi Pieter
Jesper here. Well, there’s no doubt, AI still has some way to cover. But maybe it also be about not being too quick to judge. From my experience Copilot and especially Copilot from Visual Studio Code does a pretty good job in delivering value. But the answer you get depends a lot on the question you ask. Now you don’t show the prompt you used so I made a guess. Here’s what I got out of GitHub Copilot in VS Code:
Could you please give me a Power FX expression that calculates the first working day in the next month?
GitHub Copilot:
Certainly! Here is a Power FX expression that calculates the first working day (Monday–Friday) in the next month:
// Calculates the first working day (Monday–Friday) in the next month
Set(
firstWorkingDayNextMonth,
With(
{
firstDayNextMonth: DateAdd(DateValue(Text(Today(), “yyyy-mm”) & “-01”), 1, Months)
},
If(
Weekday(firstDayNextMonth, StartOfWeek.Monday)
firstDayNextMonth,
DateAdd(firstDayNextMonth, 8 – Weekday(firstDayNextMonth, StartOfWeek.Monday), Days)
)
)
)
Now I haven’t tested it to see if it provides the correct answer, but the point is more that AI is here to stay and whether we like it or not, we need to find a way to ‘live together’.
Maybe we (humans) could benefit from learning to speak a little bit of Promptesian?
Br Jesper
Hi Jesper, thank you for your comment.
I am not against AI at all. It is however very important to realise that copying AI without knowledge is not giving the best result.
Coding knowledge is likely to fade away as many new coders build up their copy/paste skills before they develop their coding/analysis skills.
My prompt was almost identical to yours.
Further on my opinion on AI, I am against the wrong uses of AI.
Sometimes it feels like companies generate marketing materials using AI without any of their own vision included.