1

在此处输入图像描述这是一年内交易盈亏的示例电子表格。

如果在工作表的日期和工作表上的日期之间没有计数,我正在尝试让I6工作表MONTHLY STATS - SPREADS上的单元格填充 a 。0L1 Mar 2131 Mar 21SPREADS LOG

但我只希望0在 cell 中存在数据时填充它H6。如果没有数据,H6我想I6是空白的。(请注意,我不能使用数字格式将这些0' 隐藏在单元格I6中,因为我I稍后会在工作表中对完整的列进行平均)

虽然它正在执行此单元格,但它还I6必须能够运行下面显示的COUNTIFS&公式。SUM

重要提示:这也必须以相反的方式工作。例如,如果在将数据放入列中后W我希望0在列中填充的日期之间没有's 。WONLOST

这是我目前在单元格中使用的公式I6

=IF(H6="", "",IF(COUNTIFS('SPREADS LOG'!P:P,"L",'SPREADS LOG'!R:R,">="&DATE(2021,3,1),'SPREADS LOG'!R:R,"<="&DATE(2021,3,31)),COUNTIFS('SPREADS LOG'!P:P,"L",'SPREADS LOG'!R:R,">="&DATE(2021,3,1),'SPREADS LOG'!R:R,"<="&DATE(2021,3,31)),"0"))

如果有人可以对此进行调整或建议进行编辑,那就太好了。

4

1 回答 1

2

这是一个公式,可以做你想要的。

细胞H6

=LET(LOSSES,COUNTIFS('SPREADS LOG'!$P:$P,"L",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<="&EDATE($A6,1)),WINS,COUNTIFS('SPREADS LOG'!$P:$P,"W",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1)),IF(AND(LOSSES=0,WINS=0),"",WINS))

细胞I6

=LET(LOSSES,COUNTIFS('SPREADS LOG'!$P:$P,"L",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<="&EDATE($A6,1)),WINS,COUNTIFS('SPREADS LOG'!$P:$P,"W",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1)),IF(AND(LOSSES=0,WINS=0),"",LOSSES))

使用空字符串而""不是0完美地从公式中排除单元格而不破坏它们。SUMCOUNTIFS

请注意,您不能使用其他单元格的值来决定是否填充0值,因为这会创建循环引用。

没有的版本LET

细胞H6

=IF(AND(COUNTIFS('SPREADS LOG'!$P:$P,"L",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1))=0,COUNTIFS('SPREADS LOG'!$P:$P,"W",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1))=0),"",COUNTIFS('SPREADS LOG'!$P:$P,"W",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1)))

细胞I6

=IF(AND(COUNTIFS('SPREADS LOG'!$P:$P,"L",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1))=0,COUNTIFS('SPREADS LOG'!$P:$P,"W",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1))=0),"",COUNTIFS('SPREADS LOG'!$P:$P,"L",'SPREADS LOG'!$R:$R,">="&$A6,'SPREADS LOG'!$R:$R,"<"&EDATE($A6,1)))

这些公式假定您的列中的A日期包含日期值(例如01.03.2021三月)并使用自定义格式设置格式。这使您可以简单地复制整个列的公式,而无需手动更改日期。我强烈推荐这种方法,因为它对您当前的方法没有任何缺点,但是当您将其添加到您的自动化库中时,它可能具有巨大的优势。如果您决定坚持您的方法,则需要更改COUNTIFS.

编辑是因为我误解了问题并提供了不正确的答案。

于 2021-03-30T13:04:43.340 回答