When forms with non-mandatory fields are submitted empty, no records are saved for them in the FieldData SQL table. Therefore, when an export is performed, if the first submitted record has empty fields, the corresponding columns might be added last in the exported CSV file. This might result in a different column reordering depending on the time of the export.
To resolve the issue, upgrade your solution to Sitecore XP 10.3.0 or later.
To prevent the issue, you can customize the behavior by modifying the logic of the GenerateFileContent method, as follows:
For example, this line:
var formData = formEntries.OrderByDescending(item => item.Created);
Can be replaced with the following line:
var formData = formEntries;
Note: The code sample is provided only as a starting point and the logic of the GenerateFileContent method can be modified depending on your needs.
<register serviceType="Sitecore.ExperienceForms.Data.IExportDataProvider, Sitecore.ExperienceForms" implementationType="Sitecore.ExperienceForms.Client.Data.CsvExportProvider, Sitecore.ExperienceForms.Client" />