Return Latest Month Value

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
922
Office Version
  1. 365
Hi,

I have the following tables;

Book1
CDEFGHIJKLMNOPQR
2Table 1Table 2Tuesday, 31 January, 2023
3BranchJanFebMarAprMayJunJulAugSepOctNovDecBranchSales
4Texas300Texas100
5New York300New York100
6Chicago300Chicago100
7Total900Texas100
8New York100
9Chicago100
10Texas100
11Table 3New York100
12Total900Chicago100
Sheet1
Cell Formulas
RangeFormula
D4:D6D4=SUMIF($Q4:$Q12,C4,R4:R12)
D7D7=SUM(D4:D6)
D12D12=LOOKUP(2,1/(D7:O7>0),D7:O7)


Table 2 has the raw data. This data is updated daily.
Table 1 is the summary from Table 2

In Table 3, I am trying to take the total for the latest date. Example if today is Jan 31, then the total will show 900. However, when the date changes to Feb 1 2023 in cell R2,, the total in Table 1 which is based from Table 2 will change as well. Assuming today is Feb 1 2023, an example of the new tables will look as below:

Book1
CDEFGHIJKLMNOPQR
2Table 1Table 2Tuesday, 31 January, 2023
3BranchJanFebMarAprMayJunJulAugSepOctNovDecBranchSales
4Texas300700Texas100
5New York300300New York100
6Chicago300300Chicago100
7Total9001300Texas500
8New York100
9Chicago100
10Texas100
11Table 3New York100
12Total1300Chicago100
Sheet1
Cell Formulas
RangeFormula
D7:E7D7=SUM(D4:D6)
D12D12=LOOKUP(2,1/(D7:O7>0),D7:O7)


Is there a way to build a formula in Table 1 that takes the sum from Table 2 only for the respective months based on the dates in cell R2 and the figures in Table 2?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Not getting your requirement, can you please explain further, you are getting data for Feb in your example, now what do you want?
 
Upvote 0
Yes, you can use the SUMIFS function to sum the values in Table 2 based on the respective months in the dates column (assuming the dates are in column Q). Here's an example formula you can use in Table 1:

=SUMIFS(Table2[Value],MONTH(Table2[Date]),MONTH(R2),YEAR(Table2[Date]),YEAR(R2))

In this formula, "Table2[Value]" refers to the column in Table 2 containing the values you want to sum, and "Table2[Date]" refers to the column containing the dates.

The MONTH function extracts the month from the dates in the Table 2 date column, and the YEAR function extracts the year. These values are then compared to the month and year in cell R2 using the SUMIFS function, which only adds up the values in Table 2 that meet both criteria.

Note that you'll need to adjust the ranges and column names in this formula to match your specific table layout.
 
Upvote 0
Try

Book5
ABCDEFGHIJKLMNOPQRS
1
2Table 1Table 22/28/2023
3BranchJanFebMarAprMayJunJulAugSepOctNovDecBranchSales
4Texas07000000000000Texas100
5New York03000000000000New York100
6Chicago03000000000000Chicago100
7Total013000000000000Texas500
8New York100
9Chicago100
10Texas100
11Table 3New York100
12Total1300Chicago100
13
14
15
16
17
Sheet1
Cell Formulas
RangeFormula
D4:O6D4=SUMPRODUCT($R$4:$R$12*(MONTH($R$2)=MONTH(D$3&1)*($Q$4:$Q$12=$C4)))
D7:O7D7=SUM(D4:D6)
D12D12=LOOKUP(2,1/(MONTH($R$2)=MONTH(D3:O3&1)),D7:O7)
 
Upvote 0
Hi Sufian and excel_learnerz

Thank you and appreciate it.

The data is updated daily from 1 Jan to 31 Dec. Is there a way the formula could retain the previous month data when the dates cross over to the next month?
 
Upvote 0
I only know one way to do it to keep monthly columns in table 2.
I don't have any other idea to do it with formula.
Hope someone else can help you in this matter.
Good luck.
 
Upvote 0
you can modify the formula to retain the previous month's data even when the dates cross over to the next month. To do this, you can use an IF statement to check whether the date in cell R2 is the first day of a month. If it is, the formula will sum the data for the previous month. If it's not, the formula will sum the data for the current month.

Here's the modified formula:

=IF(DAY(R2)=1, SUMIFS(Table2[Value], MONTH(Table2[Date]), MONTH(R2)-1, YEAR(Table2[Date]), IF(MONTH(R2)=1, YEAR(R2)-1, YEAR(R2))), SUMIFS(Table2[Value], MONTH(Table2[Date]), MONTH(R2), YEAR(Table2[Date]), YEAR(R2)) )

This formula checks if the day of the date in cell R2 is the first day of the month using the DAY function. If it is, the formula calculates the sum for the previous month using SUMIFS. If the month is January (MONTH(R2)=1), it also adjusts the year to the previous year. If the day is not the first day of the month, the formula calculates the sum for the current month as before.

Remember to adjust the ranges and column names in this formula to match your specific table layout.
 
Upvote 0
=IF(DAY(R2)=1, SUMIFS(Table2[Value], MONTH(Table2[Date]), MONTH(R2)-1, YEAR(Table2[Date]), IF(MONTH(R2)=1, YEAR(R2)-1, YEAR(R2))), SUMIFS(Table2[Value], MONTH(Table2[Date]), MONTH(R2), YEAR(Table2[Date]), YEAR(R2)) )
Did you test that at all? It will not work since SUMIFS requires actual ranges for its sum and criteria ranges, not arrays. The use of MONTH and YEAR there will create arrays.
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,302
Members
449,150
Latest member
NyDarR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top