Datediff with null in Spotfire



我正试图计算两个日期之间的差异,但如果"结束日期"为null,如第二行和第四行,那么我想输入"今天"。。。。数据表是这样的。

Hire Date             Term Date = "end date"          
01/01/2019            05/01/2020
05/04/2018            
09/17/2019            03/18/2020
10/19/2018

我原以为这样的事情会奏效,但事实并非如此。。。

If([Term Date]<>NULL THEN DateDiff("year",[Hire Date],[Term Date])
ELSE  DateDiff("year",[Hire Date],Today())
END 

提前感谢!

您可以使用SN((来代替Null。

DateDiff('year',[Hire Date] ,  SN([TermDate],Today() )   )

或者使用case语句而不是IF,因为IF语句的格式不正确-If(argument, True, False)是正确的格式,但在某些情况下更容易处理案例。

Case when [Term Date] is null then DateDiff("year",[Hire Date],Today()) 
else DateDiff("year",[Hire Date],[Term Date]) 
end 

最新更新