1 个单元格中的平均每日利润公式

Average profit per day formula in 1 single cell

我想使用这里解释的解决方案:

但只需一个单元格,而不必使用 4 个不同的单元格进行计算。

我想出了这个公式,但在我看来它太复杂且效率低下:

=AVERAGEIF((arrayformula(if((arrayformula(if(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0)<>"", vlookup(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0), {A2:A,C2:C}, 2, false), "")))<>"", (arrayformula(if(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0)<>"", vlookup(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0), {A2:A,C2:C}, 2, false), "")))-QUERY((arrayformula(if(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0)<>"", vlookup(query({A2:A, arrayformula(int(A2:A))}, "select max(Col1) where Col1 is not null group by Col2 label max(Col1) ''", 0), {A2:A,C2:C}, 2, false), ""))), "SELECT * offset 1", 0), "")*-1)),">0")

虚拟文件在这里,公式在D4:

https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing

有什么建议吗?

尝试:

=INDEX(AVERAGE(QUERY(IFNA(QUERY(
 INDEX(SORTN(SORT({INT(A3:A), C3:C}, ROW(A3:A), ), 9^9, 2, 1, 1),,2),  "offset 1", )-
 INDEX(SORTN(SORT({INT(A3:A), C3:C}, ROW(A3:A), ), 9^9, 2, 1, 1),,2)), "offset 1", )))