I would like to create the following condition on Spotfire :
In english : if the actual date is empty for the last month, then fill in with "empty"
I tried with this but it doesn't work :
if([Actual Date]= NULL, "empty")
I receive this error message :
enter image description here
Thanks for the help :) !
This would work if [Actual Date] is a String; it would create a new column that has the same value as [Actual Date] when this is not null:
if([Actual Date] is NULL, "empty",[Actual Date])
However if [Actual Date] were of type Date or DateTime this method would not work as you would replace a date with a string. So you could insert a special date instead - the value depending on your requirements to handle this date in further analysis
if([Actual Date] is NULL, Date(9999,01,01),[Actual Date])
Related
I'm trying to insert a date into Cassandra based on the current date.
create table mobileTimeSeries (
deviceid text,
date date,
PRIMARY KEY(deviceid, date));
insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()));
That works, but I'm wondering if it's possible to do something like
insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()-1));
insert into mobileTimeSeries (deviceid, date) values ('test', toDate(now()+1));
I just get this error mismatched input '+' expecting ')' (... 'tablet',toDate(now()) [+]...)
Not sure if this is possible at all. Thanks
You can calculate date on your app and just insert it as a date instead of using now().
After CASSANDRA-11936 in 4.0+ you can do now() - 1d kinda things.
I want to add a new column to a source of data.
The new column's value is based on the data of the current row (To Resolved date and From Activated date) as well as data from another query (Calendar). Here is the a screenshot of the source data I am working on:
I am trying to get the number of rows of the other source (Calendar) that are within the range [From Activated date, To Resolved date]. For now, I have this formula for the new column (without the counting yet):
= Table.SelectRows(Calendar, each _[Date] >= [From activated date] and _[Date] <= [To Resolved date])
However, it does not work because Power Query does not find the columns From Activated date and To Resolved date in the Calendar query.
Expression.Error: The field 'From activated date' of the record wasn't
found.
Details:
Date=2017-01-01
Year=2017
MonthNumber=1
MonthName=January
Day=1
Weekday=1
WorkingDays=0
Question
How can I get the current values of From Activated date and To Resolved date for the current row ?
Add another query as a function - in this case, I named it 'CalendarRows':
(StartDate, EndDate) =>
let
Source = Table.RowCount(Table.SelectRows(Calendar, each [Date] >= StartDate and [Date] <= EndDate))
in
Source
Now add a column to your data table, referencing this function:
= Table.AddColumn(#"Previous Step", "Calendar Rows", each CalendarRows([From activated date], [To Resolved date]))
Does anyone know what DAX function I should use to display information from one table in another table.
I've got 2 tables in my data model:
Tasks
- Task ID
- Task Name
- Start Date
- End Date
Fiscal Periods
- ID
- Period Name
- Start Date
- End Date
What I'm trying to do is for each Task, add a calculated column the is populated with the corresponding Fiscal Period ID. I'm trying to add a filter or calculation that specifies:
- if the task start date is between Fiscal Start Date and Fiscal End Date, return the fiscal period id.
Anyone have any ideas?
Thanks,
Ro
This might help:
In case Fiscal Period ID is a number:
=CALCULATE(MAX(Periods[ID]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
In case Fiscal Period ID is not a number:
Put Start Date to calculated column first, say 'Period Start Date'
=CALCULATE(MAX(Periods[Start Date]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
and then use LOOKUPVALUE for ID
=LOOKUPVALUE(Periods[ID],Periods[Start Date],Tasks[Period Start Date])
I'm trying to cast a CHARACTER VARYING column to a DATE but I need a date format like this : DD/MM/YYYY. I use the following SQL query :
ALTER TABLE test
ALTER COLUMN date TYPE DATE using to_date(date, 'DD/MM/YYYY');
The result is a date like this : YYYY-MM-DD.
How can I get the DD/MM/YYYYformat ?
Thanks a lot in advance !
Thomas
A DATE column does not have a format. You cannot specify a format for it.
You can use DateStyle to control how PostgreSQL emits dates, but it's global and a bit limited.
Instead, you should use to_char to format the date when you query it, or format it in the client application. Like:
SELECT to_char("date", 'DD/MM/YYYY') FROM mytable;
e.g.
regress=> SELECT to_char(DATE '2014-04-01', 'DD/MM/YYYY');
to_char
------------
01/04/2014
(1 row)
https://www.postgresql.org/docs/8.4/functions-formatting.html
SELECT to_char(date_field, 'DD/MM/YYYY')
FROM table
The documentation says
The output format of the date/time types can be set to one of the four
styles ISO 8601, SQL (Ingres), traditional POSTGRES (Unix date
format), or German. The default is the ISO format.
So this particular format can be controlled with postgres date time output, eg:
t=# select now();
now
-------------------------------
2017-11-29 09:15:25.348342+00
(1 row)
t=# set datestyle to DMY, SQL;
SET
t=# select now();
now
-------------------------------
29/11/2017 09:15:31.28477 UTC
(1 row)
t=# select now()::date;
now
------------
29/11/2017
(1 row)
Mind that as #Craig mentioned in his answer, changing datestyle will also (and in first turn) change the way postgres parses date.
In case you need to convert the returned date of a select statement to a specific format you may use the following:
select to_char(DATE (*date_you_want_to_select*)::date, 'DD/MM/YYYY') as "Formated Date"
Depends on which type you require as output, but here are 2 quick examples based on an intervals:
SELECT (now() - interval '15 DAY')::date AS order_date -> 2021-07-29
SELECT to_char(now() - interval '15 DAY', 'YYYY-MM-DD') -> 2021-07-29
Let's say your date column is order_date:
SELECT (
RIGHT(order_date, 4)
|| '-'
|| SUBSTRING(order_date, 4, 2)
|| '-'
|| LEFT(order_date, 2)
)::DATE
FROM test
OR
SELECT CAST(
RIGHT(order_date, 4)
|| '-'
|| SUBSTRING(order_date, 4, 2)
|| '-'
|| LEFT(order_date, 2)
AS DATE )
FROM test
What I need is a data item expression which outputs the starting date of the current quarter of last year. Finding the current year is easy, as is subtracting 1 year from that date. But beyond that I get stuck.
I currently have an ugly if expression for each quarter like:
if (extract(month,current_date) in (10,12,12))
then ((extract(year,_add_years (current_date,-1))||'-10-01'))
But no matter what I do I can't concatonate the year and date into string I can convert to a date object. The above code gives the error:
The operation "add" is invalid for the following combination of data types: "integer" and "character"
Trying to cast the integer as a character using cast() I get this error. I also get this error when trying to turn a character array into a date:
The operation "condexp" is invalid for the following combination of data types: "character" and "integer"
Trying to use SQL Server specific functions (it is a SQL Server database) just gives me an error that those functions are unavailable for local processing, so I can't seem to use SS date arithmatic, and I can't find anything particularly applicable in Cognos' built in date functions.
How can I manipulate a date to add a year to a known day/month combination and use that as a date object?
I'm using cognos 10.1.1, but it would work.
You can get the value by using the following code:
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
)
The following is the simple way to get the starting month of the quarter.
(floor((extract(month,current_date)-1)/3)*3+1),
and you can convert timestamp to date or string.
cast(
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
),
date
)
,
cast(
cast(
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
),
date),
varchar(10)
)
plus, you can use extract function when you get a day value.
extract(day, _first_of_month (current_date))
I would go with SQLSERVER built-in functions tht exists in Cognos.
Here is an expression that works for me:
DATEADD({month},(3)*((DATEPART({quarter},[FullDateAlternateKey]))-1),
DATEADD({YEAR}, DATEDIFF({YEAR}, 0, dateadd({year},-1,[FullDateAlternateKey])), 0))
The FullDateAlternateKey field is my date field (from ADVERTUREWORKS DW DB).
If you still have problems, try to isolate the problem by trying this expression on new simple list report.