Creating a base date for analysis in tableau - tableau-desktop

I have a problem where i want to set a base date to a date time variable in the database. I would then use the base date for my aggregations. And the days subsequent to this base date would be categorised as Day1, Day2 and so on.
So for example, if I want to see cohorts of orders created by the base date - I would want the calculated after this date. I don't want to do this using a date filter.
Image below:

It seems like you could use the DATE function to convert your field, like this:
DATE([Acquisition Date])
If you don't already have the year value stored, but have a method in mind to add it, you could use MONTH([Acquisition Date]) to obtain the month and date and DAY([Acquisition Date]) to obtain the date. You could then use MAKEDATE function to build the date or MAKEDATETIME function to build the datetime value.
Once it's stored as a date value, you could use DATEADD to add and subtract days to it as needed.
There are multiple formulas available for converting Tableau dates, described here: https://help.tableau.com/current/pro/desktop/en-us/functions_functions_date.htm
Is this what you're looking for?

Related

Is it possible to have a variable within a hyperlink in MSWord?

I want to have
http://reports.ieso.ca/public/DispUnconsHOEP/PUB_DispUnconsHOEP_date_v24.xml
in Microsoft Word, but want the date to be a variable. When clicked I want it to be filled in with yesterday's date in the format of YYYYMMDD.
An example would be
http://reports.ieso.ca/public/DispUnconsHOEP/PUB_DispUnconsHOEP_20160707_v24
but want the date to change depending on the current date

Swift CoreData : Check Date is Available Control

I am using CoreData. I'm adding date and some datas. I need a if statement. This is if statement will work like that :
"if this date is available in CoreData database, user won't add any data."
I used this:
if newuser.valueForKey(NSDate) as NSDate == NSDate()
This is absolutely wrong. I'm new and i don't create this if statement. how can i do this ?
Thanks already !
To compare the dates you should be using isEqualToDate:
if newuser.valueForKey(NSDate).isEqualToDate(NSDate())
But, dates are very accurate, so the current date would need to match the saved date, and that's never going to happen - at least a part of a second will have passed before you make the comparison.
So, what you really need to do is to find out what day, month and year the date is an compare those.
In a number of ways it would be best to store these values explicitly in Core Data instead of using a date object, though both would work. In either case you need to get the date components from the date in order to find out the day, month and year and then you need to compare them (possibly creating a date with only day, month and year and no time so you can compare it to the stored date which should also have no time set).

Should date field in DW date-map be of Date data type or of String data type, if I want to put placeholders?

I have a date map (date dimension) like every other data warehouse.
The most obvious way to store date field in the date field is in date datatype. However, I want to keep some records in my date dimension which ID as negative values and the date field should give description of why this date is invalid.
For example, in my fact table, let's say I have a field called order_date_id which references the date dimension. However, for some records in the fact table, I want to say that the order_date was not recorded by the system and hence we can't use it. But I want it's entry present.
I thought that I would make an entry in the date dimension with ID=-1 and date = 'Date was not recorded'. But to use this kind of a placeholder, I will have to keep date as a string value. If I store it as a string value it will be very ineffective when I compare two dates.
Please advise a good practice.
I think you are confusing two things;
Date Dimension Design
Identification of Date not assigned by system
This is how I would design the date dimension
Date_id = number with yyyymmdd - intelligent key and this will be the primary key; this saves doing a lookup to the database to assign the id
Date - the actual date
Year - year
Month - Month (yyyy-mmm or yyyy-mmmm)
Month_Nbr - Month ( yyyy-mm )
Quarter - yyyy-Qn(1,2,3,4)
all the other attributes you need
if there are sales order which do not have a date assigned, assign them 19000101 and have them in your fact table...
if you incrementally keep getting sales order without dates, then I would consult the business and put in the 1st day of the month of when they are arriving into the system; this will be a more acceptable solution.

What is the correct type I should use to store a date up to the minute?

I want to store the date of an event in my database, but I want to do so without storing informations about seconds or anything smaller than seconds. Using Rails, in my migration I have the option to create a date column or a datetime column, the first one of which is too less accurate, and the second one is too much (up to the second and less). Which type should I choose to store such a date? Currently I'm using datetime and setting the seconds to a fixed value (e.g. 0) manually each time some date is set in the model.
Something like this:
self.date ||= Time.now.change(:sec => 0)
Am I totally out of track? Should I just use an integer field for each component of the date instead? (year, month, day, etc...) Or is datetime the correct type but I'm not understanding the purpose of it? (I think it's meant for timestamps and such things where seconds matter)
datetime is the correct type. And be sure to store it without time zone at time zone UTC:
http://derickrethans.nl/storing-date-time-in-database.html
At your option, use an SQL trigger to round your date to the minute on insert/update. It'll simplify your ruby code.

How would I store a date that can be partial (i.e. just the year, maybe the month too) and output it later with the same specifity?

I want to let users specify a date that may or may not include a day and month (but will have at least the year.) The problem is when it is stored as a datetime in the DB; the missing day/month will be saved as default values and I'll lose the original format and meaning of the date.
My idea was to store the real format in a column as a string in addition to the datetime column. Then I could use the string column whenever I have to display the date and the datetime for everything else. The downside is an extra column for every date column in the table I want to display, and printing localized dates won't be as easy since I can't rely on the datetime value... I'll probably have to parse the string.
I'm hoping I've overlooked something and there might be an easier way.
(Note I'm using Rails if it matters for a solution.)
As proposed by Jhenzie, create a bitmask to show which parts of the date have been specified. 1 = Year, 2 = Month, 4 = Day, 8 = Hour (if you decide to get more specific) and then store that into another field.
The only way that I could think of doing it without requiring extra columns in your table would be to use jhenzie's method of using a bitmask, and then store that bitmask into the seconds part of your datetime column.
in your model only pay attention to the parts you care about. So you can store the entire date in your db, but you coalesce it before displaying it to the user.
The additional column could simple be used for specifying what part of the date time has been specified
1 = day
2 = month
4 = year
so 3 is day and month, 6 is month and year, 7 is all three. its a simple int at that point
If you store a string, don't partially reinvent ISO 8601 standard which covers the case you describe and more:
http://en.wikipedia.org/wiki/ISO_8601
Is it really necessary to store it as a datetime at all ? If not stored it as a string 2008 or 2008-8 or 2008-8-1 - split the string on hyphens when you pull it out and you're able to establish how specific the original input was
I'd probably store the datetime and an additional "precision" column to determine how to output it. For output, the precision column can map to a column that contains the corresponding formatting string ("YYYY-mm", etc) or it can contain the formatting string itself.
I don't know a lot about DB design, but I think a clean way to do it would be with boolean columns indicating if the user has input month and day (one column for each). Then, to save the given date, you would:
Store the date that the user input in a datetime column;
Set the boolean month column if the user has picked a month;
Set the boolean day column if the user has picked a day.
This way you know which parts of the datetime you can trust (i.e. what was input by the user).
Edit: it also would be much easier to understand than having an int field with cryptic values!
The informix database has this facility. When you define a date field you also specify a mask of the desired time & date attributes. Only these fields count when doing comparisons.
With varying levels of specificity, your best bet is to store them as simple nullable ints. Year, Month, Day. You can encapsulate the display logic in your presentation model or a Value Object in your domain.
Built-in time types represent an instant in time. You can use the built in types and create a column for precision (Year, Month, Day, Hour, Etc.) or you can create your own date structure and use nulls (or another invalid value) for empty portions.
For ruby at least - you could use this gem - partial-date
https://github.com/58bits/partial-date

Resources