Tableau Date function and Y0Y comparsion - date

I have Column that is in String format such as 2018-03 and I want to convert this to Date format in tableau. Once I have convert these 4 years data I want to compare 2019 data with 2018 and 2021 data with 2020s

To convert to a date use the DATE function:
DATE(LEFT([DateField],5)+RIGHT([DateField],2)+"01")
Check here to see 2 different ways to do YoY - do whichever works better for your use case.

Assuming that 03 in your date 2018-03 corresponds to month, you can convert the string column to date column with the following calculation, where my_date is your string column
DATE(DATEPARSE("yyyy-MM", [my_date]))
See the results
Note, if however, 03 is quarter, use this calculation instead
DATE(DATEPARSE("yyyy-qq", [my_date]))

Related

PowerBI Matrix with Year and Month

In the matrix below I have data from Jan 2020-Jan 2021, where the Jan column has the data from both 2021 and 2021. Is there any way to have the matrix add another column for Jan 2021 instead of aggregating that in with the Jan 2020 data?
Chose Year and Month in the date hierarchy column and then in the matrix click "expand all down one level in the hierarchy.
I am new to Power BI and I was wondering recently myself about something similar.
You can create a new column (text format) and combine month and year.
Date
Date Modified
dd-MM-yyyy
yyyy-MM
or
Date
Date Modified
dd-MM-yyyy
yyyy-MM (MMMM)
or
Date
Date Modified
dd-MM-yyyy
yyyy-MM (MMM)
It is not the most elegant solution, it changes a bit what is displayed (not simply months in the headers), it has a few disadvantages but it works.
I would be curious myself whether a better solution exists.
If you click on the date column you are using [InvoiceDate] and select the date option, it will separate out the two date values.
currently it is in a hierarchy showing just the month values but not the actual date
i have this but mine stays summed up at the year level even though the 'month' is expanded under the TimeByDay...
If I take out the year it will provide it like above but combines both... or as is it puts columns in the year

compare extracted date with today() in excel

Column 1 : I have this date-time format in one column = 2018-10-08T04:30:23Z
Column 3 : I extracted date with formula = =LEFT(A11,10) and changed column format to date.
Column 32 : today(). Just to make sure both date columns match
Now when I want to compare both dates
Column 4 : =IF(C11=D11,TRUE(),FALSE())
It does not work. What did I do wrong?
One option using formulas only would be to use Excel's DATE function, which takes three parameters:
=DATE(YEAR, MONTH, DAY)
Use the following formula to extract a date from your timestamp:
=DATE(LEFT(A1,4), MID(A1,6,2), MID(A1,9,2))
This assumes that the timestamp is in cell A1, with the format in your question. Now, comparing this date value against TODAY() should work, if the original timestamp were also from today.
Should be worth trying:
=1*LEFT(A1,10)=TODAY()
May depend upon your configuration. Without format conversion (the 1*) you are trying to compare text (all string functions return Text) with a Number.

how to format date column in kdb

I am newbie to KDB. I have a KDB table which I am querying as:
select[100] from table_name
now this table has got some date columns which have dates stored in this format
yyyy.mm.dd
I wish to query that table and retrieve the date fields in specific format (like mm/dd/yyyy). If this would've been any other RDBMS table this is what i would have done:
select to_date(date_field,'mm/dd/yyyy') from table_name
I need kdb equivalent of above. I've tried my best to go through the kdb docs but unable to find any function / example / syntax to do that.
Thanks in advance!
As Anton said KDB doesn't have an inbuilt way to specify the date format. However you can extract the components of the date individually and rearrange as you wish.
For the example table t with date column:
q)t
date
----------
2008.02.04
2015.01.02
q)update o:{"0"^"/"sv'flip -2 -2 4$'string`mm`dd`year$\:x}date from t
date o
-----------------------
2008.02.04 "02/04/2008"
2015.01.02 "01/02/2015"
From right to left inside the function: we extract the month,day and year components with `mm`dd`year$:x before stringing the result. We then pad the month and day components with a null character (-2 -2 4$') before each and add the "/" formatting ("/"sv'flip). Finally the leading nulls are filled with "0" ("0"^).
Check out this GitHub library for datetime formatting. It supports the excel way of formatting date and time. Though it might not be the right fit for formatting a very large number of objects (but if distinct dates are very less then a keyed table and lj can be used for lookup).
q).dtf.format["mm/dd/yyyy"; 2016.09.23]
"09/23/2016"
q).dtf.format["dd mmmm yyyy"; 2016.09.03] // another example
"03 September 2016"
I don't think KDB has built-in date formatting features.
The most reliable way is to format date by yourself.
For example
t: ([]date: 10?.z.d);
update dateFormatted: {x: "." vs x; x[1],"/",x[2],"/",x[0]} each string date from t
gives
date dateFormatted
------------------------
2012.07.21 "07/21/2012"
2001.05.11 "05/11/2001"
2008.04.25 "04/25/2008"
....
Or, more efficient way to do the same formatting is
update dateFormatted: "/"sv/:("."vs/:string date)[;1 2 0] from t
now qdate is available for datetime parsing and conversion

SAS: Combine YEAR and MONTH data into a single mm/dd/yyyy date without changing types

Question: How do I combine YEAR and MONTH data into a single mm/dd/yyyy date without converting from numeric to character types?
I have date data which needs to be read into SAS. It comes in two columns, YEAR and MONTH. The data looks similar to this:
YEAR MONTH
2012 1
2012 1
2013 10
2012 2
2014 7
The data must be stored in mm/dd/yyyy format. For example, YEAR = 2013 and MONTH = 10 corresponds to 10/01/2013.
I have accomplished this via:
if month = 1 then
date = input(compress("01/01/"||year),mmddyy10.);
else if month = 2 then
date = input(compress("02/01/"||year),mmddyy10.);
...
However, the log gives the following note:
NOTE: Numeric values have been converted to character values at the
places given by:
(Line):(Column).
I understand that this is being done because SAS stores dates as numeric values since January 1, 1960. The Compress function returns a character value. Thus, the numeric data is being coerced into a character type.
While the above code sufficiently solves my problem, the note implies that date formatting should not be handled in this way (via type conversion).
Use the mdy() function:
date = mdy(month, 1, year)

Converting string to date in Crystal Reports

I'm new to Crystal Reports, I'm trying to extract and display month and year from the string (In DB the data type of the column is varchar). Following is an example of the data.
05-JAN-12 11.49.28.000000000 AM
I need it in following format
Jan-12
I have used cDate to convert the string to date format but was unsuccessful, maybe I didn't do it right way.
Alter the formula to extract the date portion, then convert it to a date:
DateValue(Split("05-JAN-12 11.49.28.000000000 AM")[1])
Apply formatting to the field as desired.
This may work
Date (Year ({reportfield}) * 10000 + Month ({reportfield}) * 100 + Day ({reportfield}))
Then format the field to display the date as your choosing.
MonthName(DatePart ("m", <<Date field>>))+"-"+totext(DatePart ("yyyy", <<DAtefield>>),0,"")