Excel Formula needs adjusting - excel

Please can someone help 'fine tune' this If formula that doesn't quite do what I need:
=IF(AV4=0,AP4,IF(OR(AV4>=70,AV4<=30),AP4-IF(AP4>16,4,IF(AP4<16,2,0)),AP4))
the changes I need are:
if the figure in AV is equal to or less than 30 it is deducting 4 (if AP is over 16) or 2 (if AP is under 16) but it should be adding (not deducting) 4 or 2
Also if AP is = or < 16 up or down by 2 (at present it doesn't do anything if AP is 16
The full brief is as follows:
I have present handicaps in column AP - based on whether their present handicap is 16 and over or 16 and below - I need the following to happen based n results in column AU:
if a number in column AV is higher than 70
Present handicap over 16 (column AP) - decrease by 4
Present handicap under 16 (column AP) - decrease by 2
if a number in column AV is less than 30
Present handicap over 16 (column AP)- increase by 4
Present handicap under 16 (column AP) - increase by 2
If AP is = or < 16 up or down by 2 (if AV over 70 or less than 30)
If AV = 0 - it just copies the value of AP
All rows with a result between 31 an 69 between nothing happens and the handicap in column AP doesn't change

This looks to be giving intended results. Check against your own data.
=IF(AV4>69,IF(AP4>16,AP4-4,AP4-2),IF(AV4<31,IF(AP4>16,AP4+4,AP4+2),AP4))

Related

TRUE/FALSE ← VLOOKUP ← Identify the ROW! of the first negative value within a column

Firstly, we have an array of predetermined factors, ie. V-Z;
their attributes are 3, the first two (•xM) multiplied giving the 3rd.
f ... factors
• ... cap, the values in the data set may increase max
m ... fixed multiplier
p ... let's call it power
This is a separate, standalone array .. we'd access with eg. VLOOKUP
f • m pwr
V 1 9 9
W 2 8 16
X 3 7 21
Y 4 6 24
Z 5 5 25
—————————————————————————————————————————————
Then we have 6 columns, in which the actual data to be processed is in, & thereof derive the next-level result, based on the interaction of both samples introduced.
In addition, there are added two columns, for balance & profit.
Here's a short, 6-row data sample:
f • m bal profit
V 2 3 377 1
Y 2 3 156 7
Y 1 1 122 0
X 1 2 -27 2
Z 3 3 223 3
—————————————————————————————————————————————
Ultimately, starting at the end, we are comparing IF -27 inverted → so 27 is within the X's power range ie. 21 (as per the first sample) .. which is then fed into a bigger formula, beyond the scope of this post.
This can be done with VLOOKUP, all fine by now.
—————————————————————————————————————————————
To get to that .. for the working example, we are focusing coincidentally on row5, since that's the one with the first negative value in the 'balance' column, so ..
on factorX = which factor exactly is to us unknown &
balance -27 = which we have to locate amongst potentially dozens to hundreds of rows.
Why!?
Once we know that the factor is X, based on the * & multiplier pertaining to it, then we also know which 'power' (top array) to compare -27, as the identified first negative value in the balance column, to.
Is that clear?
I'd like to know the formula on how to achieve that, & (get to) move on with the broader-scope work.
—————————————————————————————————————————————
The main issue for me is not knowing how to identify the first negative or row -27 pertains to, then having that piece of information how to leverage it to get the X or identify the factor type, especially since its positioned left of the latter & to the best of my knowledge I cannot use negative column index number (so, latter even if possible is out of the question anyway).
To recap;
IF(21>27) = IF(-21<-27)
27 → LOCATE ROW with the first negative number (-27)
21 → IDENTIFY the FACTOR TYPE, same row as (-27)
→ VLOOKUP pwr, based on factor type identified (top array, 4th column right)
→ invert either 21 to a negative number or (-27) to the positive number
= TRUE/FALSE
Guessing your columns I'll say your first chart is in columns A to D, and the second in columns G to K
You could find the letter of that factor with something like this:
=INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0)))
INDEX(J:J<0) converts that column to TRUE and FALSE depending on being negative or not and with XMATCH you find the first TRUE. You could then use that in VLOOKUP:
=VLOOKUP(INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0))),A:D,4,0)
That would return the 21. You can use the first concept too to find the the -27 and with ABS have its "positive value"
=VLOOKUP(INDEX(G:G,XMATCH(TRUE,INDEX(J:J<0))),A:D,4,0) > INDEX(J:J,XMATCH(TRUE,INDEX(J:J<0)))
That should return true or false in the comparison

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Sort numbers into groups so that the difference of their sums is minimal

