Sort Columns By Date

Hi. Is there a way to sort columns by date if the range of dates change each time the flow is run? For example, if it runs every day for the last 30 days, how do I maintain an ascending sort?

Thanks,
Jonathon

Hi @Jonathon_Jonas,

Quick question: You’re trying to sort columns by date, not rows, correct?

Hi Brian,

Yes, columns by date. Oldest date first and then most recent all the way to the right. And then include a total column as well as the final column on the right.

Thanks,
Jonathon

Got it. I think your best option would be to use the “flip table” step to get the columns turned into rows, then sort the rows, then use another flip step to get it back to having dates as the columns.

It’d look like this:

image

The tricky thing is getting a “total column”, because the “Math” step needs you to reference the names of columns, but the names of your columns will be changing, like you said.

The first step would be to get your source table looking like this (pic below) where there is a column called “Date” who’s value is “Amount”. Those two cells will become your headers once you flip the table.

(If you can change your source table, I’d just add those as the first column. Otherwise, you can add a column in Parabola and then re-order it so that it becomes the first column.)

2.Then, flip the table, then sort it:

image

  1. Then, flip it back:

  1. Here, you could add a total column by using the Math step, but like I said, that won’t work long-term if the names of your columns are going to change.

Another question - is it always the same number of dates, or is that changing as well?

@Jonathon_Jonas

To follow up, you can get a total column by using the “Sum by group” step. First you would just add a placeholder column that you’ll use for the grouping.

In the end it’ll look like this:

image

The upper section is for getting a row where you have the total. Then you add that back to the rest of the data and flip the table back so that it’s in columns again.

The “Insert text column” step:

The “Sum by group” step:

image

Then you stack the tables and flip it back, so in the end you have something like this:

You can copy the snippet below and paste it into your flow to see all the steps I created above. Then you’d need to just connect your data source in place of the Google Sheets step you see in the screenshot above.

parabola:cb:b40cf0ce-9aec-46e5-94de-3cf44af7e905

Let me know if you have any questions about how any of this works and good luck!

3 Likes