I need to create a new column with an IF.
If the difference between two dates is more than a month I have to use a text-like "much time" but if it is not I have to show a date.
So the date must be converted to a string to use a text column.
How can I convert date to text?
Fecha_real =
IF( DATEDIFF(ventas[fecha_pedido]; ventas[fecha]; month) = 1 ;
"much time";
ConvertToTextInSomeWay ventas[fecha]
)
This is pretty simple with the FORMAT function.. For example, FORMAT(ventas[fecha], "Short Date") will convert fecha into textlike "12/31/2018".
That's just one format example. There are plenty of pre-defined and custom options if you'd rather something else. For example, FORMAT(ventas[fecha], "dd-mm-yyyy") would format that same date as "31-12-2018" instead.
Related
I'm trying to create a new custom column from a conditional statement and current date.
Next picture explains exactly what i need to get with power query.
An example of what I need from pseudocode is:
if [fecha fin de plazo]>=CurrentDate and [fecha CIERRE investigación]=null
then "string"
My biggest problem is I don't know how to extract the current date with PowerQuery.
You could try using,
if [fecha fin de plazo]>= DateTime.LocalNow() and [fecha CIERRE investigación]=null
then "string"
DateTime.LocalNow()
Using the DateTime.LocalNow you get the date and time of your system, the problem is at time to compareting the date value with the result of DateTime.LocalNow() becsause you need to compare only dates.
That's why It must use DateTime.Date. This fucntion returns the date component of DateTime.LocalNow().
if [date1] >= DateTime.Date(DateTime.LocalNow()) and [date2]=null
then "string"
You can get more information about this functions here:
DateTime.LocalNow()DateTime.Date()
I had a problem with my code. It returns the below error:
DAX comparison operates do not support comparing values of type date with values of type text.
Basically, I want to count rows based on some conditions. And I know there is a need to convert the data type, but I am not sure how to do it.
Total Open Issues =
--------------------
--basic info
VAR SELECTEDDATE =
DATEVALUE(SELECTEDVALUE(Calender[FullDateAlternateKey].[Date]))
--------------------
--FIND the relvent data
VAR rlvttable =
calculatetable(
Tracker,
Tracker[Catagory]="ISSUE",
DATEVALUE(Tracker[ClosedDate])>SELECTEDDATE
||Tracker[ClosedDate]=""
)
--------------------
--Results
Return
countrows(rlvttable)
Anyone could advise me how to correct it? Thanks~
Check the data type of columns Tracker[ClosedDate] and Calender[FullDateAlternateKey] - one of them is Text, rather than Date.
To fix, you could:
choose a different field which is already a Date format
change the format of the offending column
use DATEVALUE in your measure, to convert the text date to a real date.
It also looks like you need to edit this statement, as these conditions conflict:
Tracker[ClosedDate]>SELECTEDDATE
&&Tracker[ClosedDate]=""
I am trying to compare the closedDate with "". I should use blank() instead.
I'm having trouble calling a date within an if statement. My date is, for example, "2001-08-05". I am trying to subset my data based on the date. So this is my code:
If ID = "Yes" and Date > 2001-08-05 then delete;
But this just doesn't do what I'm asking. I don't get an error, but it doesn't perform what I ask. I tried "2001-08-05"d. as well but this produced an error. Is there a certain way to read this format?
The proper format for a date constant in SAS is 'ddmmmyyyy'd, so:
if ID = 'Yes' and Date > '05Aug2001'd
You can use either single or double quotes to delimit the constant. The month name in the constant is case insensitive.
On a side-note, if you need to do a date-time constant in SAS, the format is 'ddmmmyyyy:hh:mm:ss'dt. Notice the suffix becomes dt rather than just d and there is a semi-colon between the date and time.
Or you could try to covert character to date
If ID = "Yes" and Date > input('2001-08-05',yymmdd10.) then delete;
I have a big table in SQLite with a field for dates (varchar type) with a following format dd-mm-yyyy hh:mm (i.e. 01-01-2014 01:20) and I need to transform them into the following format dd-mm-yyyy, hh:mm (adding a comma after year i.e. 01-01-2014, 01:20)
How can I do this? Does it exist any way with date formatter or using regexp in SQLite?
You simply want to insert something after the tenth character.
Use the substr function for this:
UPDATE BigTable SET AField = substr(AField, 1, 10) || ',' || substr(AField, 11)
I am using the DateFormat function to convert dates to this format: yyyy-mm-dd. This is the original format of the date: dd-mm-yyyy. Below is a snippet of the code:
<cfset newdate = #DateFormat(Trim(mydate), "yyyy-mm-dd")# />
The problem is that I get different results for different dates. For example:
If my original date is: 15-05-2013 (dd-mm-yyyy)
The result is: 2013-05-15 (yyyy-mm-dd)
However, if I change the input and:
The original date is: 01-05-2013 (dd-mm-yyyy)
The result is: 2013-01-05 (yyyy-dd-mm)
Any help or guidance as to what is wrong would be highly appreciated.
I disagree with the other answer. The real cause of the problem is that DateFormat is not designed to handle non-US date strings.
The standard CF date functions always use U.S. date parsing rules. That means when you pass in an ambiguous date string, like 01-05-2013, it is parsed according to U.S. English date conventions. In this case, month first ie "mm-dd-yyyy". So the result will always be January 5th, not May 1st.
In some cases you get lucky. With the string 15-05-2013, there is obviously no 15th month, so CF/java must swap the month and day automatically, rather than throwing an error. That is why it seems to handle some dd-mm-yyyy date strings correctly, but not others.
If you want to parse non-US date strings, you should use the LS (Locale Sensitive) date functions instead. However, according to the docs dashes ie "-" are not a standard date separator in most non-US locales: only Dutch and Portuguese (Standard). So you would either need to change the separator OR use one of those two locales when parsing the date:
lsDateFormat( myDate, "yyyy-mm-dd", "pt_PT")
Side note:
As an aside, DateFormat does expect a date object. However, like most functions in CF it is flexible enough to accept a date string as well. That allows you to use it as a lazy shortcut to convert from date string => date object => then back to (formatted) date string again. Using date objects is preferable (and you really should validate date strings as well) but that is another conversation altogether ...
The problem is that DateFormat expects a date object, and returns a string.
You're passing it a string, not a date. What you want to do is firstly turn your string (of 01-05-2013 etc) into a date object.
To do this I'd recommend using either ParseDateTime or LSParseDateTime, and/or LSDateFormat.
e.g.
<cfset originalDateString = "01-05-2013">
<!--- turn that into a Date --->
<cfset dateObject = ParseDateTime(originalDateString)>
<cfset newdateString = DateFormat(dateObject, "yyyy-mm-dd")>
Alternatively, if you know your string is always in a dd-mm-yyyy format, you could parse the string yourself, e.g. treat it as a list delimited by hyphens.
<cfset dd = listFirst(originalDateString, "-")>
<cfset mm = listGetAt(originalDateString, 2, "-")>
<cfset yy = listLast(originalDateString, "-")>