Blog

Copilot - A cautionary example of how Copilot can write formula that's completely incorrect!

Although Copilot simplifies the task of writing formula, it still is important to verify that what Copilot suggests is correct. Here's an interesting example of where Copilot got it very wrong.

The great news is that the Copilot feature in Power Apps was made generally available this week. This includes the natural language Dataverse table designer and the Copilot features within Power Apps Studio.

Although these AI features make us more productive, it's important to be vigilant and to check that the suggestions are correct. Here's an example that I recently encountered where Copilot got it wrong.

An example of how Copilot gives the wrong suggestion in Power Apps

To begin, I clicked the Copilot menu from a gallery control to format a date value.

In the panel that appears, the 'Desired data formatting' shows 3 selectable options - '12/5/2023', 'December 5, 2023', 'Tuesday, December 5, 2023'.



I selected the 'December 5, 2023' option. The screenshot below shows the Copilot suggestion.



What's wrong with the Copilot suggestion?

For clarity, here's a formatted version of Copilot's suggestion.

Text(
With({yearStart:Date(Year(ThisItem.TargetEndDate),1,1)},
With({yearEnd:DateAdd(yearStart,1,"Years")},
DateAdd(yearEnd,-1,"Days")
)
),
"mmmm","en-GB"
) &
" " &
Text(ThisItem.TargetEndDate,"m","en-GB") &", " &
Text(ThisItem.TargetEndDate,"yyyy","en-GB")

For anyone with any familiarity with how to format date values, it should be quite obvious that the correct answer is the following expression.

Text(ThisItem.TargetEndDate,"mmmm, d yyyy")

The screenshot below highlights the result of Copilot's suggestion. It hardcodes each date value with the month name 'December' (using an unnecessary step to get the last day of the year). It then incorrectly follows this by displaying the month number rather than the day number,


Why did Copilot get it wrong?

The cause of this issue appears to be a localisation bug. I'm based in the UK (which uses a date format of dd/mm/yyyy).

What appears to happen is that the Power Apps editor correctly recognises the date values in the underlying data source and correctly provides the 3 desired date formats (because the editor is location aware).

When Copilot carries out its processing, it assumes that the input dates are in US format and therefore produces the incorrect Power FX formula that attempts to carry out a transformation and to substitute day with month numbers.

Conclusion 

The important thing to learn from this is that much of the Copilot functionality has been built, trained, and tested on US systems. Therefore, it's important to exercise additonal care when using Copilot for functions that are related to dates, or other region-specific usages.

  •   Categories: 
  • ai