Excel Formula - Sumif OR - excel

A challenge for the excel users:
I have a table with the following columns:
Year || Week || Output
2011 || 50 || 1000
2011 || 51 || 2000
2011 || 52 || 1500
2012 || 01 || 1200
2012 || 02 || 1700
2012 || 03 || 1900
I want to sum the values on the column output that are between a given year/week and another year/week. Example:
between 2011/50 and 2011/52. Result = 1000+2000+1500 = 4500
between 2011/51 and 2012/02. Result = 2000+1500+1200+1700 = 6400
Thank you all in advance.
Regards,
MH

My steps:
Year = A, Week = B, Output = E
Create a temp column (C) holding: {Year}*100 + {Week}
Create two input sets for the boundaries (also with {Year}*100 + {Week}) -- <LOW> & <HIGH>.
Create a temp column (D) with this formula:
=IF(AND(C2>=<LOW>,C2<=<HIGH>),1,0)*E2
Then the summation cell becomes:
=SUM(D:D)
EDIT: Found another way with no D column from above
N1 = LOW (year*100 + week)
O1 = HIGH (year*100 + week)
N2 => =TEXT(N1)
O2 => =TEXT(O1)
=SUMIFS(E:E,C:C, CONCATENATE(">=", $N$2),C:C, CONCATENATE("<=", $O$2))

You can use SUMIFS(), in case that you're using Excel 2007 or above.
Example
=SUMIFS(C2:C7, A2:A7, "=2011", B2:B7, ">49", B2:B7, "<53")
Otherwise you can still use Excel Macros.

Assuming your data is in A1:C6, you can do this with an array formula (enter using Shift+Ctrl+Enter):
=SUM((A1:A6=2011)*(B1:B6>=50)*(B1:B6<=52)*(C1:C6))
Or, with SumProduct (enter as normal):
=SUMPRODUCT((A1:A6=2011)*(B1:B6>=50)*(B1:B6<=52)*(C1:C6))
Obviously, you'll need to enter or reference your criteria. Also, if the year will change then you'll need another term to check the max year.

Related

Iterate through rows and columns, compare dates and if statement true sum and print in new column

