如何计算一列连续减少值的次数
How do I count the number of times a column consecutively decreases in value
我有一个分布sheet,其中一列包含一个人的体重。我想计算他们的体重在当前体重和所有时间的连续条目中连续减少了多少次,所以:
108
107
106
105
104
106
104
103
应该return3因为最后连减3次,也应该5因为开始连减5次。这些值在 sheet 中的一列而不是一行中。我该怎么做?
粘贴到 D2 单元格:
=ARRAYFORMULA(IF(LEN({A2; A2:A}), IF(B2:B901 < {1000; B2:B900}, 1, ), ))
粘贴到 E2 单元格:
=ARRAYFORMULA(IF(D2:D901=1,
MMULT(N(ROW(D2:D901)>=TRANSPOSE(ROW(D2:D901))), N(D2:D901=1))-HLOOKUP(0,
MMULT(N(ROW(D2:D901)> TRANSPOSE(ROW(D2:D901))), N(D2:D901=1)), MATCH(
VLOOKUP(ROW(D2:D901), IF(N(D2:D901<>D1:D900), ROW(D2:D901), ), 1, 1),
VLOOKUP(ROW(D2:D901), IF(N(D2:D901<>D1:D900), ROW(D2:D901), ), 1, 1), 0), 0), ))
并确保您的 sheet 至少有 901 行
我设法在没有帮助列的情况下完成了当前的连胜,它还计算了连胜持续的天数(这不是我要求的,但对我来说更好)。不确定在这里回答我自己的问题是否是正确的回答,我对这个网站没有经验。
=iferror(sum(query(query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), true),TRUE ), )), Log!B2:B}, "select * where Col1 is not null order by Col1 desc limit " & match(False, query(query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), true),TRUE ), )), Log!B2:B}, "select * where Col1 is not null order by Col1 desc"), "select Col3"), 0)-1), "select Col2")), 0)
并计算最大连胜:
=max(transpose(index(query({0}, "select " & join(",", unique(transpose(split(substitute(join(" + ", query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1,), Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ), 0),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), false),false ), )), Log!B2:B}, "select Col2 where Col1 is not null order by Col1 desc")), " + 0 + ", ","), ","))))), 2)))
我有一个分布sheet,其中一列包含一个人的体重。我想计算他们的体重在当前体重和所有时间的连续条目中连续减少了多少次,所以:
108
107
106
105
104
106
104
103
应该return3因为最后连减3次,也应该5因为开始连减5次。这些值在 sheet 中的一列而不是一行中。我该怎么做?
粘贴到 D2 单元格:
=ARRAYFORMULA(IF(LEN({A2; A2:A}), IF(B2:B901 < {1000; B2:B900}, 1, ), ))
粘贴到 E2 单元格:
=ARRAYFORMULA(IF(D2:D901=1,
MMULT(N(ROW(D2:D901)>=TRANSPOSE(ROW(D2:D901))), N(D2:D901=1))-HLOOKUP(0,
MMULT(N(ROW(D2:D901)> TRANSPOSE(ROW(D2:D901))), N(D2:D901=1)), MATCH(
VLOOKUP(ROW(D2:D901), IF(N(D2:D901<>D1:D900), ROW(D2:D901), ), 1, 1),
VLOOKUP(ROW(D2:D901), IF(N(D2:D901<>D1:D900), ROW(D2:D901), ), 1, 1), 0), 0), ))
并确保您的 sheet 至少有 901 行
我设法在没有帮助列的情况下完成了当前的连胜,它还计算了连胜持续的天数(这不是我要求的,但对我来说更好)。不确定在这里回答我自己的问题是否是正确的回答,我对这个网站没有经验。
=iferror(sum(query(query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), true),TRUE ), )), Log!B2:B}, "select * where Col1 is not null order by Col1 desc limit " & match(False, query(query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), true),TRUE ), )), Log!B2:B}, "select * where Col1 is not null order by Col1 desc"), "select Col3"), 0)-1), "select Col2")), 0)
并计算最大连胜:
=max(transpose(index(query({0}, "select " & join(",", unique(transpose(split(substitute(join(" + ", query({Log!A2:A, ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1,), Log!A2:A - offset(Log!A2:A, -1,,counta(Log!A2:A)+1 ), 0),0 ), )), ArrayFormula(if(len(Log!A2:A), if(row(Log!A2:A) > 2, if(len(Log!B2:B), Log!B2:B < offset(Log!B2:B, -1,,counta(Log!B2:B)+1 ), false),false ), )), Log!B2:B}, "select Col2 where Col1 is not null order by Col1 desc")), " + 0 + ", ","), ","))))), 2)))