Calculate Total Expense With Condition

kumara_faith

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

I have the following table:


Book2
BCDEFGHIJKLMNOPQRSTU
3MonthExpense CategoryAmountToday5/12/2024MonthJanFebMarAprMayJuneJulyAugustSeptemberOctoberNovemberDecember
4JanLoans5000Average4560594311
5JanFood50Total Actual52255301529352175053
6JanAutomobile60Total Estimated6041
7JanMedical80
8JanFood20
9JanTemple15
10FebLoans5000
11FebFood150
12FebAutomobile65
13FebMedical45
14FebFood23
15FebTemple18
16MarLoans5000
17MarFood110
18MarAutomobile65
19MarMedical78
20MarFood15
21MarTemple25
22AprLoans5000
23AprFood125
24AprAutomobile25
25AprMedical17
26AprFood35
27AprTemple15
28MayLoans5000
29MayFood10
30MayAutomobile12
31MayMedical14
32MayFood12
33MayTemple5
Sheet1


The expense details is in the first table. In the second table, I am trying to calculate the average per month excluding the Loans expenses which is the outlier for every month. The total column includes the loans expense. I am trying to calculate the following:

1. The average expense for every month excluding the Loans in row J4:U4
2. In rowJ6:U6, I am trying to calculate the total expense for the current month based on the average expense for Jan-Apr . This will differ based on the current month. If the current date is June, then it will be Jan-May and so on.

The average expense per day for Jan-Apr excluding Loans is 52. The current date is 12 May 2024 with a balance of 19 days in May. Average expense of 52 X 19 days +5000(Loans) will result in 5988. Assuming total expense for May as of 12 May 2024 excluding Loans is 53, then total expense for May will be 6041

I tried the following but it did not work:

Excel Formula:
=IFERROR((AVERAGEIFS($D$4:$D$100000, $B$4:$B$100000, "<="&N3, $C$4:$C$100000, "<>"&"Loans") * (EOMONTH(G3,0)-G3+1)) + SUMIFS($D$4:$D$100000, $B$4:$B$100000, N3, $C$4:$C$100000, "Loans"), 0)

Please note that the actual range is from b4:b100000. This is a working file and the expenses will be entered everyday. The formula range will from B4:B100000 and the amount will be in the range d4:d10000. Both range will will have empty values as we enter the data every month from Jan to Dec 2024.



Is there a formula that could be used to accomplish this ? Appreciate all the help.
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
Excel Formula:
=AVERAGEIFS($D:$D,$B:$B,J$3,$C:$C,"<>Loans")
 
Upvote 0
Assuming this sheet is only 2024. Adapt the ranges.
Book1
IJKLMNO
3MonthJanFebMarAprMayJune
4Average45.0060.2058.6043.4010.60
5Total Actual5,225.005,301.005,293.005,217.005,053.00
6Total Estimated 5,984.20
Sheet3
Cell Formulas
RangeFormula
J4:N4J4=AVERAGEIFS($D$4:$D$33,$B$4:$B$33,J3,$C$4:$C$33,"<>Loans")
J5:N5J5=SUMIFS($D$4:$D$33,$B$4:$B$33,J3)
J6:N6J6=LET(loan,INDEX($D$4:$D$33,MATCH(J3&"Loans",$B$4:$B$33&"Loans",0)), d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3), avg,AVERAGEIFS($D$4:$D$33,$C$4:$C$33,"<>Loans",$B$4:$B$33,"<>"&J3), IF(d<0,"",loan+d*avg))
 
Upvote 0
Hi Cubist,

The formula for J6 does not seems to take into account the expenses incurred for May up to the current date which is 53 (excluding loans which the above formula has already included). Is there a way to include the expenses up to the current date for May to arrive at the correct total estimated expense for May ? Thanks.
 
Upvote 0
We can take advantage of the total in row 5.
Excel Formula:
=LET(loan,INDEX($D$4:$D$33,MATCH(J3&"Loans",$B$4:$B$33&"Loans",0)),
exp,J5-loan,
d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3),avg,AVERAGEIFS($D$4:$D$33,$C$4:$C$33,"<>Loans",$B$4:$B$33,"<>"&J3),
IF(d<0,"",loan+exp+d*avg))
 
Upvote 0
There are some redundant calculations in post#5. It can simplify to this.
Excel Formula:
=LET(
d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3),
avg,AVERAGEIFS($D$4:$D$33,$C$4:$C$33,"<>Loans",$B$4:$B$33,"<>"&J3),
IF(d<0,"",J5+d*avg))
 
Upvote 0
Hi Cubist,

Thank you and that worked. Really appreciate it.

When I drag the formula across to Jan to Apr, the formula shows blank which is correct because the months has passed. When I drag to June to Dec, by right the formula should also show blank because the months are in the future. But the formula seems to show estimated figures. Is there a way to modify this ?
 
Upvote 0
See below for the updated formula to not show for the other months. One thing I noticed one thing about your methodology of calculating the average. What you're calculating is the average monthly expense, not per day, so it's not quite correct. See how the result N6 compares to N7.
Book1
IJKLMNO
3MonthJanFebMarAprMayJune
4Average4560.258.643.410.6
5Total Actual5,2255,3015,2935,2175,053
6Total Estimated 6,037
7Total Estimated* 5,700
Sheet10
Cell Formulas
RangeFormula
J4:N4J4=AVERAGEIFS($D$4:$D$33,$B$4:$B$33,J3,$C$4:$C$33,"<>Loans")
J5:N5J5=SUMIFS($D$4:$D$33,$B$4:$B$33,J3)
J6:O6J6=LET( m,MONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1)), d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3), avg,AVERAGEIFS($D$4:$D$33,$C$4:$C$33,"<>Loans",$B$4:$B$33,"<>"&J3), IF(m<>MONTH($G$3),"",J5+d*avg))
J7:O7J7=LET( m,MONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1)), d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3), avg,SUMIFS($D$4:$D$33,$B$4:$B$33,"<>"&J3,$C$4:$C$33,"<>Loans")/30.44, IF(m<>MONTH($G$3),"",J5+d*avg))
 
Upvote 0
I didn't divide by the number of months above. The result should be closer to other months.
Book1
IJKLMNO
3MonthJanFebMarAprMayJune
4Average4560.258.643.410.6
5Total Actual5,2255,3015,2935,2175,053
6Total Estimated 6,037
7Total Estimated* 5,215
Sheet10
Cell Formulas
RangeFormula
J4:N4J4=AVERAGEIFS($D$4:$D$33,$B$4:$B$33,J3,$C$4:$C$33,"<>Loans")
J5:N5J5=SUMIFS($D$4:$D$33,$B$4:$B$33,J3)
J6:O6J6=LET( m,MONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1)), d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3), avg,AVERAGEIFS($D$4:$D$33,$C$4:$C$33,"<>Loans",$B$4:$B$33,"<>"&J3), IF(m<>MONTH($G$3),"",J5+d*avg))
J7:O7J7=LET( m,MONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1)), d,(EOMONTH(DATE(2024,MONTH(DATEVALUE("1-"&J3&"-2024")),1),0)-$G$3), avg,SUMIFS($D$4:$D$33,$B$4:$B$33,"<>"&J3,$C$4:$C$33,"<>Loans")/30.44/(m-1), IF(m<>MONTH($G$3),"",J5+d*avg))
 
Upvote 0
Solution
Hi Cubist,

Thank you for your patience and assistance. That worked. Really appreciate it and have a great day ahead.🙏
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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