this is my first question here and i can't find a solution that works for me.
I have a set of data. i need to compare the date displayed in cell 2,2 (until 2,109) with the date in the head of cell 3,1 until 54,1. If the date is the same month in the same year, I need to display in cell(s) 55,1 the value "one month before" or "the active cell -1 row".
The cells used in the if-statement refer to Dates / there are dates written in the cells. I might mistreat the dates...
Highly appreciate any help.
Many thanks in advance!
My code looks like this: I don't recieve an error but the values dont make sense
Sub oneM_lag()
'
' oneM_lag Macro
'
With Application
.Calculation = xlCalculationManual
End With
rw = 2 'counting purpose
erw = 109
cdrw = 2 'change date
cdcl = 2
dvrw = 1 'date values in head of each row
dvcl = 3
vrw = 2 'flow values
vcl = 3
fcl = 54 'final calculated flow values
frw = 2
Do While rw < erw
If Cells(cdrw, cdcl) >= Cells(dvrw, dvcl) Then
Cells(frw, fcl) = Cells(vrw, vcl - 1)
End If
rw = rw + 1
cdrw = cdrw + 1
dvcl = dvcl + 1
frw = frw + 1
vcl = vcl + 1
Loop
End Sub
I tried a different code. I manually lagged the dates by 1 month so now i want to display the value in the i-th cell below the Date:
fd = 3
For i = 2 To 109
If Cells(i, 2) <= Cells(1, fd) Then
Cells(i, 54) = Cells(i, fd)
End If
fd = fd + 1
Next i
End Sub
This works but only for row 29 where it corretly identified the value ... i checked the format of my values. The code pasts other wrong values until row 52.
I think I'll need a bit more clarification to give you the answer you are looking for. You wrote that you need to compare the dates in the between column 2 (B) and the head of cells 3, 1 through cell 54, 1, Since you said 'head', I'm inclined to believe that you meant row 1, columns 3 through 54 or C1 through BB1. (If written in terms of how VBA interprets Cells, you've written the head of rows 3 through 54 in column A.)
I don't have enough information to provide updated VBA, yet.
After you read through this, please either update your question with the answers I need to help or place them in a comment. (If you update your question, leave a comment to so I know that you did.)
What I think you want the code to do
I believe that you have a spreadsheet that looks something like this:
A
B
C
D
~
BB
BC
1
?
Dates
May 1, 2022
Apr 1, 2022
~
Aug 1, 2019
if true, results of first iteration
2
?
Aug 1, 2019
?
?
~
?
?
3
?
Jul 2, 2019
?
?
~
?
?
Where should the results of the second iteration go?
You've coded and inferred that this is something that needs to be iterated, but I only know that the first output value needs to be placed in cell BC1. Where does the next value go?
For example, using the example table:
First iteration
Compare the month and year B2: Aug 1, 2019 with dates in C1:C54.
The month = month & year = year match is C54: Aug 1, 2019.
Collect date in B2: Aug 1, 2019. Subtract one month from the date collected: July 1, 2019.
Place the modified date, July 1, 2019, in BC1 (the 55th column, row 1).
A
B
C
D
~
BB
BC
1
?
Dates
May 1, 2022
Apr 1, 2022
~
Aug 1, 2019
July 1, 2019
2
?
Aug 1, 2019
?
?
~
?
?
3
?
Jul 2, 2019
?
?
~
?
?
What happens next?
Do I compare the next value in column B with the new date in BC1?
If so, does the resulting match, less one month go in cell BD1?
Your question mentions the 'true sum'; how does that come into play here?
What your code does
When I wrote that you would need to modify the if-then, I wrote what your code does.
Here is a different example table, this indicates where the values will go if the first through third iteration are true:
A
B
C
D
E
~
BB
1
?
Dates
Aug 1, 2019
Jul 1, 2019
Jun 9, 2019
~
Aug 1, 2022
2
?
Aug 1, 2019
?
?
?
~
if true, results of first iteration
3
?
Jul 2, 2019
?
?
?
~
if true, results of second iteration
4
?
Oct 9, 2019
?
?
?
~
if true, results of third iteration
Is B2 ≥ C1? True. Then the value in B2 goes to BB2.
A
B
C
D
E
~
BB
1
?
Dates
Aug 1, 2019
Jul 1, 2019
Jun 9, 2019
~
Aug 1, 2022
2
?
Aug 1, 2019
?
?
?
~
Aug 1, 2019
3
?
Jul 2, 2019
?
?
?
~
if true, results of second iteration
4
?
Oct 9, 2019
?
?
?
~
if true, results of third iteration
Update
I'm still not sure what you're looking for, but perhaps if I show you what your code is doing, that will help.
A
B
C
D
E
~
BB
BC
BD
1
?
Dates
8/1/19
7/1/19
6/9/19
~
8/1/22
?
?
2
?
8/1/19
use this value if the first iteration matches
?
?
~
if matched this value changes
?
?
3
?
7/2/19
?
use this value if the second iteration matches
?
~
if matched this value changes
?
?
4
?
10/9/19
?
?
use this value if the third iteration matches
~
if matched this value changes
?
?
The first iteration:
Is B2 ≤ C1?
If yes, then put the value of C2 into BB2
The second iteration:
Is B3 ≤ D1?
If yes, then put the value of D3 into BB3
The third iteration:
Is B4 ≤ E1?
If yes, then put the value of E4 into BB4
I can tell you that BB is 54; BC should be 55. Although, you said that the correct value was provided in row 29...If you wanted to stick to column C's values, that means that row 29 column C and column AC have the same value?

SUM.PRODUCT - how to get an array of values that correspond to a single cell value

I'm trying to calculate weight average per user for three different processes. My table looks like this:
User || Process || Bonus[%] || Weight
John Smith || RETURNS || 5 || 2
John Smith || PUTAWAY || 10 || 3
John Smith || RECEIVING || 7 || 1
So basically I want my formula in each row to look like this:
=SUM.PRODUCT({5,10,7},{2,3,1})/SUM({2,3,1})
The formula needs to have an array of values based on the User Name. How can I do that?
Try formula:
=SUMPRODUCT((A2=$A$2:$A$7)*($C$2:$C$7)*($D$2:$D$7))/SUMPRODUCT((A2=$A$2:$A$7)*($D$2:$D$7))
You can use this:
=SUMPRODUCT(--(user_name_column="user name"),[Bonus %],[Weight])/SUMIF(user_name_column,"user name",[Weight])
adjusting the ranges to match your data locations.

SLA COUNT IN EXCEL FORMULA

I'm looking for an excel (Office 2016 packet) formula that count SLA for ticket resolution.
the SLA counter must consider :
1) Monday To Saturday as work day ;
2) Holiday as no working days (must be skipeed as work day);
3) SLA start for ticket generate in workdays during range-time "08:00-20:00" out of this time-range SLA count is "0" ;
4) Output should result as R1= first 24Hours ; R2= from 25 to 48 hours ; R3= from 49 to 72 hours; "Out of Sla" = since 72 hours
Data to count SLA is formatted as below for either for ticket open and closure:
Column N Column O Column P Column Q
"TICKET START DATE" "TICKET STOP DATE" "SLA" "HOLIDAY"
28/4/18 13:30 30/4/18 19:20 2 25/04/2018
28/4/18 13:11 29/4/18 13:11 1 01/05/2018
28/4/18 12:57 28/4/18 12:57 1
I solved point 1) & 2) with NETWORKDAYS.INTL formula using the first column as start_date ; the second column as end_date; 11 as third formula's field to exclude Sunday as workdays; fourth formula's value pointing a column where are listed the "holidays" date .
I could not find a solution for point 3).
It will also appreciate a possible solution for point 4) .
Thank you in advance.
Formula example of above fields :
=NETWORKDAYS.INTL(N15;O15;11;Q16:Q17)
Alessandro.
I've needed to do something similar in the past. Please see the formula below. It will give you the amount of time between working days (Monday-Friday), only taking into account times 8:30am to 5:30pm. Try inserting your specific parameters.
=IFERROR((NETWORKDAYS.INTL(H8,I8,,)-1)*("17:30"-"8:30")
+IF(NETWORKDAYS.INTL(I8,I8,,),MEDIAN(MOD(I8,1),"8:30","17:30")
,"17:30")-MEDIAN(NETWORKDAYS.INTL(H8,H8,,)*MOD(H8,1),"8:30","17:30"),"")
H8 = Start Date
I8 = End Date
8:30 = Start Time
17:30 = End Time

