Hi All, Is there a particular reason why a CS...

Hi All, Is there a particular reason why a CSV file generated by the AppSheet has a random arrangement of the rows in the data table? When I refer back to the original Google Sheet, the rows are in correct order, but the CSV file shows data in a haphazard manner. Any reason for this behavior?

0 22 713
22 REPLIES 22

Good question I was just wondering that myself.

The actionโ€™s Do this actually says: App: export this view to a CSV file I just tested it and as expected if you set a sort order for a table view, the exported CSV file will respect the same sort order.

However if the view has no particular sort order, the generated CSV seems to be in random order. Perhaps in that case it should have been in key column order? @praveen

Or maybe row number?

Okay @RezaRaoofi and@Lynn Thank you very much. Iโ€™ll try setting a sort order.

Youโ€™re welcome!

@RezaRaoofi Hi, I tried setting up a sort order (well, I actually used the _RowNumber, Ascending as I thought thatโ€™s the easiest for my requirement), but still the CSV is generated in a very random order. Would like your help here! Thanks.

@Malaka_Jayawardene

I have not tried sorting by _RowNumber myself; perhaps it has to be a different sort order.

Perhaps sort by _RowNumber is equivalent to โ€œno sort orderโ€.

Hi guys, has one found the solution? I also noticed the same problem with random rows order in exported CSV file.

Yes I tried but it doesnโ€™t work really. FYI I used [_RowNumber] to sort table.
View


CSV

By my own testing, you canโ€™t sort by a column that is not included in the view/column order.
You can, of course, but it wonโ€™t affect the CSV.
This might be a bug or not expected behaviour.
@Phil Can you give us some insight about this?

In view I use to export there are all columns so it is not the reason I think. As for [_RowNumber], it is hard to say I do not know whether it includes into the CSVโ€ฆ Thanks for help!

I did my testing and the rows are sorted if Iโ€™m using a column that is shown in the view

It would not make sense to sort a DATA file by a column that is NOT included in the data. For any arbitrary user (or process) who wouldnโ€™t know how it was sorted in the first place, it would still be โ€œrandomlyโ€ sorted.

If you NEED to sort by a column, it should be included. It has value to the consumer, if only to be able to deduce HOW the data was sorted.

It does since thatโ€™s how you sort a table on the app to show data from high to low or log to high using [_RowNumber] and it should export the table to CSV respecting that order.

We have no obligation to create a hidden NOW() column to each one of our table just to have the same functionality. If thatโ€™s the case, we shouldnโ€™t be able to select [_RowNumber] at all.

I like the fact that we can sort the rows on a table view with a column that is not shown / is not in the column order since that prevents the table to show the arrow Up or Down on a column that ends up distracting the user.

I get what you are saying. All I can say is a repeat, using Row Number for sorting has no value but if you do sort the data by that number, it DOES have value to the resulting data and therefore it should be included.

Row Number is a legacy item and kept for that reason. Knowing how its assigned, I personally never use the value.

So the NOW() InitialValue hidden and added on every single table is the only way to go?
How do you sort by newest added to the oldest without [_RowNumber]? Just curious

Maybe you donโ€™t do that at all!

If I needed to ensure that rows could be sorted by WHEN they were inserted into the system, then Yes I would use a DateTime column.

I have been avoiding details but let me dive a little deeper as to why Row Number breaks down for me.

Sheets - For the most part Row Number will match the order of entry. But consider this use case, a user goes offline for a few hours but still enters data in offline mode. Other users with connectivity add rows that funnel into the sheet right away. Once the offline user goes online and Syncs, those rows are added into the source sheet at the bottom. It looks as if those rows were added after all the others but technically they werenโ€™t. Sorting by a DateTime can correct for this.

Databases - With the possible use of Indexing and optimizations, there never is any way to know if the rows handed to AppSheet are in order of entry or not.


I always code my client apps with the notion that I will someday migrate them to a database. With this in mind, I create and use the data in a way that will make migration to a database simple and quick.

Fair enough.
I can see this as a problem on apps with 5+ users.

This could be a โ€œTips & Tricksโ€ section to see best practices.
I also have in mind the idea of upgrading to a SQL database, for example, and I donโ€™t know if the rules I apply today using Excel will work as expected

Yes it is the solution but only if you sort other columns than [_RowNumber]!
In my case wonโ€™t work
Thanks for help again!

You really do not want, nor should you need, to sort by Row Number. That value is given by AppSheet based on order of the rows being loaded and as such is arbitrary.

Nice discussion btw I think I understood [_RowNumber]. Thanks for that!

Top Labels in this Space