Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9788

Fill zeros for the dates when no data was included

$
0
0

I have a Sales sheet with date and values, looking like this:

+---+------------+-----------+-------+|   |     A      |     B     |   C   |+---+------------+-----------+-------+| 1 | Date       | Some data | Value || 2 | 11/10/2021 | foo       | 50    || 3 | 12/10/2021 | bar       | 25    || 4 | 14/10/2021 | baz       | 75    |+---+------------+-----------+-------+

And I have an other sheet named Revenues in last 30 days, which is being built dynamically using this formula: =SORT(QUERY(Sales!A2:C,"select * where A >= date '"& TEXT(today() - 30,"YYYY-MM-DD") &"' label count(A) ''",0))

What this formula does is it gets all the rows from my Sales sheet where A (Date) is >= to today minus 30 days, then it copies all these rows into the sheet, which I then use to render a "Last 30 days" graph.

However, I'd like to add an additional "formula?" which will insert an extra row for every day that wasn't present in the Sales sheet, with 0 as Value, that way my graph will also show days with 0 revenue, which isn't the case as of right now.

My Revenues in last 30 days sheet should then look like this:

+---+------------+-----------+-------+|   |     A      |     B     |   C   |+---+------------+-----------+-------+| 1 | Date       | Some data | Value || 2 | 11/10/2021 | foo       | 50    || 3 | 12/10/2021 | bar       | 25    || 3 | 13/10/2021 | new       | 0     || 4 | 14/10/2021 | baz       | 75    |+---+------------+-----------+-------+

Compare it to the above table and notice the difference, 13/10/2021 was added with

How can I achieve that?

I stumbled upon this post but was not able to use any of the answers there to achieve what I wanted.


Viewing all articles
Browse latest Browse all 9788
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>