计数公式希望通过 col 变量创建 3 个 col,以便能够随着变化而向下计数,并从中点向上/向下计数。
自动化和脚本基础数据分析与建模内容组织数据混合和清理回复:计数公式这就是您所寻找的东西吗?
“向下”
Col Cumulative Sum(Row() == Col Min(Row(), :Lot))
“向上”
Col Sum(Row() == Col Min(Row(), :Lot)) - Col Cumulative Sum(Row() == Col Min(Row(), :Lot)) + 1
中间
Col Cumulative Sum(Row() == Col Min(Row(), :Lot)) - Col Sum(Row() == Col Min(Row(), :Lot)) + 1
回复:计数公式如果地块总是连续的,那么 Jarmo 的回答就是正确答案。但是,如果分组列不连续,例如
A
A
A
B
B
A
A
C
C
C
那么提供的公式将不正确。以下是处理不连续分组的替代公式
向下
As Constant( count = 0 );
If( :Lot != Lag( :Lot ),
count
++);
count;
向上
As Constant(
count = 0;
For Each Row( If( :Lot != Lag( :Lot ), count++ ) );
count = count + 1;
);
If( :Lot != Lag( :Lot ),
count
--);
count;
中间
As Constant(
count = 0;
For Each Row( If( :Lot != Lag( :Lot ), count++ ) );
count = count + 1;
count = -1 * Ceiling( count / 2 );
);
If( :Lot != Lag( :Lot ),
count
++);
count;
回复:计数公式你好@DELANDJ1985 ,
我的做法与@jthi和@txnelson略有不同。请参阅附件 jmp 文件,其中我为每个计数方案定义了单独的列公式。我对每个方案都做了略微不同的处理,以便您可以接受这个概念,并可能根据您手头的具体问题对其进行修改。您的查询甚至可能有多个可能的答案!
您不必创建列公式,但可以编写脚本并将其作为脚本运行,这样列就不会被锁定。但是,该细节取决于您的特定场景的需求。
希望这有帮助!,
DS