我已经单独尝试过Num((今天() - I_TRAN_DATE)/ 90 + 1,0)它会返回整数,但是当我尝试将它与pick函数结合使用时似乎无效。我知道它还没有完成,但至少应该返回1-3的结果
pick(
Num((today()-I_TRAN_DATE)/90 + 1,0)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year'
)
答案 0 :(得分:1)
这看起来像是将数字从表达式传递给pick函数的问题。当使用num函数时,这不会改变基础值 - 包括一些括号和round函数根据下面的脚本解决问题,该脚本生成日期列表,然后在最后应用pick函数。
Let varMinDate = Num(31350); //30/10/1985
Let varMaxDate = Num(42400); //31/01/2016
TempCalendar:
LOAD
$(varMinDate) + Iterno()-1 As Num,
Date($(varMinDate) + IterNo() - 1) as TempDate
AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate);
TestCalendar:
Load
TempDate AS I_TRAN_DATE,
week(TempDate) As Week,
Year(TempDate) As Year,
Month(TempDate) As PeriodMonth,
Day(TempDate) As Day,
if(Year2Date(TempDate),1,0) as CurYTDFlag,
if(Year2Date(TempDate,-1),1,0) as LastYTDFlag,
inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12,
date(monthstart(TempDate), 'MMM-YYYY') as MonthYear,
Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear,
WeekDay(TempDate) as WeekDay,
if(TempDate>=MonthStart(AddMonths(Today(),-12)) and(TempDate<=MonthStart(Today())),1,0) as Rolling12Month
,'Q' & Ceil (Month(TempDate)/3) as Quarter
,Year(TempDate)&'-Q' & Ceil (Month(TempDate)/3) as YearQuarter
,if(Year(TempDate)=(Year(Today())-1),1,0) as LastYear
, if(MonthStart(TempDate)=MonthStart(Today()),null(),'Exclude Current Period') As ExcludeCurrentPeriod
Resident TempCalendar
Order By TempDate ASC;
Drop Table TempCalendar;
Let varMinDate = null();
Let varMaxDate = null();
PeriodTable:
Load
Pick(round((num((((today()-I_TRAN_DATE)/90) + 1),0)),1)
,'less than 3 months'
,'3-6 months'
,'6-12 months'
,'greater than 1 year') as Period
,I_TRAN_DATE
Resident TestCalendar;