Calculating running (cumulative) sum with start and end dates over time - google-data-studio

I'm looking for a way to calculate recurring revenue over time in a time plot where the X-axis is the date and Y-axis is the total amount of revenue (sum). The question we're trying to answer is "At any given point in time, what is the total amount of revenue coming in?"
Every line in the source data has an account name, subscription type (new, renewal, expansion), annual subscription amount, service start date, and service end date.
[Sample of data below]
Account
Type
Subscription Amount
Service Start
Service End
001
New
$ 1000
Jan 1, 2020
Dec 31, 2021
002
New
$ 2000
Feb 1, 2020
Jan 31, 2021
003
New
$ 3000
Apr 1, 2020
Mar 1, 2022
001
Expansion
$ 500
May 1, 2020
Dec 31, 2021
002
Renewal
$ 2500
Feb 1, 2021
Jan 31, 2023
004
New
$ 1000
Mar 1, 2021
Feb 28, 2023
002
Expansion
$ 250
Jun 1, 2021
Jan 31, 2023
001
Renewal
$ 1500
Jan 1, 2022
Dec 31, 2023
The main issue I'm running into is that when using either running sum or "cumulative" under the time plot settings panel, the total will continue running on the X-axis regardless of the service end date. This is a problem for situations like Account 002, which renews Feb 1st, 2021. Data Studio would (incorrectly) show an amount of $4500 for that account starting on Feb 1st -- where I want it to show only $2500 at that time.
Comparing what the data should be showing at any point in time vs. what actually happens:
Date
Amount I want to see
What is currently calculated
Jan 1, 2020
$ 1000
$ 1000
Feb 1, 2020
$ 3000
$ 3000
Apr 1, 2020
$ 6000
$ 6000
May 1, 2020
$ 6500
$ 6500
Feb 1, 2021
$ 7000
$ 9000
Mar 1, 2021
$ 8000
$ 10,000
Jun 1, 2021
$ 8250
$ 10,250
Jan 1, 2022
$ 8250
$ 11,750
Jan 1, 2023
$ 5250
$ 11,750
Is there a way to achieve this?
Ideally, the most elegant solution seems to be to tell the plot to only sum between dates (i.e. sum if "reported x-axis date" is between Service Start date and Service End date), but I don't know how to reference the X-axis value in a formula.
I have not yet tried blending the data but I'm thinking that may be another path forward as well?
Any help on this would be much appreciated!

Related

Formula for a conditional cumulative sum in Mac Numbers

I have a spreadsheet in Mac1 Numbers2 that tracks amounts due and amounts paid, ordered by date.
Transaction Date
Customer Name
Amount Due
Amount Paid
...
...
...
...
16 Nov 2022
Name1
$70.00
$70.00
16 Nov 2022
Name2
$70.00
$0.00
16 Nov 2022
Name3
$0.00
$70.00
16 Nov 2022
Name2
$0.00
$70.00
...
...
...
...
I would like to add an additional column, Running Total, that shows for each transaction, the accumulated credit/amount due for that row's customer up to that row's date.
Transaction Date
Customer Name
Amount Due
Amount Paid
Running Total
...
...
...
...
...
16 Nov 2022
Name1
$70.00
$70.00
$0.00
16 Nov 2022
Name2
$70.00
$0.00
-$70.00
16 Nov 2022
Name3
$0.00
$70.00
$70.00
16 Nov 2022
Name2
$0.00
$70.00
$0.00
...
...
...
...
...
I have a separate sheet that shows the complete running sum for each customer from the beginning of time through the present, but I'm at a loss for how to create a row-by-row, grouped running sum (or even whether Numbers allows for it).
I have tried to create formulas with SUMIF, but have not made headway in understanding how to code the kind of filter I need, so have not even created a runnable test formula. Various Google searches for creating running sums by group/category in Numbers, Excel, and GoogleSheets have not yielded results.
In a database, this would be trivial, but I'm restricted to Numbers.
1 MacOS Monterey 12.5
2 Numbers 12.2

Different results between dimension Month and Date (Year Month)

I am trying to generate a list of users but I get different values depending on which dimension I use.
The data source is a GA4 property, but it also occurs with UA.
This is my example: https://datastudio.google.com/reporting/f75c1478-e738-45ad-8a23-97c51b69c374
For the attached table, if I use the "Month" dimension, it returns a different value that I use the dimension "Date (Year Month).
Could someone explain me the difference and how I could fix it?
Thank you very much in advance!
Date (Year Month)
Users
New users
1
Aug 2022
70,469
52,103
2
Jul 2022
71,939
54,837
3
Jun 2022
75,868
57,613
4
May 2022
85,273
67,462
5
Apr 2022
82,099
63,977
Month
Users
New users
1
Aug 2022
58,674
52,025
2
Jul 2022
60,150
54,748
3
Jun 2022
62,643
57,498
4
May 2022
73,172
67,398
5
Apr 2022
69,164
63,893

