简体   繁体   English

本月至今的总计

[英]Month-to-date totals

I have an Excel workbook that has several different worksheets in it. 我有一个Excel工作簿,其中有几个不同的工作表。 The one worksheet that contains the main data has 100's of entries. 包含主要数据的一个工作表具有100个条目。 This sheet also gets a new entry every day in the row column. 该表还每天在行列中获得一个新条目。 The first column is the date column that is formatted as date and time. 第一列是日期列,其格式设置为日期和时间。

I need a formula that checks the newest entry's date to see if its month matches the current month and then sums all entries for that month. 我需要一个公式来检查最新条目的日期,以查看其月份是否与当前月份匹配,然后将该月份的所有条目相加。 I know that I am going to use a SUMIF but the hard part is the rest of the formula. 我知道我将使用SUMIF,但困难的部分是公式的其余部分。 I forgot to mention that I need the formula to divide by the number of current month entries used. 我忘了提一下,我需要公式除以使用的当前月份条目数。

Assuming your dates are in A1:A26 and amounts to be summed are in in B1:B26 here is the formula to use. 假设您的日期在A1:A26 ,要累加的金额在B1:B26这是要使用的公式。

=SUMIFS(B1:B26,A1:A26,">="&DATE(YEAR(TODAY()),MONTH(TODAY()),1),A1:A26,"<="&TODAY())

This returns the amounts that are in a date that is greater than or equal to the first day of the current month, AND less than or equal to TODAY. 这将返回在大于或等于当月的第一天小于或等于今天的日期的金额。

There are a couple ways you could do this and I would suggest using sumproduct formula. 您可以通过几种方式执行此操作,我建议使用sumproduct公式。

I'm assuming your data has dates in column A starting in row 2, and a value in column B. 我假设您的数据在A列中的日期从第2行开始,而值在B列中。

In column C you could have a total in each line which is the sum of all rows above the current one that the month matches. 在C列中,您可以在每一行中获得总计,这是该月份匹配的当前行上方所有行的总和。

Formula in C2 would be below which can be carried down C2中的公式将低于该值,可以向下推广

=SUMPRODUCT(--(MONTH(A2)=MONTH($A$2:A2)),$B$2:B2)

Otherwise if you have a single cell and just want to get the latest total this formula would do it. 否则,如果您只有一个单元格,并且只想获取最新总数,则可以使用此公式。 This assumes the latest entry will also be the newest date (highest value) 假设最新条目也将是最新日期(最高值)

=SUMPRODUCT(--(MONTH(MAX(A:A))=MONTH(A2:A1000)),B2:B1000)

In sumproduct the first part of the formula --(A=B) returns true or false values which equate to 1s and 0s. 总和中,公式的第一部分-(A = B)返回true或false值,它们等于1s和0s。 The second part is just your value columns. 第二部分只是您的值列。

The second formula does the same thing but it compares the month of the newest date to all others in the column. 第二个公式执行相同的操作,但是它将最新日期的月份与该列中的所有其他日期进行比较。

Gordon 高登

Since new entries are added daily I am assuming these are in date order ascending, so please try: 由于每天都会添加新条目,因此我假设它们的日期顺序是升序的,所以请尝试:

=SUMIF(A:A,">"&EOMONTH(TODAY(),-1),AD1:AD100)  

or adjust the AD range to suit (could use AD:AD ). 或调整AD范围以适合(可以使用AD:AD )。

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

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