Conditional series in Tableau based on Date Frequency - datetime

In the table below I have customers who pay an amount at a predetermined frequency and duration. In Tableau I want to showcase the payments owed from today until expiry. I want to, conditional on the frequency determine what are their payment and when these payments will fall due.
Date-Start
Date Expiry
Customer
Frequency
Amount
01 Jan 2022
31 Jan 2025
A
Monthly
$500
01 March 2021
28 Feb 2026
B
Quarterly
$800
I have created a date diff to get number of days between today and expiry but im still stuck. How do I show a chart etc with customer A paying $500 for the next couple years? As it stands now I have one static datapoint. Essentially I want to create a series of point as long as expiry hasn't occurred.

Related

Cloud Firestore: query for an item's availability given a timestamp

Imagine an Airbnb like app. A rentals collection contains documents with fields start and end of type timestamp that records the start date and end date of the rental (year, month and day only). Inside my Flutter app, when a user wants to make a new rental request, I need to check if the request interferes with any existing rentals. Would it be too much to store an array of Timestamp objects that contain the amount of days, then use arrayContains to query/check?
For example:
rental #1
start: Jan 1
end: Jan 2
days: [Jan 1, Jan 2]
rental #2
start: Jan 6
end: Jan 10
days: [Jan 6, Jan 7, Jan 8, Jan 9, Jan 10]
Suppose the user wants to book a rental for Jan 3-4. I would run a loop and query for documents with arrayContains: Jan 3 and arrayContains: Jan 4 and if it returns any documents, then I know the rental request date is invalid. The maximum amount of days a user can rent is 27 days, although I expect the average rental duration to last under 7 days. Is my method viable? I could change the maximum rental duration from 27 to 14 possibly.
The other method I came up with is to query for the rentals immediately before and after the desired pickup time. So using the above example, if my desired rental date is Jan 3-4, I would query for the closest rental that ends before Jan 3 and the closest rental that starts after Jan 4. However, the issue I'm running into is what if the user in rental #1 decides to extend their rental from Jan 1-2 to Jan 1-3 (before our user is able to refresh their app)? Or if a particular listing has no rental history associated with it.

Representing an entire day or week or month as a number like timestamp

How can a day or week or month, essentially a range of time be represented by a single number?
The next interval would represent a number 1 more than the number for the previous interval, just how the next second is 1 more than the previous second, in timestamp representation.
Given a bunch of such numbers, the larger number simply means its representing a time interval afterwards in time, when compared to a number smaller than it.
Just realized if I stick to UTC and represent the day as YYYYMMDD, this becomes a number that I am looking for.
20180420 // 20 april 2018
20180421 // 21 april 2018
20180510 // 10 may 2018
20190101 // 1 jan 2019
This works for representing a day perfectly, I think.
For week, maybe do ceil() of days of current month divided by 7 for representing week as a number W and then using the format: YYYYMMW.
2018043 // 3rd week of april 2018
2018045 // 5th week of april 2018, though may not be the 5th week semantically but representation model works, greater than 4th week of april 2018 and smaller number than 1st week of may 2018
For month, simply YYYYMM works.
I feel so smart right now! 😄

Google Analytics - showing different revenue for same month viewed

When viewing - Acquisition>>>All Traffic>>>Source/Medium with organic traffic segment loaded with dates Jan 1 - Oct 31, with the revenue metric (line chart graph setting) while viewing by revenue per month, I get the total amount of organic revenue per month from Jan 1 - October 31st. Each month shows the total organic revenue.
However, If I change the date range to only show revenue for October 1st - 31st (note, nothing else is changed but removing Jan 1 - Sept 31), the total revenue for October doesn't match the October revenue when I view it from Jan 1 - October 31st. It is really odd and I don't understand why.
Does anyone have any insight on why the month of October shows different revenue when I set the dates for October 1st - 31st compared to Jan 1st - October 31st with each month's revenue isolated in the graph?
The most likely explanation is that it's a sampling issue, go into GA and look for the shield icon at the top of the report page. If it's any color other than green, hover over it to see what the sampling is. If that is the issue, the main way to get unsampled data is to use a smaller date range, or looking for 'unsample' tools.

Removing inconsistent observation in r

I have the data frame as I have below. I want to examine all Intake frequencies with "03 Month". My mission is to remove any Intake that is far away from three months by comparing the dates. Intake stands for when a client first register with an agency. 03 Month is three months follow up.
I am running R version 3.3.2 in Window environment.
I have taking the difference between the current date and the previous date in days. However, it is not straight forward to eliminate the observation with less than 90 days and greater than say 100 days as some patient has only intake and no follow up which i will like to keep.
Any help please.
ID DATE FREQ
1 08/09/2014 Intake
1 27/03/2015 Intake
1 01/09/2015 Intake
1 07/12/2015 03 Months
1 18/03/2016 06 Months

Get data of exactly one year out of an xts time series

I'm programming a function in which I want to plot let's say the stock price for any stock during the last 365 days. However not trading days, but just a one year period. So if I'm generating the chart on the 15th of February I want data from the 16th February 2012-15th February 2013. How can I do that? last() for example shows me the last 365 trading days or days of which there is data available.
library(quantmod)
getSymbols("AAPL")
plot(AAPL)
User character subsetting.
AAPL[paste(Sys.Date()-365, Sys.Date(), sep="/")]

Resources