简体   繁体   English

Google表格会计脚本

[英]Google Sheets Script for Accounting

I'm very new to Google App Script so please bear with me. 我是Google App Script的新手,所以请耐心等待。 I'm trying to create custom functions in Google Sheets to monitor monthly and weekly sales and expenses. 我正在尝试在Google表格中创建自定义功能,以监控每月和每周的销售和费用。 I can do it with built-in formulas, but it's too time-consuming to edit every cell every time. 我可以使用内置公式来完成它,但每次编辑每个单元格都太费时了。 Here is what the Google Sheet looks like . 以下是Google表格的样子

For monthly accounting, I use the formula below (here it's for "Sales"). 对于月度会计,我使用下面的公式(这里是“销售”)。 I use the sum of multiple SUMIFS for the expenses since there are multiple criteria ("Supplies", "Staff", or "Operations"). 我使用多个SUMIFS的总和作为费用,因为有多个标准(“供应”,“员工”或“操作”)。

=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))

For weekly accounting, I use another formula below. 对于每周会计,我使用下面的另一个公式。 Here, I sum up all transactions (here "Sales") within a given range of dates (here Mar 31 2019 to Apr 6 2019 ). 在这里,我总结了给定日期范围内的所有交易(此处为“销售”)(此处为Mar 31 2019 Apr 6 2019 )。 As in above, I use the same principle of summing up multiple SUMIFS functions for "Expenses". 如上所述,我使用相同的原则来为“费用”总结多个SUMIFS函数。

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,"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,"Sales")

Expenses: =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") 费用: =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")

How can I translate the formulas shown above into a custom function? 如何将上面显示的公式转换为自定义函数? I was trying to write something like this one: 我试着写这样的东西:

在此输入图像描述

I suggest a different strategy that avoids custom functions and allows you to use standard functions without complex parameters and, in the process, achieves a more logical layout of the data. 我建议采用不同的策略来避免自定义函数,并允许您使用没有复杂参数的标准函数,并在此过程中实现更合理的数据布局。

  • 2019 Sheet: Category (Column E): make these a dropdown selection to avoid typos and other errors. 2019工作表:类别(E列):使这些选项成为选择,以避免拼写错误和其他错误。
  • 2019 Sheet: Column F - It's not clear whether sales should be normally negative (credit), or expenses should be normally positive (debit). 2019表:F栏 - 目前尚不清楚销售是否通常为负(信用),或者费用通常是正数(借方)。 Either way, the sum of this column will reconcile to something at some stage so the "sign" of transactions is important. 无论哪种方式,此列的总和将在某个阶段与某些东西协调,因此交易的“符号”很重要。 It also means that formulas for Sales on the Summary Sheet should be prefixed with a negative (so that they appear as a positive number). 这也意味着汇总表上的销售公式应该以负数为前缀(以便它们显示为正数)。
  • Summary Sheet-Monthly Sales - Prefix with a "minus" so that sales are shown as positive. 摘要表 - 每月销售额 - 带有“减号”的前缀,以便销售显示为正数。 =-ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"Sales"))
  • **Summary Sheet: Monthly Expenses"" - Simplify the formula: just sum the values that are NOT "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"))的值=ARRAYFORMULA(SUMIFS('2019'!$F$2:$F,text('2019'!$A$2:$A,"MMM"),A3,'2019'!$E$2:$E,"<>Sales"))
  • Summary Sheet: Net - =B3-C3 (Sales minus Expenses) 汇总表:净额 - =B3-C3 (销售额减去费用)
  • Summary Sheet: Weekly reporting - It is always difficult to balance monthly results against weekly results. 摘要表:每周报告 - 总是很难平衡每月结果与每周结果。 So much so, that many business adopt a quarterly cycle of 4/4/5 weeks to cater for the changes in the number of days per month. 因此,许多企业采用4/4/5周的季度周期来满足每月天数的变化。 In any event, the formula that you are using is VERY complicated and prone to error through typos (if nothing else). 无论如何,你使用的公式非常复杂,并且通过拼写错误容易出错(如果没有别的话)。 I suggest: 我建议:
  • create columns for the respective weekly "From"/"To" dates on the weekly report, and use date arithmetic to calculate the respective dates for each new week/month. 为每周报告中的相应每周“从”/“到”日期创建列,并使用日期算法计算每个新周/月的相应日期。
  • use Weekly Sales and Expenses formula that reference the "From/To" dates. 使用引用“从/到”日期的每周销售和费用公式。 This makes your formulas completely generic, enables you to copy formula with conventional "Copy/Paste" commands, and doesn't require detailed formula editing. 这使您的公式完全通用,使您能够使用传统的“复制/粘贴”命令复制公式, 并且不需要详细的公式编辑。
  • Consider whether you want the weekly results to align to the monthly results. 考虑您是否希望每周结果与月度结果一致。 If you do, then 如果你这样做的话
    • fine-tune the month-end by adding or deleting days to the "To" date in week#4. 通过在第4周的“收件人”日期添加或删除天数来微调月末。 The Week#1 "From" date for the following month will adjust automatically, as will the respective "From"/"To" dates for the other weeks in the following month(s). 下个月的第1周“自”日期将自动调整,以及下个月其他周的相应“起始”/“至”日期也将自动调整。 This will help eliminate unintentional errors such as including March 31 in both March week#4 and April week#1. 这将有助于消除无意识错误,例如包括3月31日和4月的第3周。
    • You might also add an extra three columns at the right to sum Total Sales, Total Expenses and Net profit for the four weeks. 您还可以在右侧添加额外的三列,以总计四周的总销售额,总费用和净利润。 This figure will agree to the monthly result. 该数字将与月度结果一致。

Formula simplification 公式简化

By disclosing the From and To dates, you can use those dates in your SumIFS formula. 通过公开From和To日期,您可以在SumIFS公式中使用这些日期。 For example, March Week#1: 例如,March Week#1:
Sales: =-SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"Sales") Expenses: =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")费用: =SUMIFS('2019'!$F$2:$F,'2019'!$A$2:$A,">="&G3,'2019'!$A$2:$A,"<="&H3,'2019'!$E$2:$E,"<>Sales")


Monthly Results 每月结果
每月结果

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"))
Expenses: =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"))
Net: =B3-C3 净: =B3-C3


Weekly results - extract 每周结果 - 提取
每周结果(摘录)

Week#1 Results 第1周结果
Sales: =-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")
Expenses: =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")
Net: =H3-I3 净: =H3-I3
Week#2Results 周#2结果
Sales: =-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")
Expenses: =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")
Net: =M3-N3 净: =M3-N3


Date Arithmetic 日期算术 全周结果

March Week#1 From: Mar 1 2019 (the only date that is entered manually) 3月第1周自: Mar 1 2019 (手动输入的唯一日期)
March Week#1 To: =F3+6 3月第1周至: =F3+6
March Week#2 From: =G3+1 3月周#2来自: =G3+1
March Week#2 To: =K3+6 3月第2周至: =K3+6
March Week#4 To: =U3+6+3 3月第4周到: =U3+6+3
April Week#1 From: =V3+1 四月第1周来自: =V3+1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM