我有一個數據庫中的數據,當數據被提取時,該數據庫為當前月份編號分配一列,然後為前幾個月創建單獨的列倒計時。 因此,對於從 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 函數。
