问题
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]
)
回答1:
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.
来源:https://stackoverflow.com/questions/54045506/how-to-create-a-new-column-converting-date-to-text