Set a SUM condition based on DATE calculation in Excel - excel

Problem
I have a table in Excel with a date range and quantities. I need to sum the quantities based date range from today and older then 30, 60, 90, etc days.
Logic
If the product was created within 30 days SUM qty.
If the product was created between 30 days and 60days, SUM qty.
If the product was created between 60 days and 90days, SUM qty.
Expected Results
Qty would equal to 24 (24)
Qty would equal to 32 (12+11+9)
Qty would equal to 26 (10+1+10+5)
Table
CREATED AT QTY
01/02/2016 10
01/02/2016 1
03/02/2016 10
05/02/2016 5
01/03/2016 12
02/03/2016 11
06/03/2016 9
12/03/2016 24

Use SUMIFS():
=SUMIFS(B:B,A:A,"<=" & Today() + 1,A:A,">=" & Today() - 30)
Change the + 1 to -30 and the - 30 to - 60 and so forth.
Or you can set up a small table where you have the end dates listed in a column then you can simply use something like this:
=SUMIFS(B:B,A:A,"<=" & TODAY() - D2 + 31,A:A,">=" & TODAY() - D2)

Related

Excel formula help - I have 14/28 day readings averaged per day which need to be recorded as daily readings

Dates when the data was read are shown on the date column on the left, then worked out a value per day shown in ET/DAY column.
To analyze monthly data etc etc I want daily data so every day has the ET/DAY value between the dates it was read and inserted in the et/day column.
I have entered in manually what I want in blue but need a formula to do this as too long to do all manually
You can do this with MATCH. With an ascending list, if you give the magic number 1 as the third parameter, it will show the last row number with a smaller or equal number.
Here it's matched 17 with 15 in column A and the result is 2, for row 2:
A
B
C
1
10
=MATCH(17,A:A,1) = 2
2
15
3
20
So for your data, you can match the daily dates with the column on the left, and feed the row number into INDEX to look up from the ET/Day column.
A
B
C
D
E
1
Date
ET/Day
Daily
ET/Day
2
05/Jan/1995
05/Jan/1995
=Index(B:B, Match(#D:D,A:A,1)) = #N/A
3
19/Jan/1995
3.00
06/Jan/1995
=Index(B:B, Match(#D:D,A:A,1)) = 3.00
4
02/Feb/1995
5.41
07/Jan/1995
=Index(B:B, Match(#D:D,A:A,1)) = 3.00
5
...
...
6
19/Jan/1995
=Index(B:B, Match(#D:D,A:A,1)) = 3.00
7
20/Jan/1995
=Index(B:B, Match(#D:D,A:A,1)) = 5.41
There's an inconsistency here with the 05 Jan rate but it should be good after that.

Number of days in between given two dates treating number of days in month as fixed 30 days

I need to calculate difference between two dates with a fixed 30 days a month logic. The example is shown below
Start date = 10/4/2018
End date = 28/10/2018
Expected number of days between = 199
(Excel calculation of difference of days => 28/10/2018 - 10/4/2018 = 201 which is not what I need)
The basis for calculation of difference between two dates is, it should consider number of days in a month as 30 days irrespective of the month. So all months in between the start & end dates with 31 days should be treated as 30 days. If there is Feb in between, it should also be taken as 30 days month.
Procedure to calculate number of days in between two given dates:
Fraction of days in the starting month = 30/4/2018 - 10/4/2018 = 21 days
Months in between 1/5/2018 to 30/9/2018 = 5 months = 5 x 30 = 150 days
Fraction of days in the last month = 28/10/2018 - 1/10/2018 = 28 days
Total days = 21 + 150 + 28 = 199 days.
If A1 is start date cell, B1 = End date cell, please suggest how to do it in excel.
I've broken the formula into the three components as in your example:
The formulas in D2:G2 are:
D2: =IF(AND(YEAR(A2)=YEAR(B2),MONTH(A2)=MONTH(B2)),MIN(DATE(YEAR(A2),MONTH(A2),30),B2),DATE(YEAR(A2),MONTH(A2),30))-MIN(DATE(YEAR(A2),MONTH(A2),30),A2)+1
E2: =MAX(((YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)-1)*30,0)
F2: =MIN(IF(AND(YEAR(B2)=YEAR(A2),MONTH(B2)=MONTH(A2)),0,B2-DATE(YEAR(B2),MONTH(B2),1)+1),30)
G2: =SUM(D2:F2)
or, all in one:
=IF(AND(YEAR(A2)=YEAR(B2),MONTH(A2)=MONTH(B2)),MIN(DATE(YEAR(A2),MONTH(A2),30),B2),DATE(YEAR(A2),MONTH(A2),30))-MIN(DATE(YEAR(A2),MONTH(A2),30),A2)+1+MAX(((YEAR(B2)-YEAR(A2))*12+MONTH(B2)-MONTH(A2)-1)*30,0)+MIN(IF(AND(YEAR(B2)=YEAR(A2),MONTH(B2)=MONTH(A2)),0,B2-DATE(YEAR(B2),MONTH(B2),1)+1),30)
I like the elegance of #Jeeped 's code, but this might be easier to follow.
Try this,
=SUMPRODUCT(--(DAY(ROW(INDIRECT(A2&":"&B2)))<>31))+
(DAY(A2)=31)+
SIGN(SUMPRODUCT((MONTH(ROW(INDIRECT(A2&":"&B2)))=2)*(DAY(ROW(INDIRECT(A2&":"&B2)))=28)))*2
It seems to me that your examples are a little "wonky", like how the 31st counts sometimes (like if it's the start/end date) but not others.
Anyway, this function ain't pretty but it does the trick:
Function No31st(startDate As Date, endDate As Date) As Long
Dim d As Date
For d = startDate To endDate 'iterate each day in range
If Day(d) <= 30 Then 'count days up to the 30th
No31st = No31st + 1
'if it's Feb 28, add 2 more days
If (Month(d) = 2 And Day(d) = 28) Then
No31st = No31st + 2 ' + Feb 29 + Feb 30
If Day(d + 1) <> 1 Then d = d + 1 'leap year
End If
End If
Next d
'since the 31st counts if it's the last day:
If Day(startDate) = 31 Or Day(endDate) = 31 Then No31st = No31st + 1
End Function
Sample Output:
StartDate endDate result
10/4/2018 28/10/2018 199
31/1/2018 31/3/2018 61
28/2/2018 1/3/2018 4
28/2/2000 1/3/2000 4
31/1/2018 1/2/2018 2
The DAYS360 formula is based on the 12 30-day month logic.
Simple & Easy Ways:
(1)
=YEARFRAC(start_date,end_date,4)*360
(2)
=DAYS360(start_date,end_date)

Select the majority value

I have the following Excel spreadsheet:
A B C D
1 Sales Price Sales Price Sales Price
2 January February March
3 Year 01 50 70 90
4 Year 02 50 60 40
5 Year 03 60 70 30
6 Year 04 40 60 50
7 Year 05 50 40 25
8
9 Majority Sales Price: 50 70 90
In Rows 3-7 you see the sales price of a product from the months January-March in 5 years (Year 01 - Year 05).
In Row 9 I want to select the sales price which has the majority within each month.
For example in January the sales price of 50 has the majority because it appears both in Year 01 and Year 02.
Please keep in mind the following criterias:
a) If there is no majority of a sales price the highest sales price should be picked. (Cell D9)
b) If two or more sales prices have the same majority the higher one should be picked. (Cell C9)
What formula do I need to get my desired result?
In cell B9 enter the following formula as an array, i.e. Ctrl+Shift+Enter:
{=IFERROR(MAX(MODE.MULT(B3:B7)), MAX(B3:B7))}
This uses MODE.MULT to find the modal value(s), which returns the result as an array. If there is more than one modal value, MAX returns the highest out of that array. If there is no modal value, MODE.MULT throws an error, hence the IFERROR statement which is used to find the max value in the error case.

Apply growth % to range in Excel

I'm doing a sales forecast and want to project what a 10% growth would be from month 1 to month 24.
For example if month 1 = 100 and a 10% growth for month 24 = 110.
The spreadsheet is laid out like this:
B C D Y
2 Month 1 Month 2 Month 3 ... Month 24
3 100 110
What function would I use to populate columns C3 though X3? say
Thanks!

How to calculate workdays and compensation for given period based on Employee's monthly salary?

I have only three editable fields:
salary = 15,000
start date = 18 Jul 2014
end date = 12 Oct 2014
With these fields, I need to calculate the total salary I need to pay. Payment is on a monthly basis:
(JULY = 15,000 / 31 * 14) +
(AUG = 15,000 / 31 * 31) +
(SEPT = 15,000 / 30 * 30) +
(OCT = 15,000 / 30 * 12).
I can get total days based on both dates (ie 87 days, =DAYS($enddate,$startdate)+1) ) but I need to split the days according to the months.
What formula do I need automatically to get the amount, because each person will have different salary and different dates?
You can use Excel VBA custom Function to solve your problem:
1). First, you should populate Excel Worksheet with data structure reflecting Employees Name, Monthly Salary, StartDate and EndDate, like in the following sample:
Employee M.Salary Start Date EndDate
John $15,000.00 7/18/2014 10/12/2014
Ann $20,000.00 7/19/2014 10/13/2014
Peter $16,000.00 7/20/2014 10/14/2014
Jeff $25,000.00 7/21/2014 10/15/2014
2). The DAYS in date range can be simply found by subtraction (EndDate-StartDate), because the underlying data type in integer
3). For general solution to the problem (Calculate the compensation for any arbitrary period and monthly salary) you will need to create custom VBA formula and use it in a separate column for each Employee. Refer to this article for explanation: Create a custom worksheet function in Excel VBA
4). Pertinent to your particular case with fixed date rage, the simplified solution based on the Excel Worksheet formulas (no VBA) is described below:
Employee MoSalary Start End Days FullMo FirstMo LastMo Total
John $15,000.00 7/18/2014 10/12/2014 87 30000.00 $6,774.19 $6,000.00 $42,774.19
Ann $20,000.00 7/18/2014 10/12/2014 87 40000.00 $9,032.26 $8,000.00 $57,032.26
Peter $16,000.00 7/18/2014 10/12/2014 87 32000.00 $7,225.81 $6,400.00 $45,625.81
Jeff $25,000.00 7/18/2014 10/12/2014 87 50000.00 $11,290.32 $10,000.00 $71,290.32
4a). In column E starting with row 2 add formula for DAYS : =(D2-C2)+1 and extend it for entire range
4b). In column F starting with row 2 add formula for whole months : =2*B2 and extend it for entire range
4c). In column G starting with row 2 add formula for the first month : =14*B2/31 and extend it for entire range
4d). In column H starting with row 2 add formula for last month : =12*B2/30 and extend it for entire range
4e). In column I starting with row 2 add formula for total compensation : =SUM(F2:H2) and extend it for entire range
Hope this will help. Best regards,
I have split this out because I am not entirely sure what you require and you may be able to assemble the pieces in a way that better suits you:
Assuming your data is in A1:A3, put 1/7/14 in C1, 1/8/14 in D1, 1/9/14 in E1 and 1/10/14 in F1.
To count the number of applicable days by month, in C2 enter:
=IF(MONTH($A2)=MONTH(C1),EOMONTH(C1,0)-$A2+1,IF(MONTH($A3)=MONTH(C1),DAY($A3),EOMONTH(C1,0)-EOMONTH(C1,-1)))
To compute the salary for the month by computing the daily rate for the applicable month and multiplying that by the number of days from above, in C3 enter:
=$A1*C2/(DAYS(EOMONTH(C1,0),C1)+1)
Format C2:C3 to suit and copy across to F2:F3.

Resources