Excel formula for working with multiples (factors) - excel

I need a formula on Excel which would deduct the multiple of 20 from a given number. For example:
2 would give you 18,
10 would give 10,
23 would give 17,
118 would give 2,
321 would give 19.

It's worth noting that Excel has built-in functions for working with multiples: CEILING and FLOOR (in newer versions you have CEILING.MATH and FLOOR.MATH).
In your case, this should work:
=CEILING(A1,20)-A1

You want to divide it by 20, round it up and multiply it by 20, the rest is trivial.
=-(A1-ROUNDUP(A1/20,0)*20)

Related

Excel: Average Difference in a single formula

I have a dataset like this:
10, 23, 43, 45, 56;
12, 25, 21, 23, 40;
I want to know the average of the difference between the two rows like
mean (10 - 12, 23 - 25, 43 -21 ...)
Of course, this is only an example and the actual rows are hundreds of element long. I would like to compute the average of the difference without having to compute somewhere the difference and then having the average. (The sheet is already pretty big)
Thanks a lot
Mathematically, what you are asking for is identical to:
=AVERAGE(A1:E1)-AVERAGE(A2:E2)
Regards
Try,
=AVERAGE(INDEX((A1:E1)-(A2:E2), , ))
If there were missing values in one range or the other, you would need something like
=AVERAGEIFS(A1:G1,A1:G1,"<>",A2:G2,"<>")-AVERAGEIFS(A2:G2,A1:G1,"<>",A2:G2,"<>")
(I have tested it with blanks in G1 and F2)

Excel - Count of entries below cumulative threshold without helper column

I have the following little table. I'd like a formula that finds the number of values where the cumulative total (of column B) is less than some threshold (tx).
I tried
{=MIN((SUM(OFFSET(B1,0,0,A1:A17))>tx)*A1:A17)-1}
but OFFSET doesn't seem to be arrayable like that. Obviously, this would be trivial with a helper column, but for certain reasons that is not possible.
So the correct answer here should be 10.
tx = .8
A B
1 0.112106465
2 0.110981698
3 0.091959216
4 0.082163441
5 0.073292066
6 0.072407529
7 0.071646289
8 0.061646797
9 0.06011448
10 0.057566381
11 0.050341978
12 0.048227061
13 0.043207335
14 0.03940462
15 0.012914194
16 0.007603446
17 0.004417003
You're not really looking for a MIN; rather it should be MAX that follows your condition.
In E7 as a standard (non-array) formula,
=AGGREGATE(14, 6, ROW(1:17)/(SUBTOTAL(9, OFFSET(B1, 0, 0, ROW(1:17), 1))<D7), 1)
      
I prefer the following array formula** due to its non-volatility:
=MATCH(TRUE,MMULT(0+(ROW(B1:B17)>=TRANSPOSE(ROW(B1:B17))),B1:B17)>=0.8,0)-1
Regards
The most succinct way to do it I've found is
=SUM(--(SUBTOTAL(9,OFFSET(B1,,,A1:A17))<0.8))
entered as an array formula, or, equivalently,
=SUMPRODUCT(--(SUBTOTAL(9,OFFSET(B1,,,A1:A17))<0.8))

Explain the CEILING function for dates

I have a formula which gives me different dates depending on the multiplier. I am not sure how it works though, except that it rounds a date. The formula is the following:
=DATE(YEAR($L$4),CEILING(MONTH($L$4),2),0)
So imagine today´s date is 18/08/2015 in cell L4. If i change the multiplier i get the following results:
=DATE(YEAR($L$4),CEILING(MONTH($L$4),2),0) = 31/07/2015
=DATE(YEAR($L$4),CEILING(MONTH($L$4),3),0) = 31/08/2015
=DATE(YEAR($L$4),CEILING(MONTH($L$4),4),0) = back again to 31/07/2015.
Why does this happen? Why does it go back to 31/07/2015 if the multiplier increases to 4?
=CEILING('number', 'multiple') returns a multiple of the 'multiple' that is nearest to the 'number'.
Since MONTH evaluates to 8 or August, you would have =CEILING(8, 3), which evaluates to 9, because 9 is the multiple of 3 closest to 8. 2 and 4 as multiples will both return 8.
=DATE(2015, 9, 0) will return the last date of the previous month, because the day is 0.
If you tried your formula with CEILING(MONTH($L$4), 10), you would get 31/9/2015, because the multiple of 10 nearest to 8 is 10, and the DATE formula will end up looking like =DATE(2015, 10, 0) which evaluates to 31/9/2015.
As a side note, the button below is very helpful in analyzing the formulas that you select in the excel chart.

How to distribute data into matrix format in VBA excel

Because of the structual nature of dataset, I plan to use VBA in Excel 2010 to process the dataset. The main characteristics of the dataset include three main columns as illustrated:
FromID, ToID, Amount
10, 10, 50
10, 11, 67
10, 12, 56
11, 10, 60
11, 11, 80
12, 10, 17
12, 11, 57
Of course this is the simplified version of the data and the origional data is much complicated than this. The FromID include the point who sends the data and ToID is the poin who receives the data. The amount indicate the size of the data. What I want is, based on the FromID and ToID, to generate a n*n matrix to store the dateset in matrix format in excel,
What i want, the matrix should be as follows:
10 11 12
10 --- 50 67 56
11 --- 60 80 17
12 --- ...
I now have such type of data in columns but I am a noob in VBA and i dont have too much experience. I am wondering is that possible to give me some suggestions about the logics (detailed?) and if possible, could you provide some code snippets with some explanations about how to do this?
Many thanks!
You may not need any VBA coding. Excel has a facility called a Pivot Table to create two dimensional tables of this type. See:
Introduction

Excel formula for "result of 2-7 on the die is always treated as if you rolled an 8"

I have a spreadsheet program which rolls twenty-sided dice. Sheet 1 is Rolls and Sheet 2 is Values.
I want to roll a d20, but if it comes up 2-7, fudge it and assume I got 8 instead.
Rolls!A2's function is =RANDBETWEEN(1,20) which returns a random number between 1 and 20 to represent the d20 roll. Values!7E is function which calculates a (non-random) number (currently 13).
Currently, Rolls!C7's function attempts to calculate my result with =Values!E7+Rolls!A2. But I would like to update Rolls!C7 to reflect the fudging. If Rolls!A2 returns numbers 2, 3, 4, 5, 6, or 7, Rolls!C7 would instead be calculated as if it rolled an 8.
Replace Rolls!A2 in your formula with this: IF(AND(Rolls!A2<8, Rolls!A2>1),8,Rolls!A2) this way it will always be at least 8 unless a 1 is rolled.
Or you could do =IF(Rolls!A2=1,1,MAX(Rolls!A2,8))

Resources