我是Google App Script的新手,请多多包涵。我正在尝试在Google表格中创建自定义功能,以监控每月和每周的销售和费用。我可以使用内置公式来完成此操作,但是每次编辑每个单元格都非常耗时。 Here is what the Google Sheet looks like。
对于月度结算,我使用以下公式(此处为“销售”)。由于存在多个条件(“供应”,“工作人员”或“运营”),因此我将支出SUMIFS
的倍数加起来。
=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
对于每周会计,我在下面使用另一个公式。在这里,我总结了给定日期范围(在Mar 31 2019
至Apr 6 2019
)内的所有交易(此处为“销售”)。如上所述,我使用相同的原则总结“费用”的多个SUMIFS
函数。
销售:=SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Sales")
费用:=SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Supplies")+SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Staff")+SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&date(2019,3,31),'2019'!$A$2:$A,"<="&date(2019,4,6),'2019'!$E$2:$E,"Operations")
如何将上面显示的公式转换为自定义函数?我试图写这样的东西:
答案 0 :(得分:0)
我建议采用另一种策略,该策略应避免使用自定义函数,并允许您使用不带复杂参数的标准函数,并在此过程中实现更合理的数据布局。
=-ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"<>Sales"))
=B3-C3
(销售额减去费用)公式简化
通过披露“开始”和“结束”日期,您可以在SumIFS公式中使用这些日期。
例如,三月周#1:
销售:=-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"Sales")
费用:=SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"<>Sales")
销售: =-ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
费用:=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"<>Sales"))
净额: =B3-C3
第1周结果
销售: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&F3,'2019'!$A$2:$A,"<="&G3,'2019'!$E$2:$E,"Sales")
费用:=SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&F3,'2019'!$A$2:$A,"<="&G3,'2019'!$E$2:$E,"<>Sales")
净额::=H3-I3
Week#2Results
销售: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&K3,'2019'!$A$2:$A,"<="&L3,'2019'!$E$2:$E,"Sales")
费用:=SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&K3,'2019'!$A$2:$A,"<="&L3,'2019'!$E$2:$E,"<>Sales")
净额: =M3-N3
3月第1周从: Mar 1 2019
(唯一手动输入的日期)
3月第1周到: =F3+6
2月3月第2周发件人:=G3+1
3月第2周到: =K3+6
3月第4周#:=U3+6+3
4月第1周来自: =V3+1