I have facing issue with date in angularjs, when I use central timezone(-6,-7,-8) getting issue with date

I have this date in startdate=2021-10-27T00:00:00-04:00,
d=new Date(data.StartDate) // outputTue Oct 26 2021 23:00:00 GMT-0500
But date is getting one day before'Tue Oct 26 2021 23:00:00 GMT-0500' in central timezone(below -6,-7,-8...),
How to resolve this date issue(26) in central timezone and for all timezones it is getting well. But only -6,-7... timezone have an issue

Moment returns wrong datetime

I am using React as a front-end framework, python as a back-end language.
Python returns UTC datetime to React. Somehow, react+moment shows wrong local datetime (Berlin timezone). May I know, what to fix this issue ?
Case 1 is correct, but case 2 is wrong
Case 1:
Python returns to React: "2019-10-02T22:00:00Z"
React+Moment returns: Thu Oct 03 2019 00:00:00 GMT+0200 (Central European Summer Time) {}
moment('2019-10-02T22:00:00Z').toDate()
Thu Oct 03 2019 00:00:00 GMT+0200 (Central European Summer Time)
Case 2:
Python returns to React: "2019-10-30T22:00:00Z"
React+Moment returns: Wed Oct 30 2019 23:00:00 GMT+0100 (Central European Standard Time) {}
moment('2019-10-30T22:00:00Z').toDate()
Wed Oct 30 2019 23:00:00 GMT+0100 (Central European Standard Time)
Python is using utc while moment.js is using an extra offset of +1 or whatever (your local time). If you want moment.js to use utc too, do this:
const m = moment.utc('2019-10-30T22:00:00Z')
console.log(m.toDate())

Parsing a schedule to upload to Google Calendar

I've got half a C class and maybe one or two shell scripts I've written to draw from as experience. I'm trying to parse data from a schedule in order to upload it to Google Calendar from a terminal. I receive the schedule in a block of text like this:
Sat Sep 01 2012 00:00:00 GMT-0700 (PDT) Saturday 2:00PM 11:00PM
Sun Sep 02 2012 00:00:00 GMT-0700 (PDT) Sunday 00:00AM 00:00AM
Mon Sep 03 2012 00:00:00 GMT-0700 (PDT) Monday 9:00AM 6:00PM
Tue Sep 04 2012 00:00:00 GMT-0700 (PDT) Tuesday 9:00AM 6:00PM
Wed Sep 05 2012 00:00:00 GMT-0700 (PDT) Wednesday 00:00AM 00:00AM
Thu Sep 06 2012 00:00:00 GMT-0700 (PDT) Thursday 8:00AM 4:00PM
Fri Sep 07 2012 00:00:00 GMT-0700 (PDT) Friday 10:00AM 7:00PM
And I've figured out that with googlecl I can type this into my terminal:
$ google calendar add "Sep 3 Work 9 to 6"
And I'll get a calendar event I can then have automagically synced to my phone.
I've read through some of the documentation on sed and awk figuring I could just use these to grab say the 5th through 10th (ie Sep 01) characters of each line and the time the shifts start and end, add the "Work" title, and pipe this directly to googlecl. I haven't gotten it down yet though.
I've also tried researching file i/o in C, as I could export my schedule as seen above to a text file and then maybe use C to pipe the schedule in plain-er English to Google Calendar.
Is sed and awk the preferred way of doing this? (I guess doing it with just common *nix commands is my first choice if I can figure it out) Should I instead write a little program in C to do this? Any help (even if it's just linking me to your favorite tutorials on either so I can do some more reading) would be appreciated, as many of the pages I've found Googling were both very long and a little over my head. Thanks.
awk '{ if ($9 != $10) {print "google calendar add \"" $2, $3, "Work", $9, "to", $10"\""}}' cal
Result:
google calendar add "Sep 01 Work 2:00PM to 11:00PM"
google calendar add "Sep 03 Work 9:00AM to 6:00PM"
google calendar add "Sep 04 Work 9:00AM to 6:00PM"
google calendar add "Sep 06 Work 8:00AM to 4:00PM"
google calendar add "Sep 07 Work 10:00AM to 7:00PM"
Explanation:
if ($9 != $10) {...}
If they are the same it looks like you don't need to enter them in your calendar. Also, implicitly checks for non-empty lines.
print "google calendar add \"" $2, $3, "Work", $9, "to", $10"\""
Print the string with relevant fields, escaping the quotes.
edit: As for executing it automatically, there is quite some delicate quoting issues going on, so putting this line in a for-loop is not trivial (for me!). One easy way out is to store the results in "file", and then "sh file".

Resources