条件付きの前の行値のローリング合計私のデータは、Lot# と Qty の 2 つの列で始まります。
前の行の値のローリング合計 (現在の行 + 前の 2 行) を計算するスクリプトを作成するのに助けが必要です。
ロジックは以下の表のように説明されます。

高度な統計モデリング自動化とスクリプト作成マスカスタマイゼーションRe: 条件付きの前の行の値のローリング合計質問を投稿していただきありがとうございます。 楽しいですが、解決するのは難しい問題でした。
JSL に注釈を追加しました。それが理にかなっていて、単なる巨大な魔法の公式のように見えないことを願っています。
正直なところ、最初は解決するのはほぼ不可能だと思っていましたが、コーヒーをたっぷり飲んだ後は、それほど悪くはありませんでした。
Re: 条件付きの前の行の値のローリング合計ありがとうバイロン。
Re: 条件付きの前の行の値のローリング合計このスクリプトをデータテーブルに追加して試してみましょう
dt1=current data table();
//I want to get the max quantity by lot, so I'm adding a new column to change all the lots back to their non-decimal value.
dt1<< New Column("Lot Actual", formula(If( :Qty == Col Maximum( :Qty, Char( Round( Num( :Lot# ), 0 ) ) ),
:Lot#,
.
)));<BR />//this next formula column excludes rows that aren't the max Qty by lot
dt1<< New Column( "Lot Values in One Formula",
Formula(
If( :Lot Actual == "",
Row State( row() ) = Excluded State( 1 );
Excluded( Row State( row() ) );
1;
)
)
);
dt1<<RUN formulas=""></RUN>//once all the formulas for tagging the data are added, we can use Tabulate to get a subset of just the important rows.<BR />//There are lots of other ways to do this, this just happened to be the method of the day
obj1=dt1 << Tabulate(
Add Table(
Column Table( Analysis Columns( :Qty ) ),
Row Table( Grouping Columns( :Lot# ) )
)
);
dt2=obj1 << Make Into Data Table;
column(dt2,2)<<SET name=""></SET><BR />//Finally here is the rolling sum of the last three lots<BR />//there is moving average function we could have used, it would have looked simpler but more abstract
dt2<<NEW column=""></NEW>//<BR />//This part joins the values from the separate table back to the original table<BR />
dt1 << Update(
With( dt2 ),
Match Columns( :Lot# = :Lot# )
);
close(dt2, nosave);
obj1<<CLOSE window=""></CLOSE>//I feel like this step is cheating a little. This step just repeats the missing values down to the next non-missing<BR />//row. Its some code I got from Brady Brady a ways back. Different iterations of come in handy from time to time.
<BR />dtnr=current data table();
dtcollist=dtnr<<GET column="" names=""></GET>Re: 条件付きの前の行の値のローリング合計はいそうです。
ただし、この結果を得るために一部の行を除外せずに元のデータテーブルを維持したいと考えています。
これはできるでしょうか?
Re: 条件付きの前の行の値のローリング合計これは正しいですか。 (写真の一番右の列)?

Re: 条件付きの前の行の値のローリング合計これを入手する方法を考えてみます。
誰かがこれに対する解決策を持っている場合に備えて、同様に共有してください。
ありがとう。
Re: 条件付きの前の行の値のローリング合計そうですね、分かりました。
各ロットの最大値を見つけて、現在と最後の 2 つの最大ロット値のローリング合計を取得する必要があります。
解決策が隠れているような気がするので、もう少し検討する必要があるかもしれません。
Re: 条件付きの前の行の値のローリング合計数式を使用するというアイデアを証明していただきありがとうございます。
一部のロット データがカウントされていないため、私のデータセットでは式を使用してローリング合計を直接実行できません。
例、
Lot# 3 と Lot# 3.2、Lot# 3.2 数量のみが最終ロット数量であるため、ローリングサムにカウントされます。
Lot#3に追加数量が追加されました。 Lot#3.2になります。
Lot#7、7,2、7,3、Lot#10、10.3も同様です。
ロット番号 7.3 数量と 10.3 は、最終ロット数量であるため、ローリングサムでカウントされます。
コミュニティからの指導が必要です。

Re: 条件付きの前の行の値のローリング合計1 つの方法は、次のような数式を使用することです。

If( Row() == 1,
:Qty,
If( Row() == 2,
Lag( :Qty, 1 ) + :Qty,
:Qty + Lag( :Qty, 1 ) + Lag( :Qty, 2 )
)
)
最初の行には合計するものが何もないため、行 1 のみが使用されます。
2 番目の行には、現在と前の 2 つの値しかないため、その row+lag(1)
2 番目以降のすべての行は、現在の行と前の 2 行の合計をとります:lag(1) と lag(2)