响应时间段数据验证菜单的每日平均利润(不包括当天)
Average of profit per day (excluding present day) responsive to data validation menu for time period
我从这个问题中得到了一个公式:
这让我可以正确计算每天的平均值。
我需要让它响应数据验证菜单,用户可以在其中选择 he/her 需要获取平均值的时间段:过去 24 小时、过去 3 天、过去 7 天、上个月等等。
我还需要能够从平均值计算中排除当天,因为一天的前几个小时总是使平均值下降。
我有这个平均值计算公式,它给出了正确的平均值(除了它不排除今天):
=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", )))
然后我将这个公式作为响应具有时间段的数据验证菜单的平均值的示例。但是对于这个用例,这里的平均值计算是错误的。我不知道如何结合这两种解决方案:
=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)))
这可能吗?有什么建议吗?
我的档案:
https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
使用:
=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", )))
我从这个问题中得到了一个公式:
这让我可以正确计算每天的平均值。 我需要让它响应数据验证菜单,用户可以在其中选择 he/her 需要获取平均值的时间段:过去 24 小时、过去 3 天、过去 7 天、上个月等等。
我还需要能够从平均值计算中排除当天,因为一天的前几个小时总是使平均值下降。
我有这个平均值计算公式,它给出了正确的平均值(除了它不排除今天):
=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", )))
然后我将这个公式作为响应具有时间段的数据验证菜单的平均值的示例。但是对于这个用例,这里的平均值计算是错误的。我不知道如何结合这两种解决方案:
=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)))
这可能吗?有什么建议吗?
我的档案: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing
使用:
=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", )))