[英]Average of profit per day (excluding present day) responsive to data validation menu for time period
I have a formula taken from this question: Average profit per day formula in 1 single cell我有一个取自这个问题的公式: Average Profit per day formula in 1 single cell
Which gives me the correct calculation for average value per day.这给了我每天平均值的正确计算。 I need to make it responsive to a data validation menu where the user can choose the time period for which he/her needs to get the average from: last 24h, last 3 days, last 7 days, last month and so on.我需要让它响应数据验证菜单,用户可以在其中选择他/她需要从中获取平均值的时间段:过去 24 小时、过去 3 天、过去 7 天、上个月等等。
I also need to be able to exclude the present day from the average calculation because the first few hours of the day always make the average go down.我还需要能够从平均值计算中排除今天,因为一天中的前几个小时总是使平均值下降。
I have this formula for the average calculation which gives me the correct average (except that it is not excluding the present day):我有这个平均值计算公式,它给了我正确的平均值(除了它不排除今天):
=INDEX(AVERAGE(QUERY(IFNA(QUERY(
INDEX(SORTN(SORT({INT(B3:B), D3:D}, ROW(B3:B), ), 9^9, 2, 1, 1),,2), "offset 1", )-
INDEX(SORTN(SORT({INT(B3:B), D3:D}, ROW(B3:B), ), 9^9, 2, 1, 1),,2)), "offset 1", )))
Then I have this formula as an example of an average that is responsive to a data validation menu with the time period.然后,我将这个公式作为响应具有时间段的数据验证菜单的平均值的示例。 But here the calculation for the average is wrong for this use case.但是这里的平均值计算对于这个用例是错误的。 I can't figure out how to combine the 2 solutions:我不知道如何结合这两种解决方案:
=ARRAYFORMULA( AVERAGE(QUERY({IFERROR(DATEVALUE(B3:B)),D3:D},
"select Col2
where Col2 is not null
and Col1 <= "&INT(MAX(B3:B))&"
and Col1 > "&INT(MAX(B3:B))-(
IFERROR(
VLOOKUP(
SUBSTITUTE(F2," ",""),
{"24HOURS",1;
"2DAYS",2;
"3DAYS",3;
"7DAYS",7;
"2WEEKS",14;
"1MONTH",30;
"3MONTHS",90;
"6MONTHS",180;
"1YEAR",365;
"2YEARS",730;
"3YEARS",1095},
2,FALSE))
)-1, 0)))
Is such a thing possible?这样的事情可能吗? Any suggestions?有什么建议么?
My file: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing我的文件: https ://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
use:利用:
=INDEX(AVERAGE(QUERY(IFNA(QUERY(
INDEX(SORTN(QUERY(SORT({INT(B3:B), D3:D}, ROW(B3:B), ), "where Col1 <> "&TODAY()&"and Col1 >= "&TODAY()-VLOOKUP(SUBSTITUTE(F2, " ", ),
{"24HOURS",1; "2DAYS",2; "3DAYS",3; "7DAYS",7; "2WEEKS",14; "1MONTH",30; "3MONTHS",90; "6MONTHS",180; "1YEAR",365; "2YEARS",730; "3YEARS",1095}, 2, )), 9^9, 2, 1, 1),,2), "offset 1", )-
INDEX(SORTN(QUERY(SORT({INT(B3:B), D3:D}, ROW(B3:B), ), "where Col1 <> "&TODAY()&"and Col1 >= "&TODAY()-VLOOKUP(SUBSTITUTE(F2, " ", ),
{"24HOURS",1; "2DAYS",2; "3DAYS",3; "7DAYS",7; "2WEEKS",14; "1MONTH",30; "3MONTHS",90; "6MONTHS",180; "1YEAR",365; "2YEARS",730; "3YEARS",1095}, 2, )), 9^9, 2, 1, 1),,2)), "offset 1", )))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.