Skip to content
Advertisement

Generate dates in-between date and date after

Based on the table below

I want to generate the dates in between, by dividing the revenue by the number of days from the date in the current row and the row below.

Example: Revenue in US on 1 January 2020 is 120. The next revenue date for the US is 5 January 2020. There are 4 days in betweeen. Thus, to make the revenue daily, I would like to divide 120 divided by 4 days = 30.

Output table

My idea is to use a generate_series, but generate_series requires two dates?

Advertisement

Answer

Similarly to the above reply, the lead function will give you the value of the next date. Also, in case you need to count up to today’s date in when you don’t have any further transaction, the coalesce can substitute the missing target date with CURRENT_DATE.

Data

Query

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement