How do I get transactional data from subscription data in Tableau?
Albert Arrutinian
I have a chunk of data with subscriptions like this:
customer_name start_date end_date subscription_amount
A 1-7-2017 31-10-2017 4 USD/month
B 1-8-2017 30-09-2017 2 USD/month
C 1-10-2017 30-11-2017 3 USD/month
I need to convert this to transactional data, so the end result should look like this:
customer_name payment_date amount
A 1-7-2017 4 USD
A 1-8-2017 4 USD
A 1-9-2017 4 USD
A 1-10-2017 4 USD
B 1-8-2017 2 USD
B 1-9-2017 2 USD
C 1-10-2017 3 USD
C 1-11-2017 3 USD
I need this conversion to run the analysis in Tableau, but an Excel solution is also acceptable. I don't want to do it manually, but looking for an automated solution using SQL or Python (I'm new to both)
indentation
Using python (you'll need some formatting of the data to exactly match your question, but the idea is here) http://rextester.com/OENHUT92986
Use this comprehensive list to listMonths = [dt.strftime("%Y-%m-01") for dt in rrule(MONTHLY, dtstart=dtstart, until=until)
list the first day of each month between 2 dates.
import datetime
import time
from dateutil import parser
from dateutil.rrule import rrule, MONTHLY
data=[
{"customer_name":"A" ,"start_date":"2017-07-01","end_date":"2017-10-31","subscription_amount":"4 USD/month"},
{"customer_name":"B" ,"start_date":"2017-08-01","end_date":"2017-09-30","subscription_amount":"2 USD/month"},
{"customer_name":"C" ,"start_date":"2017-10-01","end_date":"2017-11-30","subscription_amount":"3 USD/month"}
]
for datum in data :
dtstart=parser.parse(datum["start_date"])
until=parser.parse(datum["end_date"])
listMonths = [dt.strftime("%Y-%m-01") for dt in rrule(MONTHLY, dtstart=dtstart, until=until)]
for month in listMonths :
print datum["customer_name"],month,datum["subscription_amount"]
will yield:
A 2017-07-01 4 USD/month
A 2017-08-01 4 USD/month
A 2017-09-01 4 USD/month
A 2017-10-01 4 USD/month
B 2017-08-01 2 USD/month
B 2017-09-01 2 USD/month
C 2017-10-01 3 USD/month
C 2017-11-01 3 USD/month