How to convert a field with 202008 to a date in Tableau - tableau-api

I am trying to convert a field that contains strings such as 202008, 202108 to a date field. I have tried the date() function, clicking on the measure and converting it to a date. I have also tried DATE(LEFT([Month],4)+"-"+RIGHT([Month],2)+"-01") but that will only return the year.

Using Tableau Desktop 2021.1, when I change the data type from String to Date, Tableau translates the strings to 8/1/2020 and 8/1/2021. If you are using an earlier version of Desktop, it is possible that this functionality is not present.
However, if changing the data type isn't working for you, the calculated field code you provided should actually work, you just need to change the date part from Year to Month/Day/Year using the Custom date part option.

Related

Converting number to date format using Power Query Editor

I need help to convert Numbers into date format using Power Query Editor in either Excel or PowerBI
The date appears in number form like this 930101 and I want to convert it to normal Uk date format
Not sure which one is month and which one is date among "0101" in your string. But you can handle this your self and follow this below steps for get your required output in Power Query Editor-
First, split your string value using fixed 2 character and your data will be divide into 3 column now. define which one is Year, Month and Day.
Now, merge those 3 column maintain the UK pattern DD/MM/YY using a separator "/" and you will get a string like "01/01/93".
Finally, create a custom column using the below code-
Date.From([Merged],"en-GB")
Here is the final output-
In the above image, you can see the date in still US format just because of my Laptop's locally setup.

Tableau Dashboard Default set to Yesterday by using Date Parameter

I have created daily dashboard which shows the data for single date selected from DATE PARAMETER (with ALL value). Which is OK for me that I can see the data for any date I want.
But the problem is when I open my dashboard it is showing data for date which I selected in date parameter while publishing the Dashboard to Server/Online and Instead of that I want set it default to Yesterday.
i.e. when I open my dashboard first time it should show yesterday's data and also there should option to change date as well to see another date data.
Can we achieve this using DATE PARAMETER (with ALL values)? If it is not possible then is there any other way?
Please Help!
Use a relative date filter instead of a parameter. Just be sure to save and publish the workbook with Yesterday as the relative date value.
1, Create a calculation field d_yesterday, formula is TODAY()-1
2, Create a parameter, data type is Date, value when workbook opens set to d_yesterday
3, use the Date parameter in other calculations fields, or insert parameter into custom SQL query.

Tableau String to Date Time Format Issues

I am pulling in date information via MySQL and the date is in the string format of "MM/dd/YY hh:mm:ss"
Using the built in conversion to date isnt working; so I tried using DATEPARSE and also using DATE and manually parsing it. I have had no luck and I have no idea why I keep getting "null" as the answer or it is putting the month as year, day as month, and year as day.
See screenshots below for the different formulas I have used:
DATEPARSE
Original date format
DATE with manual parsing
This worked for me using your example original data
DATEPARSE('mm/dd/yy hh:mm:ss',[Time] )
I used tableau's documentation of custom date formats to find the right formula for the format.
If this doesn't solve the problem then it is most likely due to a Locale issue. The Dateparse function relies on the locale specified by your computer settings to interpret and then display the strings you want to convert and can affect whether a certain format can be specified. This means that if a certain format is not recognised it will return a null. This will often occur is the windows region and language format is changed to another language other than the original language the workbook was created it.
So check your locale and if required execute the following workaround (documented by tableau here):
Open Windows control panel > region and language > format
Click format dropdown and change to original language of workbook creation
click ok or apply and reopen tableau work book

Converting datenum field as a date field in jasper domain

I'm trying to create a calculated field in a jasper domain which is a value of field is Datenum. I need to convert that datenum into a date format (1/1/16 or like this) while creating the calculated field.
I have tried by only changing the datatype from number to date. but it only gives something like this(1/1/70). I have attached screenshots below.
Are there any way to use this field as date field.
Conversion
First, you are not using any function to tell Jasper that you need a date. You have only set the data type to date. Since Java date began counting at 01.01.1970 this is the date you get.
The calculated field doesn't know how to interpret your data in the format 20160101. It is possible to use a DomEL function called date in the expression which interprets a date in ANSI format:
date('2016-01-01')
Nonetheless the format of the field SUBMITDATENUM is different. The date function will not be able to interpret this. Unfortunately I am not aware if it is possible to provide a format in which the data is interpreted.
Datebase options
If you can change the format of the table structure, simply add another field or change the data format of the field (if feasible). Otherwise, you could add a database view which converts the field into a "real" date field.
This is the solution I would go for.
More options
There might be a possibility in version 6 with Groovy since it can be used inline:
<field id="e.groovyEval" dataSetExpression="groovy('(5.0/6).toString()')" type="java.lang.String" />
So with the correct Groovy function (which I haven't used yet - I don't know if variables can be inserted) this could help:
<field id="e.groovyDate" dataSetExpression="groovy('Date.parse(\'yyyyMMdd\', ASASMARTLAYER_PHWORDERSPAN.SUBMITDATENUM)')" type="java.lang.Date" />

GWT to get value from date field

I am using GWT ext and trying to get the values from page and setting it in pojo class.
Except date field all the values are obtained using
(TimeField) ComponentMgr.getComponent(id[2])).getText())....
But while using the same snippet for date field it fails to perform.
Can any one help me with this issue please......
This works fine for me:
dateField.getText();
If you want to convert a string to a date field, you'll have to parse it. Bear in mind that there are already out-of-the-box date pickers in GWT 1.6. If you're using a version that does not come with date pickers, there are several projects like this.
I have also used date field many times.
DateField field = new DateField();
field.getValue();
This will return value as Date instance.So If your pojo has date property then you need to parse it.
For the string value you should go for getText() method.