我有一个数据库中的数据,当数据被提取时,该数据库为当前月份编号分配一列,然后为前几个月创建单独的列倒计时。 因此,对于从 9 月开始的 24 个月数据提取,将有一列“当前月份”的所有行的值为“9”,然后它将有 24 列带有下标标题“_01”、“_02”、... “_24”,表示“2021 年 8 月”、“2021 年 7 月”、...“2019 年 9 月”。
我使用手动公式输入每个月,但想使用“当前月份”值自动执行此操作。 我不知道如何为月份和年份执行此操作,因为年份会根据当前月份的值而变化。
任何帮助将不胜感激!
这是 24 个月行示例的数据表脚本,其中包含基于当前月份值为 9 月的手动生成的 DateKey 列:
dt=New Table( "Set Month with Key Example",
Add Rows( 24 ),
Compress File When Saved( 1 ),
New Column( "Month",
Character,
"Nominal",
Set Values(
{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}
)
),
New Column( "DateKey",
Character,
Set Values(
{"01082021", "01072021", "01062021", "01052021", "01042021", "01032021", "01022021", "01012021", "01122020", "01112020", "01102020", "01092020", "01082020", "01072020", "01062020", "01052020", "01042020", "01032020", "01022020", "01012020", "01122019", "01112019", "01102019", "01092019"}
)
)
);
<BR />dt:DateKey << Data Type( Numeric, Format( "m/y", 8 ), Input Format( "ddmmyyyy" ) ) <<<BR />Set Modeling Type( "Continuous" ) << Set Field Width( 12 );
CurMonth=9;
莫妮克
这是使用日期增量的一种可能的解决方案。 作为公式完成,但如果要重命名列,则应该很容易在循环中使用:
CurMonth = 9;
currentDate = Date DMY(1, curmonth, Year(Today()));
Date Increment(currentDate, "Month", -1 * Num(:Month), "start");
首先 curMonth 用于生成 currentDate 并假设开始年份与当前年份相同,然后该日期用于 Date Increment 函数。