I found a few threads that were similar however I believe mine is a bit unique. This will be difficult to write so please bear with me.
I have a strain of 10 accounts, each account has a static number that can not be split up. I have 3 employees that need these accounts split as even as possible. They cannot share an account.
For example:
(A)lpha = 15
(B)eta = 30
(C)harlie = 22
(D)elta = 19
(E)cho = 28
(F)ranklin = 3
(G)roto = 7
(H)enry = 28
(I)ndia = 38
(J)uliet = 48
The total sum is = 238. In the perfect world, 2 people would get 79 and one person would have 80. However, remember we cannot break apart an account so we would need to add accounts together to get as close to evenly spread as possible.
I need a formula for this since situations like this occur regularly and it takes some time to figure this out. I believe this would be best executed with a helper column.
The closest I have come to is:
FHJ = 79
ABCG = 74
DEI = 85
But since this is reoccurring and can happen over even more accounts, I need something I can reuse over and over.
Another less complex but approximated solution would be to
sort your accounts from highest to lowest number.
Start sorting the numbers into 3 groups (A, B, C)
starting with the 3 highest numbers (48|J, 38|I, 30|B) sorting to group A, B and C
next highest number (28|E) goes to the group with the lowest sum (C)
next highest number (28|H) goes to the group with the lowest sum (B)
and so on …
You should end up with this:
Which is different from your manual solution but closer. If you see the differences:
Solution from above: 81 - 77 = 4
Your manual solution: 85 - 74 = 11
This algorithm is an approximation, it will not always find the best solution but if the difference between the lowest and highest number is not too large then the result is very close to the best solution.
This is known as a partition problem. You could try implementing the pseudo-polynomial time algorithm from the Wikipedia page. You'll have to modify it for 3 partitions instead of 2.
INPUT: A list of integers S
OUTPUT: True if S can be partitioned into two subsets that have equal sum
1 function find_partition(S):
2 n ← |S|
3 K ← sum(S)
4 P ← empty boolean table of size (floor(K/2)+ 1) by (n + 1)
5 initialize top row (P(0,x)) of P to True
6 initialize leftmost column (P(x, 0)) of P, except for P(0, 0) to False
7 for i from 1 to floor(K/2)
8 for j from 1 to n
9 if (i-S[j-1]) >= 0
10 P(i, j) ← P(i, j-1) or P(i-S[j-1], j-1)
11 else
12 P(i, j) ← P(i, j-1)
13 return P(floor(K/2), n)

Rolling Time LookBack Calculation

I'm sorry if this has been answered. I've been searching around for awhile now.
I have a times series dataset that I need to perform calculations on based on the previous x time (last hour,day, etc).
My issues is that I don't know how to run these calculations since the time deltas are not standardized.
Example:
Column A - Time (in seconds lets say)
Column B - Value
Time Value Result(5)
01 3 0
02 5 3
04 4 8
07 8 9
09 6 12
13 4 6
14 4 10
15 1 8
22 9 0
33 7 0
How could I return the Result(5) column by summing the last 5 seconds from that one instance (row) (not including it)?
Thank you.
EDIT:
To clear up what I'm trying to do:
1) Find the previous 5 secs of data using column A and return that range of rows
2) Using that range of rows for the 5 previous secs, sum column B
3) Output in Column C (formula)
The following formula should do what you need (paste into C2 and drag down):
=SUMIFS($B$2:$B$11,$A$2:$A$11,">="&A2-5,$A$2:$A$11,"<"&A2)
Where YourTime is the time in the row you wish to look back and sum over.
I've tested and it works for the data you provided - expand the ranges as appropriate.

Need to make a calculation based on multiple lookup results on another Excel sheet

Need to try and get a result based on possible 3 lookups in Excel.
I have a price for a certain size hire vehicle and need to check to see if I want to add in a supplement or not based on entry into a cell in another sheet.
I have a sheet called Keys that has the criteria I base my calculations on and a second sheet I have the rates loaded for all the vehicle sizes available, cars to coaches. I would like to calculate the supplement for customers of the move to a larger vehicle or even a reduction dependent on what I choose.
Keys data is:
Vehicle Sizes
Range # Seats Rate Column Supplement Range to work on
1 4 R N
2 7 S Y 1
3 16 T N
4 24 U Y 5
5 29 V N
6 35 W N
7 45 X N
So for example if the I have chosen to calculate the supplement on the 7 seater then I want to calculate the difference between the 7 seater and 4 seater and that is my supplement. I have also chosen to calculate the reduction between the 29 and 24 seater vehicles.
Am trying to figure out how to combine multiple IF and LOOKUP, if they are correct or not.
So basically IF I have a Y in the supplement column on Keys then calculate the difference in the rates based on the Rate Column based on the Range to work on.
Any suggestions or help appreciated
Sorry think I forgot about the actual rates. They are stored on another sheet as per below. the charges are per service, like an airport transfer etc., they are in VN Dong so thats why they are in the 100,000 + range.
R S T U V W X
Rate with Surcharge
4 7 16 24 29 35 45
340000 373000 394000 735000 780000 1050000 1210000
I have tried to tweak the answer from pnuts but getting a bit lost, note sure if I need the MATCH in the formula of not.
I doubt this will suit but it may help to clarify your requirements:
=IF($D2="N","",INDEX(Sheet2!$Q$2:$X$4,MATCH(F$1,Sheet2!$Q$2:$Q$4,0),CODE($C2)-80)-INDEX(Sheet2!$Q$2:$X$4,MATCH(F$1,Sheet2!$Q$2:$Q$4,0),CODE($C2)+$E2-$A1-81))
in F2 copied across and down to suit.

Resources