有条件的前一行值的总和我的数据以两列开始,批号和数量。
我需要帮助来创建脚本来计算前一行值的滚动总和(当前行+前2行)。
逻辑说明如下表所示。

脚本编写回复:带条件的前一行值的总和一种方法是使用如下公式:

If( Row() == 1,
:Qty,
If( Row() == 2,
Lag( :Qty, 1 ) + :Qty,
:Qty + Lag( :Qty, 1 ) + Lag( :Qty, 2 )
)
)
对于第一行,没有什么可累加的,因此仅使用第一行
对于第二行,只有两个值,即当前值和上一个值,因此其row + lag(1)
第二行之后的所有行将取当前行加上前两行的总和:lag(1)和lag(2)
回复:带条件的前一行值的总和感谢您证明使用公式的想法。
我的数据集无法直接使用公式进行累加总和,因为一些手脚数据没有计算在内。
例,
批号3和批号3.2,由于批号为最终批号,因此只有批号3.2数量计入滚动总和。
批号3中增加了额外数量。 成为拍品编号3.2。
批号7、7、2、7、3和批号10、10.3相同。
批号7.3数量和10.3由于是最终批数量而计入滚动总和。
需要社区的指导。

回复:带条件的前一行值的总和是的,我现在明白了。
需要找到每个批次的最大值,然后取当前和最后两个最大批次值的滚动总和。
我觉得有一个潜伏的解决方案,可能需要对此进行更多思考。
回复:带条件的前一行值的总和我会弄清楚如何得到这个。
万一有人对此有解决方案,请也分享。
谢谢。
回复:带条件的前一行值的总和这是正确的吗。 (图片中最右边的列)?

回复:带条件的前一行值的总和是的,这是正确的。
但是我想保持原始数据表而不排除一些行来获得此结果。
能做到吗?
回复:带条件的前一行值的总和将此脚本添加到数据表中并进行旋转
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>