Excel Array formula, use info from one IF result as criteria in another IF?

Context
I'm building a financial dashboard, but I'm having troubles to get a formula that fit my client's need.
I'm consolidating amount in different currencies, but for a special indicator,
I need to build a YTD with the Exchange Rate of the last month.
Something like :
(Amount_$_Jan + Amount_$_Feb)*ExRate_$_Feb + (Amount_£_Jan + Amount_£_Feb)*ExRate_£_Feb
OR
(Amount_$_Jan + Amount_$_Feb + Amount_$_Mar)*ExRate_$_Mar + (Amount_£_Jan + Amount_£_Feb + Amount_£_Mar)*ExRate_£_Mar
My issue
In the data, I have multiple currencies and they'll be more to come, so I cannot list the currencies.
I'm trying to :
get the value of the currency of each line that matches the criteria of the first IF
to use it in my second IF to find the exchange range for that currency
for the month I'm calculating for,
with: Named_Rg[Currency]=Named_Rg[Currency]
which is obviously always true, but it is the only syntax I've tried that I could validate...
I've tried :
Named_Rg[Currency]=[#[Currency]]
Named_Rg[Currency]=[Currency]
But both are giving errors (I'm using that formula outside of the table Named_Rg)
I know I can write a function in VBA, but I'd prefer to keep an xlsx.
My formula
I've removed some tests, like testing the year, which are not pertinent for the question.
I'm using it on a another sheet that the one where the table Named_Rg is :
{=SUM(IF(Named_Rg[Month]<=MONTH(X$5);Named_Rg[Amount]*IF(AND(Named_Rg[Month]=MONTH(X$5);Named_Rg[Currency]=Named_Rg[Currency]);Named_Rg[Chg to €];0);0))}
How can I refer to the Row/Currency found with the first IF in the second one?
Sample Data
That is just a sample, I'll have multiples rows per month and currency.
Year Month Currency Chg to € Amount
2017 1 EUR 1 20
2017 1 USD 0.6 30
2017 1 LST 2 40
2017 2 EUR 1 200
2017 2 USD 0.7 300
2017 2 LST 2.2 400
2017 3 EUR 1 2000
2017 3 USD 0.8 3000
2017 3 LST 2.4 4000
CSV format :
Year;Month;Currency;Chg to €;Amount
2017;1;EUR;1;20
2017;1;USD;0.6;30
2017;1;LST;2;40
2017;2;EUR;1;200
2017;2;USD;0.7;300
2017;2;LST;2.2;400
2017;3;EUR;1;2000
2017;3;USD;0.8;3000
2017;3;LST;2.4;4000
Expected results :
YTD last chg (Jan) : 118 = 20*1+30*0.6+40*2
YTD last chg (Feb) : 1419 = (20+200)*1+(30+300)*0.7+(40+400)*2.2
YTD last chg (Mar) : 15540 = (20+200+2000)*1+(30+300+3000)*0.8+(40+400+4000)*2.4
Array formula do not like the AND() or OR() operators. They need to be substituted with * or + respectively.
So your:
AND(Named_Rg[Month]=MONTH(X$5);Named_Rg[Currency]=Named_Rg[Currency])
Should be:
(Named_Rg[Month]=MONTH(X$5))*(Named_Rg[Currency]=Named_Rg[#Currency])
So the formula would be:
=SUM(IF(Named_Rg[Month]<=MONTH(X$5);Named_Rg[Amount]*IF((Named_Rg[Month]=MONTH(X$5))*(Named_Rg[Currency]=Named_Rg[#Currency]);Named_Rg[Chg to €])))
Remember that this is an array formula and needs to be confirmed with Ctrl-Shift-Enter
But I think you want this formula instead to get the desired output:
=SUMPRODUCT(SUMIFS(Named_Rg[Amount],Named_Rg[Month],"<=" & MONTH(X5),Named_Rg[Currency],Named_Rg[Currency])*(Named_Rg[Month]=MONTH(X5))*(Named_Rg[Chg to €]))
Change the , to your ; for your local settings.

Formula to calculate salary after x year?

Knowing that i am getting paid $10 000 a year, and that each year my salary increase by 5%.
What is the formula for Excel to know how much i will get in 5 year?
Thank you for any advise
The formula in Excel is:
=VF(5%;5;0;-10000)
Which results in: $12,762.82
If your Office is english version you can use:
=FV(5%;5;0;-10000)
=(10000*((1 + 0.05)^5))
The Compound Interest Equation
P = C (1 + r/n)^nt
Where...
P = Future Value
C = Initial Deposit/Salary
r = Interest Rate/Pay Increase (Expressed as a Fraction: EX = 0.05)
n = Number of Times per Year the Interest/Pay Raise Is Compounded (0 in Your Example)
t = Number of Years to Calculate
The Formula is POWER(B1,C1)*10000, and the cell B1 is (1+5% ), the cell C1 is the number of years
current = 10 000
for each year -1
current = current * 1.05
end for
current now has current salary for the given number of years

Resources